### Install Dependencies with npm or yarn Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md Installs the necessary dependencies for running the tests of the git-auto-commit-action using either npm or yarn package managers. ```shell npm install yarn ``` -------------------------------- ### Basic Git Auto Commit Workflow Setup (YAML) Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This snippet shows the fundamental configuration for adding the git-auto-commit-action to a GitHub Actions workflow. It requires write permissions for contents and is typically placed after steps that modify repository files. ```yaml name: Format on: push jobs: format-code: runs-on: ubuntu-latest permissions: # Give the default GITHUB_TOKEN write permission to commit and push the # added or changed files to the repository. contents: write steps: - uses: actions/checkout@v5 with: ref: ${{ github.head_ref }} # Value already defaults to true, but `persist-credentials` is required to push new commits to the repository. persist-credentials: true # Other steps that change files in the repository go here # … # Commit all changed files back to the repository - uses: stefanzweifel/git-auto-commit-action@v7 ``` -------------------------------- ### Run Tests with npm or yarn Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md Executes the test suite for the git-auto-commit-action using the installed dependencies. This can be done via npm or yarn commands. ```shell npm run test yarn test ``` -------------------------------- ### Advanced Git Auto Commit Configuration (YAML) Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This example demonstrates the extended configuration options for the git-auto-commit-action. It covers customizing commit messages, branches, file patterns, author details, tagging, and controlling various Git operations like add, status, and push. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 with: # Optional. Commit message for the created commit. # Defaults to "Apply automatic changes" commit_message: Automated Change # Optional. Remote branch name where commit is going to be pushed to. # Defaults to the current branch. branch: feature-123 # Optional. Options used by `git-commit`. # See https://git-scm.com/docs/git-commit#_options commit_options: '--no-verify --signoff' # Optional glob pattern of files which should be added to the commit # Defaults to all (.) # See the `pathspec`-documentation for git # - https://git-scm.com/docs/git-add#Documentation/git-add.txt-ltpathspecgt82308203 # - https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec file_pattern: '*.php src/*.js tests/*.js' # Optional. Local file path to the repository. # Defaults to the root of the repository. repository: . # Optional commit user and author settings commit_user_name: My GitHub Actions Bot # defaults to "github-actions[bot]" commit_user_email: my-github-actions-bot@example.org # defaults to "41898282+github-actions[bot]@users.noreply.github.com" commit_author: Author # defaults to "username ", where "numeric_id" and "username" belong to the author of the commit that triggered the run # Optional. Tag name to be created in the local repository and # pushed to the remote repository on the defined branch. # If only one of `tag_name` or `tagging_message` is provided, the value of the provided field will be used for both tag name and message. tag_name: 'v1.0.0' # Optional. Message to annotate the created tag with. # If only one of `tag_name` or `tagging_message` is provided, the value of the provided field will be used for both tag name and message. tagging_message: 'Codename "Sunshine"' # Optional. Option used by `git-status` to determine if the repository is # dirty. See https://git-scm.com/docs/git-status#_options status_options: '--untracked-files=no' # Optional. Options used by `git-add`. # See https://git-scm.com/docs/git-add#_options add_options: '-u' # Optional. Options used by `git-push`. # See https://git-scm.com/docs/git-push#_options push_options: '--force' # Optional. Disable dirty check and always try to create a commit and push skip_dirty_check: true # Optional. Skip internal call to `git fetch` skip_fetch: true # Optional. Skip internal call to `git checkout` skip_checkout: true # Optional. Skip internal call to `git push` skip_push: true # Optional. Prevents the shell from expanding filenames. # Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html disable_globbing: true # Optional. Create given branch name in local and remote repository. create_branch: true # Optional. Creates a new tag and pushes it to remote without creating a commit. # Skips dirty check and changed files. Must be used in combination with `tag` and `tagging_message`. create_git_tag_only: false ``` -------------------------------- ### Multiline Commit Message Generation in GitHub Actions Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This example shows how to construct a multiline commit message in GitHub Actions. It involves writing lines to a temporary file, then using a step to capture these lines into a multiline output variable for the git-auto-commit-action. ```yaml # Building a multiline commit message # Adjust to your liking - run: echo "Commit Message 1" >> commitmessage.txt - run: echo "Commit Message 2" >> commitmessage.txt - run: echo "Commit Message 3" >> commitmessage.txt # Create a multiline string to be used by the git-auto-commit Action - name: Set commit message id: commit_message_step run: | echo 'commit_message<> $GITHUB_OUTPUT cat commitmessage.txt >> $GITHUB_OUTPUT echo 'EOF' >> $GITHUB_OUTPUT # Quick and dirty step to get rid of the temporary file holding the commit message - run: rm -rf commitmessage.txt - uses: stefanzweifel/git-auto-commit-action@v7 id: commit with: commit_message: ${{ steps.commit_message_step.outputs.commit_message }} ``` -------------------------------- ### Using git-auto-commit-action Outputs in GitHub Workflows Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This example demonstrates how to use the outputs of the `git-auto-commit-action`, specifically `changes_detected`, to conditionally run subsequent steps in a GitHub Workflow. An `id` must be assigned to the action step for its outputs to be accessible. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 id: auto-commit-action #mandatory for the output to show up in ${{ steps }} with: commit_message: Apply php-cs-fixer changes - name: "Run if changes have been detected" if: steps.auto-commit-action.outputs.changes_detected == 'true' run: echo "Changes!" - name: "Run if no changes have been detected" if: steps.auto-commit-action.outputs.changes_detected == 'false' run: echo "No Changes!" ``` -------------------------------- ### Create GPG Signed Commits Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt This example shows how to configure git-auto-commit-action to create GPG-signed commits. It involves importing a GPG private key using the `crazy-max/ghaction-import-gpg` action and then specifying the GPG key details for the commit author. ```yaml - name: Import GPG key id: import-gpg uses: crazy-max/ghaction-import-gpg@v6 with: gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} passphrase: ${{ secrets.GPG_PASSPHRASE }} git_user_signingkey: true git_commit_gpgsign: true - name: Run formatter run: npm run format - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: 'style: apply formatting' commit_author: '${{ steps.import-gpg.outputs.name }} <${{ steps.import-gpg.outputs.email }}>' commit_user_name: ${{ steps.import-gpg.outputs.name }} commit_user_email: ${{ steps.import-gpg.outputs.email }} ``` -------------------------------- ### Using Action Outputs to Conditionally Run Steps (YAML) Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt This example shows how to leverage the outputs of the git-auto-commit-action, specifically `changes_detected` and `commit_hash`, to conditionally execute subsequent steps. It demonstrates notifying a webhook if changes were committed or skipping the notification if no changes were found. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 id: auto-commit with: commit_message: 'chore: update dependencies' - name: Notify on changes if: steps.auto-commit.outputs.changes_detected == 'true' run: | echo "Changes committed with hash: ${{ steps.auto-commit.outputs.commit_hash }}" curl -X POST ${{ secrets.WEBHOOK_URL }} \ -H 'Content-Type: application/json' \ -d '{"commit": "${{ steps.auto-commit.outputs.commit_hash }}"}' - name: Skip notification if: steps.auto-commit.outputs.changes_detected == 'false' run: echo "No changes detected, skipping notification" ``` -------------------------------- ### Fork Pull Request Workflow Commit Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt This example demonstrates how to use git-auto-commit-action within a fork pull request workflow. It checks out the pull request's head repository and then commits changes back to it, ensuring that formatting or other automated changes are reflected in the fork. ```yaml name: Format PHP on: push: branches: [main] pull_request_target: jobs: format: runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v5 with: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} - name: Run formatter run: composer format - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: 'style: apply php-cs-fixer' ``` -------------------------------- ### Amend Last Commit (YAML) Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt This example shows how to amend the last commit instead of creating a new one, which is useful for correcting mistakes in the most recent commit. It retrieves the author and message of the last commit and then uses git-auto-commit-action with '--amend --no-edit' options. ```yaml - uses: actions/checkout@v5 with: fetch-depth: 2 - name: Get last commit info id: last-commit run: | echo "message=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT echo "author=$(git log -1 --pretty='%an <%ae>')" >> $GITHUB_OUTPUT - name: Fix files run: npm run lint:fix - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: ${{ steps.last-commit.outputs.message }} commit_author: ${{ steps.last-commit.outputs.author }} commit_options: '--amend --no-edit' push_options: '--force' skip_fetch: true ``` -------------------------------- ### Signing Commits with GPG Key using git-auto-commit-action Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This configuration demonstrates how to sign commits with a GPG key when using the git-auto-commit-action. It integrates the crazy-max/ghaction-import-gpg action to import the GPG key and then configures git-auto-commit-action to use the imported key for signing and authorship. ```yaml - name: "Import GPG key" id: import-gpg uses: crazy-max/ghaction-import-gpg@v6 with: gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} passphrase: ${{ secrets.GPG_PASSPHRASE }} git_user_signingkey: true git_commit_gpgsign: true - name: "Commit and push changes" uses: stefanzweifel/git-auto-commit-action@v7 with: commit_author: "${{ steps.import-gpg.outputs.name }} <${{ steps.import-gpg.outputs.email }}>" commit_user_name: ${{ steps.import-gpg.outputs.name }} commit_user_email: ${{ steps.import-gpg.outputs.email }} ``` -------------------------------- ### YAML Workflow for PHP Formatting on Push and Pull Request Target Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This YAML workflow demonstrates how to configure GitHub Actions to run `php-cs-fixer` on a `push` to the `main` branch or when a `pull_request_target` event occurs. It utilizes `actions/checkout` to clone the head repository and `stefanzweifel/git-auto-commit-action` to commit any fixes. Note the use of `pull_request_target` carries security risks. ```yaml name: Format PHP on: push: branches: - main pull_request_target: jobs: php-cs-fixer: runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v5 with: # Checkout the fork/head-repository and push changes to the fork. # If you skip this, the base repository will be checked out and changes # will be committed to the base repository! repository: ${{ github.event.pull_request.head.repo.full_name }} # Checkout the branch made in the fork. Will automatically push changes # back to this branch. ref: ${{ github.head_ref }} - name: Run php-cs-fixer uses: docker://oskarstark/php-cs-fixer-ga - uses: stefanzweifel/git-auto-commit-action@v7 ``` -------------------------------- ### git-auto-commit-action with Custom File Pattern and Disabled Globbing Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md Demonstrates how to use a custom `file_pattern` with the git-auto-commit-action while disabling globbing. This is useful when the action doesn't detect changes due to globbing issues, especially when dealing with files in subdirectories. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 with: file_pattern: '*.md' disable_globbing: true ``` -------------------------------- ### Checkout Repository for Non-Push Events in GitHub Actions Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This snippet shows how to correctly check out a repository using `actions/checkout@v5` for events like `pull_request`. Specifying the `ref` as `${{ github.head_ref }}` is crucial to avoid checking out the repository in a detached state. ```yaml - uses: actions/checkout@v5 with: ref: ${{ github.head_ref }} ``` -------------------------------- ### Protected Branch with Personal Access Token (YAML) Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt Demonstrates how to push commits to a protected branch like 'main' using a Personal Access Token (PAT) with force push enabled. This workflow checks out the code with the PAT, updates files, and then uses git-auto-commit-action to commit and force push the changes. ```yaml - uses: actions/checkout@v5 with: token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} ref: main - name: Update files run: | ./scripts/generate-docs.sh - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: 'docs: auto-generate documentation' push_options: '--force' branch: main ``` -------------------------------- ### Checkout Action with PAT for Protected Branches Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md Configures the actions/checkout step to use a Personal Access Token (PAT) for protected branches. This ensures the action has the necessary permissions to commit to restricted branches. It falls back to GITHUB_TOKEN if a PAT secret is not available. ```yaml - uses: actions/checkout@v5 with: # We pass the "PAT" secret to the checkout action; if no PAT secret is available to the workflow runner (eg. Dependabot) we fall back to the default "GITHUB_TOKEN". token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} ``` -------------------------------- ### Checkout Action with PAT for Workflow Triggering Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This snippet demonstrates how to use the actions/checkout action with a Personal Access Token (PAT) to allow commits to trigger new workflow runs. It replaces the default GITHUB_TOKEN with a user-defined PAT stored as a secret. ```yaml - uses: actions/checkout@v5 with: token: ${{ secrets.PAT }} ``` -------------------------------- ### git-auto-commit-action with Force Push for Protected Branches Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md Enables force pushing with the git-auto-commit-action, which is necessary when dealing with protected branches and a Personal Access Token that doesn't have administrator privileges. This requires enabling force pushes in the repository settings. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: Apply php-cs-fixer changes push_options: --force ``` -------------------------------- ### Git Tagging with Commit (YAML) Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt This configuration demonstrates how to create an annotated Git tag along with a commit using the git-auto-commit-action. It specifies the commit message, tag name, and a message for the tag itself, targeting specific files for the commit. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: 'release: version bump' tag_name: 'v1.2.0' tagging_message: 'Release version 1.2.0 with new features' file_pattern: 'package.json package-lock.json' ``` -------------------------------- ### Basic Auto-Commit Workflow (YAML) Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt Demonstrates a basic GitHub Actions workflow that uses the git-auto-commit-action to automatically commit any changes made during the workflow run. It includes checking out the code, running a code formatter, and then committing the changes with default settings. ```yaml name: Format Code on: push jobs: format: runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v5 with: ref: ${{ github.head_ref }} persist-credentials: true - name: Run code formatter run: | npm install prettier npx prettier --write "**/*.js" - uses: stefanzweifel/git-auto-commit-action@v7 ``` -------------------------------- ### Automate PHP Code Style Fixes and Commits with GitHub Actions Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This workflow automatically runs `php-cs-fixer` to format PHP code and uses `git-auto-commit-action` to commit any changes. It checks out the correct branch for pull requests and requires write permissions for the GITHUB_TOKEN. ```yaml name: php-cs-fixer on: pull_request: push: branches: - main jobs: php-cs-fixer: runs-on: ubuntu-latest permissions: # Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository. contents: write steps: - uses: actions/checkout@v5 with: ref: ${{ github.head_ref }} - name: Run php-cs-fixer uses: docker://oskarstark/php-cs-fixer-ga - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: Apply php-cs-fixer changes ``` -------------------------------- ### Branch Creation and Custom Target (YAML) Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt Shows how to use the git-auto-commit-action to create a new branch for commits and push them to a specific remote branch. This is useful for feature branches or automated documentation updates. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: 'feat: add generated documentation' branch: 'feature-docs' create_branch: true file_pattern: 'docs/*.md' ``` -------------------------------- ### Tag-Only Creation Without Commit (YAML) Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt Illustrates how to use the git-auto-commit-action solely for creating and pushing a Git tag without making any new commits. This is useful for marking specific points in history, such as build numbers or release candidates. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 with: create_git_tag_only: true tag_name: 'build-${{ github.run_number }}' tagging_message: 'Build artifact tag' ``` -------------------------------- ### Advanced Git Options for File Staging Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt This snippet illustrates advanced usage of git-auto-commit-action by specifying custom Git options for staging files. It uses `status_options` and `add_options` to control which files are detected and staged, along with `file_pattern` and `disable_globbing` for precise file selection. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: 'chore: update tracked files only' status_options: '--untracked-files=no' add_options: '-u' file_pattern: 'src/**/*.js' disable_globbing: true skip_dirty_check: false ``` -------------------------------- ### Custom Commit Message and File Pattern (YAML) Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt Configures the git-auto-commit-action to use a custom commit message, specify which files to include using a file pattern, and add commit options like '--no-verify'. It also allows setting a custom commit user name and email. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: 'style: apply code formatting' file_pattern: '*.php src/*.js tests/*.js' commit_options: '--no-verify' commit_user_name: 'Auto Formatter Bot' commit_user_email: 'formatter@example.com' ``` -------------------------------- ### Extracting Commit Information (Shell) Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This shell script snippet shows how to extract the last commit's message and author details using 'git log'. The output is formatted to be compatible with GitHub Actions outputs, allowing these values to be used in subsequent steps. This is crucial for amending commits with the correct message and author. ```shell echo "message=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT echo "author=$(git log -1 --pretty=\"%an <%ae>\")" >> $GITHUB_OUTPUT ``` -------------------------------- ### Amend Commit with Git Auto Commit Action (YAML) Source: https://github.com/stefanzweifel/git-auto-commit-action/blob/master/README.md This YAML snippet demonstrates how to configure the git-auto-commit-action to amend the last commit. It includes fetching sufficient history, extracting the previous commit message and author, and setting the 'commit_options' and 'push_options' to '--amend --no-edit' and '--force' respectively. Ensure 'actions/checkout' is configured to fetch at least 2 commits. ```yaml - uses: actions/checkout@4 with: # Fetch the last 2 commits instead of just 1. (Fetching just 1 commit would overwrite the whole history) fetch-depth: 2 # Other steps in your workflow to trigger a changed file - name: Get last commit message id: last-commit run: | echo "message=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT echo "author=$(git log -1 --pretty=\"%an <%ae>\")" >> $GITHUB_OUTPUT - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_author: ${{ steps.last-commit.outputs.author }} commit_message: ${{ steps.last-commit.outputs.message }} commit_options: '--amend --no-edit' push_options: '--force' skip_fetch: true ``` -------------------------------- ### Create Multiline Commit Message Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt This snippet demonstrates how to generate a detailed multiline commit message for the git-auto-commit-action. It uses shell commands to write the commit message to a GitHub Actions output variable, which is then passed to the action. ```yaml - name: Generate commit message id: message run: | echo 'commit_message<> $GITHUB_OUTPUT echo 'refactor: improve code quality' >> $GITHUB_OUTPUT echo '' >> $GITHUB_OUTPUT echo '- Fixed linting issues' >> $GITHUB_OUTPUT echo '- Updated code formatting' >> $GITHUB_OUTPUT echo '- Removed unused imports' >> $GITHUB_OUTPUT echo 'EOF' >> $GITHUB_OUTPUT - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: ${{ steps.message.outputs.commit_message }} ``` -------------------------------- ### Skip Push for Local Commit Only Source: https://context7.com/stefanzweifel/git-auto-commit-action/llms.txt This snippet shows how to configure git-auto-commit-action to create only a local commit without pushing to the remote repository. This is useful for multi-stage workflows where subsequent steps might depend on the committed files before a final push occurs. ```yaml - uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: 'temp: intermediate changes' skip_push: true - name: Run additional processing run: ./process-committed-files.sh - name: Push manually run: git push origin ${{ github.ref }} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.