{"id":31363828,"url":"https://github.com/pachadotdev/clang-format-example","last_synced_at":"2026-04-21T05:32:50.825Z","repository":{"id":315649474,"uuid":"1060363253","full_name":"pachadotdev/clang-format-example","owner":"pachadotdev","description":"Example GHA workflow of how to use https://github.com/pachadotdev/clang-format","archived":false,"fork":false,"pushed_at":"2025-09-30T16:38:16.000Z","size":96,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-19T02:47:45.336Z","etag":null,"topics":["clang","cpp","github-actions","llvm"],"latest_commit_sha":null,"homepage":"https://github.com/pachadotdev/clang-format","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pachadotdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-19T19:34:15.000Z","updated_at":"2025-09-30T16:38:19.000Z","dependencies_parsed_at":"2025-09-19T22:01:03.538Z","dependency_job_id":"2d18271f-6a21-4666-a6ba-f1ee5863bf55","html_url":"https://github.com/pachadotdev/clang-format-example","commit_stats":null,"previous_names":["pachadotdev/clang-format-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pachadotdev/clang-format-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fclang-format-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fclang-format-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fclang-format-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fclang-format-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pachadotdev","download_url":"https://codeload.github.com/pachadotdev/clang-format-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fclang-format-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32078857,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T02:38:07.213Z","status":"ssl_error","status_checked_at":"2026-04-21T02:38:06.559Z","response_time":128,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clang","cpp","github-actions","llvm"],"created_at":"2025-09-27T05:22:51.901Z","updated_at":"2026-04-21T05:32:50.817Z","avatar_url":"https://github.com/pachadotdev.png","language":"C++","funding_links":["https://www.buymeacoffee.com/pacha"],"categories":[],"sub_categories":[],"readme":"# Clang-format Action Example\n\nIf this project is useful to you, please consider supporting it by buying me a coffee: [![BuyMeACoffee](https://raw.githubusercontent.com/pachadotdev/buymeacoffee-badges/main/bmc-yellow.svg)](https://www.buymeacoffee.com/pacha)\n\n## What this example shows\n\n- Automatic formatting of C++ code on push/PR\n- Auto-commit formatted changes back to the repository\n- Multiple workflow patterns for different use cases\n\nThese are minimal examples showing how to use the [clang-format GitHub Action](https://github.com/pachadotdev/clang-format).\n\nThe details on how to build the binaries locally are here: [pachadotdev/clang-format](https://github.com/pachadotdev/clang-format).\n\n## Files in this example\n\n### Source Files\n\n- `src/example.badformat` - C++ file with bad formatting\n- `src/example.cpp` - auto-formatted copy of `src/example.badformat`\n- `src/utils.badformat` - Header file with bad formatting\n- `src/utils.h` - auto-formatted copy of `src/utils.badformat`\n- `.clang-format` - Optional formatting style configuration (Google-based)\n\nNote: the extension only modifies cpp and hpp files.\n\n### GitHub Workflows\n\n- `.github/workflows/format.yml` - ⭐ Minimal auto-format workflow (recommended)\n- `.github/workflows/format-pr-check.yml` - PR validation workflow (check-only)\n- `.github/workflows/format-specific.yml` - Manual workflow with version selection\n\n## How it works\n\n1. The user pushes a code with formatting issues\n2. GitHub Actions run on the push/PR\n3. This extension will use `clang-format-11`, `clang-format-12`, ..., or `clang-format-19` as requested to fix formatting and implement the changes in the repository\n\nWhen the code is properly formatted, the action will do nothing.\n\n![nodiff.png](nodiff.png \"Correctly formatted files on a previous run\")\n\n## Try it yourself\n\n1. Fork this repository\n2. Make some changes to the C++ files with poor formatting\n3. Add your own files and push your changes\n4. Watch the action automatically format and commit the fixes\n\n## Workflow Examples Explained\n\n### `format.yml` - Minimal Auto-Formatting (⭐ Recommended)\n\nWhat it does: Automatically formats and commits changes on every push/PR.\n\n- ✅ Best for: Most projects wanting automatic code formatting\n- 🔧 Behavior: Fixes code and commits back automatically\n- 📝 Triggers: Every push to main/master/develop + PRs\n  \nCopy [this](https://github.com/pachadotdev/clang-format-example/blob/main/.github/workflows/format.yml) example:\n\n```yaml\nname: Auto-format C++ Code\n\non:\n  push:\n    branches: [ main, master, develop ]\n  pull_request:\n    branches: [ main, master, develop ]\n\npermissions:\n  contents: write\n  pull-requests: write\n\njobs:\n  format:\n    runs-on: ubuntu-latest\n    \n    steps:\n      - uses: actions/checkout@v4\n        with:\n          token: ${{ secrets.GITHUB_TOKEN }}\n          persist-credentials: true\n      \n      - name: Format C++ code\n        uses: pachadotdev/clang-format@main\n        with:\n          version: '18'\n          auto-commit: true\n          commit-message: 'style: auto-format C++ code with clang-format-18'\n```\n\n### `format-pr-check.yml` - PR Validation Only\n\nWhat it does: Checks formatting without making changes, fails if issues found\n\n- ✅ Best for: Enforcing code style in PRs without auto-fixing\n- ❌ Behavior: Fails CI if formatting issues are detected\n- 📝 Triggers: Only on pull requests\n  \nCopy [this](https://github.com/pachadotdev/clang-format-example/blob/main/.github/workflows/format-pr-check.yml) example:\n\n```yaml\nname: PR Format Check\n\non:\n  pull_request:\n    branches: [ main, master ]\n\njobs:\n  check-formatting:\n    runs-on: ubuntu-latest\n    \n    steps:\n      - uses: actions/checkout@v4\n      \n      - name: Check C++ code formatting\n        uses: pachadotdev/clang-format@main\n        with:\n          version: '18'\n          auto-commit: false\n          fail-on-diff: true\n```\n\n### `format-specific.yml` - Manual with Options\n\nWhat it does: Manual workflow with version selection and specific file targeting\n\n- ✅ Best for: Advanced users wanting control over when/how formatting runs\n- 🎛️ Behavior: Choose clang-format version (11-19) via GitHub UI\n- 📝 Triggers: Manual dispatch only (Actions tab → Run workflow)\n  \nCopy [this](https://github.com/pachadotdev/clang-format-example/blob/main/.github/workflows/format-specific.yml) example:\n\n```yaml\nname: Format Specific Files\n\non:\n  workflow_dispatch:\n    inputs:\n      clang_version:\n        description: 'Clang-format version to use'\n        required: true\n        default: '18'\n        type: choice\n        options:\n        - '11'\n        - '12'\n        - '13'\n        - '14'\n        - '15'\n        - '16'\n        - '17'\n        - '18'\n        - '19'\n\npermissions:\n  contents: write\n\njobs:\n  format-specific:\n    runs-on: ubuntu-latest\n    \n    steps:\n      - uses: actions/checkout@v4\n        with:\n          token: ${{ secrets.GITHUB_TOKEN }}\n          persist-credentials: true\n      \n      - name: Format specific C++ files\n        uses: pachadotdev/clang-format@main\n        with:\n          version: ${{ github.event.inputs.clang_version }}\n          files: 'src/*.cpp src/*.h'\n          auto-commit: true\n          commit-message: 'style: format src/ files with clang-format-${{ github.event.inputs.clang_version }}'\n```\n\n## Quick Start Recommendation\n\nFor most projects, start with `format.yml`. It provides automatic formatting with minimal setup!\n\n## Expected behavior\n\nAfter pushing, you should see:\n\n- ✅ Action runs successfully\n- 🔧 Code gets properly formatted\n- 📝 Automatic commit with formatted changes\n- 🎉 Clean, consistent code style\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpachadotdev%2Fclang-format-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpachadotdev%2Fclang-format-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpachadotdev%2Fclang-format-example/lists"}