### ghcommit-action with All Options Source: https://github.com/planetscale/ghcommit-action/blob/main/README.md This example demonstrates using ghcommit-action with all available options, including specifying an empty commit if no changes are detected and filtering files by pattern. This is useful for more controlled commit behavior. ```yaml - uses: planetscale/ghcommit-action@v0.1.6 with: commit_message: "🤖 fmt" repo: ${{ github.repository }} branch: ${{ github.head_ref || github.ref_name }} empty: true file_pattern: '*.txt *.md *.json *.hcl' env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} ``` -------------------------------- ### Basic Usage of ghcommit-action Source: https://context7.com/planetscale/ghcommit-action/llms.txt This configuration demonstrates the basic setup for the ghcommit-action. No special configuration is needed as the entrypoint handles all git status codes. ```yaml # No special configuration needed — the entrypoint handles all git status codes: # ' M' / ' A' / ' T' → added to --add list # '??' (untracked) → added to --add list # ' D' → added to --delete list # 'R ' → split into --delete=old_name and --add=new_name - uses: planetscale/ghcommit-action@v0.1.6 with: commit_message: "🤖 sync generated files" repo: ${{ github.repository }} branch: ${{ github.head_ref || github.ref_name }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Internally calls ghcommit like: # ghcommit -b main -r org/repo -m "🤖 sync generated files" \ # --add=README.md --add=foo.txt --add=new.file \ # --delete=old.file --delete="a path with spaces/file.txt" ``` -------------------------------- ### Using Step Outputs: Downstream Steps with Commit Info Source: https://context7.com/planetscale/ghcommit-action/llms.txt This example demonstrates how to capture and use the commit URL and hash produced by ghcommit-action in subsequent workflow steps. This is useful for tasks like posting status comments or triggering other workflows. ```yaml steps: - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} - name: Run terraform fmt run: terraform fmt -recursive - name: Commit formatted files id: auto_commit # Give the step an ID to reference its outputs uses: planetscale/ghcommit-action@v0.1.6 with: commit_message: "🤖 terraform fmt" repo: ${{ github.repository }} branch: ${{ github.head_ref || github.ref_name }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Print commit info run: | echo "Commit URL: ${{ steps.auto_commit.outputs.commit-url }}" echo "Commit Hash: ${{ steps.auto_commit.outputs.commit-hash }}" # Example output: # Commit URL: https://github.com/org/repo/commit/abc123def456 # Commit Hash: abc123def456 ``` -------------------------------- ### Basic Usage: Auto-format on Pull Request Source: https://context7.com/planetscale/ghcommit-action/llms.txt This example demonstrates how to use ghcommit-action to automatically commit code formatting changes on a pull request. It requires the `contents: write` permission and should run on `ubuntu-latest`. Ensure `actions/checkout` is used with the correct ref to avoid conflicts. ```yaml name: fmt on: pull_request: types: - opened - synchronize - reopened jobs: fmt-code: runs-on: ubuntu-latest permissions: contents: write # Required to commit back to the repository steps: - uses: actions/checkout@v4 with: # Check out the PR head commit (not the merge commit) to avoid conflicts ref: ${{ github.event.pull_request.head.sha }} # Run your formatting or code-generation tool here - name: Format code run: go fmt ./... # Commit all changed files back to the PR branch - uses: planetscale/ghcommit-action@v0.1.6 with: commit_message: "🤖 fmt" repo: ${{ github.repository }} branch: ${{ github.head_ref || github.ref_name }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` -------------------------------- ### All Options: Scoped File Pattern and Empty Commits Source: https://context7.com/planetscale/ghcommit-action/llms.txt This example shows how to configure ghcommit-action with a scoped file pattern to only commit specific file types and enable empty commits. Empty commits are useful when you want a commit record even if no changes are detected. ```yaml steps: - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} - name: Generate docs run: make docs - uses: planetscale/ghcommit-action@v0.1.6 with: commit_message: "🤖 regenerate docs" repo: ${{ github.repository }} branch: ${{ github.head_ref || github.ref_name }} empty: true # Create a commit even if nothing changed file_pattern: '*.txt *.md *.json *.hcl' # Only commit files matching these patterns env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` -------------------------------- ### Basic Usage of ghcommit-action Source: https://github.com/planetscale/ghcommit-action/blob/main/README.md Integrate this action into your workflow to automatically commit changed files. Ensure the 'contents: write' permission is granted to the GITHUB_TOKEN. The 'ref' input for checkout is crucial for PRs to prevent merge commits. ```yaml - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} # Commit all changed files back to the repository - uses: planetscale/ghcommit-action@v0.1.6 with: commit_message: "🤖 fmt" repo: ${{ github.repository }} branch: ${{ github.head_ref || github.ref_name }} env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} ``` -------------------------------- ### Debugging ghcommit-action with Verbose Output Source: https://context7.com/planetscale/ghcommit-action/llms.txt Enable verbose output for debugging by setting the DEBUG environment variable to any non-empty value. This enables 'set -x' tracing and prints parsed git status lines. ```yaml - uses: planetscale/ghcommit-action@v0.1.6 with: commit_message: "🤖 fmt" repo: ${{ github.repository }} branch: ${{ github.head_ref || github.ref_name }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} DEBUG: "1" # Enables 'set -x' tracing and prints parsed git status lines # Debug output example: # + git status -s --porcelain=v1 -z -- . # line: ' M README.md' # Index Status: ' ' # Tree Status: M # Filename: README.md # ghcommit args: '-b main -r org/repo -m 🤖 fmt --add=README.md' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.