### Run create-pull-request in Container Environments Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md Configuration examples for running the action within Alpine and Ubuntu containers. Demonstrates the requirement to install git as a dependency before executing the action. ```yaml jobs: createPullRequestAlpine: runs-on: ubuntu-latest container: image: alpine steps: - name: Install dependencies run: apk --no-cache add git - uses: actions/checkout@v6 - name: Create Pull Request uses: peter-evans/create-pull-request@v8 ``` ```yaml jobs: createPullRequestUbuntu: runs-on: ubuntu-latest container: image: ubuntu steps: - name: Install dependencies run: | apt-get update apt-get install -y software-properties-common add-apt-repository -y ppa:git-core/ppa apt-get install -y git - uses: actions/checkout@v6 - name: Create Pull Request uses: peter-evans/create-pull-request@v8 ``` -------------------------------- ### Continuous Integration build workflow for Node.js Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md A standard CI workflow that installs dependencies, runs tests, and builds the project. This is intended to be used alongside automated dependency update workflows to ensure stability. ```yaml name: CI on: push: branches: [main] pull_request: branches: [main] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v3 with: node-version: 16.x - run: npm ci - run: npm run test - run: npm run build ``` -------------------------------- ### Trigger GitHub Actions Workflow via Repository Dispatch (External Service) Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This example shows how to trigger a GitHub Actions workflow from an external service using a `curl` command. The workflow must be configured to run on `repository_dispatch` events. The command requires a username, a repository-scoped Personal Access Token (PAT), and the repository name. ```bash curl -XPOST -u "[username]:[token]" \ -H "Accept: application/vnd.github.everest-preview+json" \ -H "Content-Type: application/json" \ https://api.github.com/repos/[username]/[repository]/dispatches \ --data '{"event_type": "create-pull-request"}' ``` -------------------------------- ### Configure Author Identity for v3 Migration Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/updating.md Example showing how to explicitly set the author input to maintain v2 behavior when migrating to v3, as the default behavior for author identity changed. ```yaml - uses: peter-evans/create-pull-request@v3 with: author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> ``` -------------------------------- ### Conditional Job Execution for Branch Pushes (YAML) Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This example shows how to ensure a specific job within a push-triggered workflow only executes when the push event is for a branch. It uses the `if: startsWith(github.ref, 'refs/heads/')` condition on the job. This is useful for separating branch-specific logic from tag-specific logic. ```yaml on: push jobs: createPullRequest: if: startsWith(github.ref, 'refs/heads/') runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 ... someOtherJob: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 ... ``` -------------------------------- ### Trigger GitHub Actions Workflow via Repository Dispatch (GitHub Actions) Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This example demonstrates triggering a GitHub Actions workflow from another workflow using the `peter-evans/repository-dispatch` action. The target workflow must be configured to listen for `repository_dispatch` events. It requires a repository access token and specifies the event type and optional client payload. ```yaml - name: Repository Dispatch uses: peter-evans/repository-dispatch@v2 with: token: ${{ secrets.REPO_ACCESS_TOKEN }} repository: username/my-repo event-type: create-pull-request client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}' ``` -------------------------------- ### Automate Gradle dependency updates with GitHub Actions Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This workflow updates Gradle dependencies by writing new lockfiles on a weekly schedule. It requires the project to be pre-configured for Gradle dependency locking. ```yaml name: Update Dependencies on: schedule: - cron: '0 1 * * 1' jobs: update-dep: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-java@v2 with: distribution: 'temurin' java-version: 1.8 - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Perform dependency resolution and write new lockfiles run: ./gradlew dependencies --write-locks - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.PAT }} commit-message: Update dependencies title: Update dependencies body: | - Dependency updates Auto-generated by [create-pull-request][1] [1]: https://github.com/peter-evans/create-pull-request branch: update-dependencies ``` -------------------------------- ### Execute in Containerized Environments Source: https://context7.com/peter-evans/create-pull-request/llms.txt Shows how to run the action within Docker containers like Alpine or Ubuntu. Requires manual installation of git within the container environment. ```yaml name: Container-based Workflow on: schedule: - cron: '0 0 * * *' jobs: alpine-container: runs-on: ubuntu-latest container: image: alpine steps: - name: Install dependencies run: apk --no-cache add git - uses: actions/checkout@v6 - name: Make changes run: date > alpine-timestamp.txt - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: title: Alpine container update branch: container/alpine-update ubuntu-container: runs-on: ubuntu-latest container: image: ubuntu steps: - name: Install dependencies run: | apt-get update apt-get install -y software-properties-common add-apt-repository -y ppa:git-core/ppa apt-get install -y git - uses: actions/checkout@v6 - name: Make changes run: date > ubuntu-timestamp.txt - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: title: Ubuntu container update branch: container/ubuntu-update ``` -------------------------------- ### Render Markdown Templates for Pull Request Body Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md Demonstrates how to use the render-template action to process a markdown file with variables and pass the result as the body of a pull request. This allows for dynamic and reusable pull request descriptions. ```yaml - name: Render template id: template uses: chuhlomin/render-template@v1.4 with: template: .github/pull-request-template.md vars: | foo: this bar: that - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: body: ${{ steps.template.outputs.result }} ``` -------------------------------- ### Dump GitHub Action Contexts for Debugging Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md Provides a workflow step pattern to output various GitHub Action contexts (github, job, steps, runner, strategy, matrix) as JSON. This is useful for inspecting the state of variables and environment data during workflow execution. ```yaml steps: - name: Dump GitHub context env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - name: Dump job context env: JOB_CONTEXT: ${{ toJson(job) }} run: echo "$JOB_CONTEXT" - name: Dump steps context env: STEPS_CONTEXT: ${{ toJson(steps) }} run: echo "$STEPS_CONTEXT" - name: Dump runner context env: RUNNER_CONTEXT: ${{ toJson(runner) }} run: echo "$RUNNER_CONTEXT" - name: Dump strategy context env: STRATEGY_CONTEXT: ${{ toJson(strategy) }} run: echo "$STRATEGY_CONTEXT" - name: Dump matrix context env: MATRIX_CONTEXT: ${{ toJson(matrix) }} run: echo "$MATRIX_CONTEXT" ``` -------------------------------- ### Configure GPG Commit Signing in GitHub Actions Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md Example workflow configuration using ghaction-import-gpg to sign commits created by the create-pull-request action. Requires GPG_PRIVATE_KEY and GPG_PASSPHRASE secrets. ```yaml steps: - uses: actions/checkout@v6 - uses: crazy-max/ghaction-import-gpg@v5 with: gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} passphrase: ${{ secrets.GPG_PASSPHRASE }} git_user_signingkey: true git_commit_gpgsign: true - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.PAT }} committer: example ``` -------------------------------- ### Authenticate with GitHub App generated tokens Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md Shows the standard implementation of using actions/create-github-app-token to authenticate the create-pull-request action. This method provides scoped access based on the GitHub App's installation permissions. ```yaml steps: - uses: actions/create-github-app-token@v2 id: generate-token with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} - uses: actions/checkout@v6 # Make changes to pull request here - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ steps.generate-token.outputs.token }} ``` -------------------------------- ### Download Website Content and Create PR with GitHub Actions Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This workflow spiders a website using wget and downloads its content. It then uses the create-pull-request action to commit any changes found on the website to a new branch, creating a pull request for review. The wget command is configured for recursive download, level 2, with a 1-second wait between requests. ```yaml name: Download Website on: schedule: - cron: '0 10 * * *' jobs: format: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - name: Download website run: | wget \ --recursive \ --level=2 \ --wait=1 \ --no-clobber \ --page-requisites \ --html-extension \ --convert-links \ --domains quotes.toscrape.com \ http://quotes.toscrape.com/ - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: commit-message: update local website copy title: Automated Updates to Local Website Copy body: This is an auto-generated PR with website updates. branch: website-updates ``` -------------------------------- ### Automate CHANGELOG.md updates with GitHub Actions Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This workflow triggers on release publication to generate a new changelog using git-chglog. It requires git-chglog configuration files in the repository and assumes the release occurred on the main branch. ```yaml name: Update Changelog on: release: types: [published] jobs: updateChangelog: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Update Changelog run: | curl -o git-chglog -L https://github.com/git-chglog/git-chglog/releases/download/0.9.1/git-chglog_linux_amd64 chmod u+x git-chglog ./git-chglog -o CHANGELOG.md rm git-chglog - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: commit-message: update changelog title: Update Changelog body: Update changelog to reflect release changes branch: update-changelog base: main ``` -------------------------------- ### Automate SwaggerUI Distribution Updates for GitHub Pages Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This workflow checks for new SwaggerUI releases, downloads the latest distribution, and updates the repository files. It uses a version file to track the current release and triggers a pull request only when an update is detected. ```yaml name: Update Swagger UI on: schedule: - cron: '0 10 * * *' jobs: updateSwagger: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - name: Get Latest Swagger UI Release id: swagger-ui run: | release_tag=$(curl -sL https://api.github.com/repos/swagger-api/swagger-ui/releases/latest | jq -r ".tag_name") echo "release_tag=$release_tag" >> $GITHUB_OUTPUT current_tag=$(> $GITHUB_OUTPUT - name: Update Swagger UI if: steps.swagger-ui.outputs.current_tag != steps.swagger-ui.outputs.release_tag env: RELEASE_TAG: ${{ steps.swagger-ui.outputs.release_tag }} SWAGGER_YAML: "swagger.yaml" run: | # Delete the dist directory and index.html rm -fr dist index.html # Download the release curl -sL -o $RELEASE_TAG https://api.github.com/repos/swagger-api/swagger-ui/tarball/$RELEASE_TAG # Extract the dist directory tar -xzf $RELEASE_TAG --strip-components=1 $(tar -tzf $RELEASE_TAG | head -1 | cut -f1 -d"/")/dist rm $RELEASE_TAG # Move index.html to the root mv dist/index.html . # Fix references in index.html sed -i "s|https://petstore.swagger.io/v2/swagger.json|$SWAGGER_YAML|g" index.html sed -i "s|href=\"./|href=\"dist/|g" index.html sed -i "s|src=\"./|src=\"dist/|g" index.html # Update current release echo ${{ steps.swagger-ui.outputs.release_tag }} > swagger-ui.version - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: commit-message: Update swagger-ui to ${{ steps.swagger-ui.outputs.release_tag }} title: Update SwaggerUI to ${{ steps.swagger-ui.outputs.release_tag }} body: | Updates [swagger-ui][1] to ${{ steps.swagger-ui.outputs.release_tag }} Auto-generated by [create-pull-request][2] [1]: https://github.com/swagger-api/swagger-ui [2]: https://github.com/peter-evans/create-pull-request labels: dependencies, automated pr branch: swagger-ui-updates ``` -------------------------------- ### Avoid inconsistent checkout triggers Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md An example of a configuration to avoid, where multiple event triggers cause inconsistent checkout states, leading to unintended multiple pull requests. ```yaml on: push: create: jobs: example: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 ``` -------------------------------- ### Reference Third-Party Action by Commit Hash Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md This example shows how to use a third-party action by referencing a specific commit hash. This is a security measure to ensure you are using a known, reviewed version of the action and prevents unexpected changes from malicious updates. It directly uses the action's compiled JavaScript file. ```yaml - uses: thirdparty/foo-action@172ec762f2ac8e050062398456fccd30444f8f30 ``` -------------------------------- ### Automate Cargo Dependency Updates with GitHub Actions Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This workflow automates the process of updating Rust dependencies using cargo-edit and creating a pull request. It runs on a weekly schedule to ensure the Cargo.toml and Cargo.lock files remain synchronized. ```yaml name: Update Dependencies on: schedule: - cron: '0 1 * * 1' jobs: update-dep: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - name: Update dependencies run: | cargo install cargo-edit cargo update cargo upgrade --to-lockfile - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.PAT }} commit-message: Update dependencies title: Update dependencies body: | - Dependency updates Auto-generated by [create-pull-request][1] [1]: https://github.com/peter-evans/create-pull-request branch: update-dependencies ``` -------------------------------- ### Configure Workflow to Trigger on Repository Dispatch Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This YAML snippet shows how to configure a GitHub Actions workflow to be triggered by the `repository_dispatch` event. This allows workflows to be initiated by external services or other GitHub Actions workflows via the GitHub API. The `types` property can be used to filter specific event types. ```yaml on: repository_dispatch: types: [create-pull-request] ``` -------------------------------- ### Visualize Git History with GitgraphJS Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/assets/cpr-gitgraph.htm This JavaScript code uses the GitgraphJS library to create a visual representation of a Git repository's history. It customizes the template and orientation to display commits, branches, and merges, simulating workflow changes for a pull request. ```javascript const graphContainer = document.getElementById("graph-container"); const customTemplate = GitgraphJS.templateExtend(GitgraphJS.TemplateName.Metro, { commit: { message: { displayAuthor: false, displayHash: false, }, }, }); // Instantiate the graph. const gitgraph = GitgraphJS.createGitgraph(graphContainer, { template: customTemplate, orientation: "vertical-reverse" }); const main = gitgraph.branch("main"); main.commit("Last commit on base"); const localMain = gitgraph.branch("<#1> main (local)"); localMain.commit({ subject: "", body: "Changes to the local base during the workflow", }); const remotePatch = gitgraph.branch("create-pull-request/patch"); remotePatch.merge({ branch: localMain, commitOptions: { subject: "\[create-pull-request\] automated change", body: "Changes pushed to create the remote branch", }, }); main.commit("New commit on base"); const localMain2 = gitgraph.branch("<#2> main (local)"); localMain2.commit({ subject: "", body: "Changes to the updated local base during the workflow", }); remotePatch.merge({ branch: localMain2, commitOptions: { subject: "\[create-pull-request\] automated change", body: "Changes force pushed to update the remote branch", }, }); main.merge(remotePatch); ``` -------------------------------- ### Update project AUTHORS file via GitHub Actions Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md Automates the generation of an AUTHORS file by extracting contributor names and emails from git logs. It triggers on pushes to the main branch and creates a pull request with the updated file. ```yaml name: Update AUTHORS on: push: branches: - main jobs: updateAuthors: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Update AUTHORS run: | git log --format='%aN <%aE>%n%cN <%cE>' | sort -u > AUTHORS - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: commit-message: update authors title: Update AUTHORS body: Credit new contributors by updating AUTHORS branch: update-authors ``` -------------------------------- ### Automate NPM dependency updates with GitHub Actions Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This workflow runs on a weekly schedule to check for and apply NPM dependency updates. It uses a Personal Access Token (PAT) to ensure the generated pull request can trigger subsequent CI workflows. ```yaml name: Update Dependencies on: schedule: - cron: '0 10 * * 1' jobs: update-dep: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v3 with: node-version: '16.x' - name: Update dependencies run: | npx -p npm-check-updates ncu -u npm install - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.PAT }} commit-message: Update dependencies title: Update dependencies body: | - Dependency updates Auto-generated by [create-pull-request][1] [1]: https://github.com/peter-evans/create-pull-request branch: update-dependencies ``` -------------------------------- ### Keep production branch synchronized with main Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md Maintains a production branch by resetting it to match the main branch and opening a pull request. This facilitates a controlled promotion process where merging the PR updates production. ```yaml name: Create production promotion pull request on: push: branches: - main jobs: productionPromotion: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: ref: production - name: Reset promotion branch run: | git fetch origin main:main git reset --hard main - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: branch: production-promotion ``` -------------------------------- ### Display Annotation Message for Pull Request Status Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md Uses the GitHub workflow 'notice' command to display a clickable link to the created or updated pull request in the action run logs. It conditionally executes based on whether the pull request operation was successful. ```yaml - name: Create Pull Request id: cpr uses: peter-evans/create-pull-request@v8 - name: Show message for created Pull Request if: ${{ steps.cpr.outputs.pull-request-url && steps.cpr.outputs.pull-request-operation != 'none' }} shell: bash env: PR_URL: ${{ steps.cpr.outputs.pull-request-url }} PR_OPERATION: ${{ steps.cpr.outputs.pull-request-operation }} run: | echo "::notice::${PR_URL} was ${PR_OPERATION}." ``` -------------------------------- ### Automate Code Fixes with autopep8 and create-pull-request (YAML) Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This workflow automatically checks for code style issues using autopep8. If fixes are found, it creates a new pull request with these changes. The workflow is designed to run on pull_request events and includes checks to prevent running on forks or on patches generated by itself. It uses actions/checkout and peter-evans/autopep8, and peter-evans/create-pull-request. ```yaml name: autopep8 on: pull_request jobs: autopep8: # Check if the PR is not raised by this workflow and is not from a fork if: startsWith(github.head_ref, 'autopep8-patches') == false && github.event.pull_request.head.repo.full_name == github.repository runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: ref: ${{ github.head_ref }} - name: autopep8 id: autopep8 uses: peter-evans/autopep8@v1 with: args: --exit-code --recursive --in-place --aggressive --aggressive . - name: Set autopep8 branch name id: vars run: | branch-name="autopep8-patches/${{ github.head_ref }}" echo "branch-name=$branch-name" >> $GITHUB_OUTPUT - name: Create Pull Request if: steps.autopep8.outputs.exit-code == 2 uses: peter-evans/create-pull-request@v8 with: commit-message: autopep8 action fixes title: Fixes by autopep8 action body: This is an auto-generated PR with fixes by autopep8. labels: autopep8, automated pr branch: ${{ steps.vars.outputs.branch-name }} - name: Fail if autopep8 made changes if: steps.autopep8.outputs.exit-code == 2 run: exit 1 ``` -------------------------------- ### Update Fork with Upstream Changes using GitHub Actions Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This workflow synchronizes a fork's default branch with its upstream repository. It fetches changes from the upstream, resets the local branch, and then uses the create-pull-request action to open a PR with the updates. Requires a PAT with 'repo' scope, and potentially 'workflow' scope if upstream modifies workflow files. ```yaml name: Update fork on: schedule: - cron: '0 0 * * 0' jobs: updateFork: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: repository: fork-owner/repo - name: Reset the default branch with upstream changes run: | git remote add upstream https://github.com/owner/repo.git git fetch upstream main:upstream-main git reset --hard upstream-main - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.PAT }} branch: upstream-changes ``` -------------------------------- ### Checkout Branch with actions/checkout@v1 Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/updating.md Demonstrates how to check out a specific branch using actions/checkout@v1 when the default v2 is not suitable. This requires an additional step to explicitly check out the desired branch. ```yaml - uses: actions/checkout@v1 - name: Checkout branch run: git checkout "${GITHUB_REF:11}" ``` -------------------------------- ### Configure Proxy Settings Source: https://context7.com/peter-evans/create-pull-request/llms.txt Demonstrates how to route the action through a proxy server, which is necessary for self-hosted runners operating behind corporate firewalls. ```yaml name: Proxy Configuration on: workflow_dispatch: jobs: proxy-pr: runs-on: self-hosted steps: - uses: actions/checkout@v6 - name: Make changes run: echo "Change behind proxy" > proxied.txt - name: Create Pull Request uses: peter-evans/create-pull-request@v8 env: https_proxy: http://proxy.example.com:8080 with: title: Update from behind proxy branch: proxy/auto-update ``` -------------------------------- ### Configure Push to Fork in v3 Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/updating.md Demonstrates the use of the push-to-fork input in v3, which replaces the deprecated request-to-parent input for managing pull request branches on forks. ```yaml - uses: actions/checkout@v2 # Make changes to pull request here - uses: peter-evans/create-pull-request@v3 with: token: ${{ secrets.MACHINE_USER_PAT }} push-to-fork: machine-user/fork-of-repository ``` -------------------------------- ### Configure Multi-line Labels Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/updating.md Shows how to provide labels as a newline-separated list in YAML, a feature introduced to improve readability for multiple input values. ```yaml labels: | chore dependencies automated ``` -------------------------------- ### Push to a fork using GitHub App tokens Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md Demonstrates how to use a generated GitHub App token to push a branch to a fork while using the default GITHUB_TOKEN to create the pull request in the parent repository. Requires maintainer-can-modify to be set to false. ```yaml - uses: actions/create-github-app-token@v2 id: generate-token with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} owner: owner repositories: fork-of-repo - uses: actions/checkout@v6 # Make changes to pull request here - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: branch-token: ${{ steps.generate-token.outputs.token }} push-to-fork: owner/fork-of-repo maintainer-can-modify: false ``` -------------------------------- ### Authenticate with GitHub App Tokens Source: https://context7.com/peter-evans/create-pull-request/llms.txt Demonstrates how to use GitHub App tokens for fine-grained permissions. This approach allows the action to trigger subsequent workflow runs that are otherwise ignored by standard PATs. ```yaml name: GitHub App Token Authentication on: schedule: - cron: '0 0 * * *' jobs: app-auth-pr: runs-on: ubuntu-latest steps: - uses: actions/create-github-app-token@v2 id: generate-token with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} - uses: actions/checkout@v6 - name: Update data run: ./fetch-latest-data.sh - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ steps.generate-token.outputs.token }} sign-commits: true commit-message: Daily data refresh title: '[Data] Daily automated refresh' branch: data/daily-refresh ``` -------------------------------- ### Filter Push Events for Branches Only (YAML) Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This configuration snippet demonstrates how to filter push events in a GitHub Actions workflow to only trigger for branches, excluding tags. It uses the `branches` key within the `on.push` event. This is useful for workflows that should not run on tag pushes. ```yaml on: push: branches: - '**' ``` -------------------------------- ### Override default checkout reference Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md Demonstrates how to use the official actions/checkout action to checkout a specific branch reference instead of the default GITHUB_SHA. ```yaml - uses: actions/checkout@v6 with: ref: develop ``` -------------------------------- ### Create Custom Commits Before Action (Bash) Source: https://github.com/peter-evans/create-pull-request/blob/main/README.md This example illustrates how to manually create Git commits within a GitHub Actions workflow before executing the create-pull-request action. It covers setting user information, committing modified files, and adding untracked files. ```bash steps: - uses: actions/checkout@v6 - name: Create commits run: | git config user.name 'Peter Evans' git config user.email 'peter-evans@users.noreply.github.com' date +%s > report.txt git commit -am "Modify tracked file during workflow" date +%s > new-report.txt git add -A git commit -m "Add untracked file during workflow" - name: Uncommitted change run: date +%s > report.txt - name: Create Pull Request uses: peter-evans/create-pull-request@v8 ``` -------------------------------- ### Complete Configuration Workflow for create-pull-request Source: https://context7.com/peter-evans/create-pull-request/llms.txt A comprehensive YAML workflow demonstrating all major configuration options for the create-pull-request action. It includes steps for checking out code, modifying files, creating the pull request with custom metadata, and handling output notifications. ```yaml name: Complete Reference Workflow on: push: branches: [main] permissions: contents: write pull-requests: write jobs: createPullRequest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - name: Make changes run: date +%s > report.txt - name: Create Pull Request id: cpr uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.PAT }} commit-message: Update report committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com> signoff: false branch: example-patches delete-branch: true title: '[Example] Update report' body: | Update report - Updated with *today's* date - Auto-generated by [create-pull-request][1] [1]: https://github.com/peter-evans/create-pull-request labels: | report automated pr assignees: peter-evans reviewers: peter-evans team-reviewers: | developers qa-team milestone: 1 draft: false - name: Show PR annotation if: ${{ steps.cpr.outputs.pull-request-url && steps.cpr.outputs.pull-request-operation != 'none' }} run: | echo "::notice::${{ steps.cpr.outputs.pull-request-url }} was ${{ steps.cpr.outputs.pull-request-operation }}." ``` -------------------------------- ### Enable Commit Signature Verification for Bots Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md Configures the action to sign commits using the default GITHUB_TOKEN or a GitHub App token. Setting sign-commits to true ensures commits are marked as verified by GitHub. ```yaml steps: - uses: actions/checkout@v6 - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: sign-commits: true ``` ```yaml steps: - uses: actions/checkout@v6 - uses: actions/create-github-app-token@v2 id: generate-token with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ steps.generate-token.outputs.token }} sign-commits: true ``` -------------------------------- ### Dynamically Set Pull Request Title and Body (YAML) Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md This snippet illustrates how to dynamically set the title and body of a pull request created by the `create-pull-request` action. It uses a previous workflow step with `id: vars` to define output variables (`pr_title`, `pr_body`) which are then referenced in the `with` block of the create-pull-request action. This allows for dynamic content, such as timestamps. ```yaml - name: Set output variables id: vars run: | pr_title="[Test] Add report file $(date +%d-%m-%Y)" pr_body="This PR was auto-generated on $(date +%d-%m-%Y) \ by [create-pull-request](https://github.com/peter-evans/create-pull-request)." echo "pr_title=$pr_title" >> $GITHUB_OUTPUT echo "pr_body=$pr_body" >> $GITHUB_OUTPUT - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: title: ${{ steps.vars.outputs.pr_title }} body: ${{ steps.vars.outputs.pr_body }} ``` -------------------------------- ### Configure PR Metadata: Labels, Assignees, Reviewers (YAML) Source: https://context7.com/peter-evans/create-pull-request/llms.txt This workflow demonstrates comprehensive configuration of pull request metadata using the create-pull-request action. It includes setting labels, assignees, individual reviewers, team reviewers, and a milestone. A personal access token (PAT) is required for some operations. ```yaml name: Full PR Configurationon: workflow_dispatch: jobs: full-config-pr: runs-on: ubuntu-latest permissions: contents: write pull-requests: write steps: - uses: actions/checkout@v6 - name: Make changes run: npm audit fix - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.PAT }} commit-message: Security vulnerability fixes title: '[Security] Automated vulnerability patches' body: | ## Summary Automated security patches from npm audit. ## Changes - Updated vulnerable dependencies - Applied recommended fixes labels: | security dependencies automated assignees: | security-lead maintainer reviewers: | senior-dev security-reviewer team-reviewers: | security-team core-maintainers milestone: 1 branch: security/auto-patches ``` -------------------------------- ### Configure Authentication Tokens for Pull Requests Source: https://context7.com/peter-evans/create-pull-request/llms.txt Demonstrates using a Personal Access Token (PAT) to trigger subsequent workflows upon pull request creation. ```yaml name: Create PR with PAT Token on: schedule: - cron: '0 10 * * 1' jobs: update: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - name: Update dependencies run: npm update - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.PAT }} commit-message: Update dependencies title: Weekly dependency updates body: | Automated dependency updates. Auto-generated by create-pull-request action. branch: deps/weekly-update ``` -------------------------------- ### Configure Proxy Support for Self-Hosted Runners Source: https://github.com/peter-evans/create-pull-request/blob/main/README.md Sets up the `https_proxy` environment variable to enable proxy support for self-hosted runners operating behind a corporate proxy. Replace `` and `` with your specific proxy details. ```yaml - name: Create Pull Request uses: peter-evans/create-pull-request@v8 env: https_proxy: http://: ``` -------------------------------- ### Format Commit Message and Description Source: https://github.com/peter-evans/create-pull-request/blob/main/README.md Demonstrates how to use the `commit-message` input to provide both a commit message and a detailed description. A single blank line separates the message from the description, allowing for multi-line descriptions. ```yaml commit-message: | the first line is the commit message the commit description starts after a blank line and can be multiple lines ``` -------------------------------- ### Push to Fork with Machine Account PAT for create-pull-request Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md Sets up the create-pull-request action to push changes to a fork of the target repository using a Personal Access Token (PAT) from a dedicated machine account. This follows the principle of least privilege, where the machine account has read-only access to the main repository. ```yaml - uses: actions/checkout@v6 # Make changes to pull request here - uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.MACHINE_USER_PAT }} push-to-fork: machine-user/fork-of-repository ``` -------------------------------- ### Checkout Remote Repository for Pull Request Creation Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md This snippet demonstrates how to check out a repository different from the one where the workflow is executing. This is necessary when creating pull requests in a remote repository. It requires a Personal Access Token (PAT) as the default GITHUB_TOKEN will not suffice. The `repository` input specifies the target repository. ```yaml - uses: actions/checkout@v6 with: token: ${{ secrets.PAT }} repository: owner/repo # Make changes to pull request here - uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.PAT }} ``` -------------------------------- ### Authenticate with SSH Deploy Keys Source: https://context7.com/peter-evans/create-pull-request/llms.txt Uses SSH keys for authentication, which allows the action to trigger push-based workflows without needing a PAT. Note that this method is incompatible with commit signing. ```yaml name: SSH Deploy Key Authentication on: push: branches: [main] jobs: ssh-pr: runs-on: ubuntu-latest permissions: contents: write pull-requests: write steps: - uses: actions/checkout@v6 with: ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} - name: Make changes run: ./generate-content.sh - name: Create Pull Request uses: peter-evans/create-pull-request@v8 with: title: SSH-pushed update branch: ssh/auto-update ``` -------------------------------- ### Export GPG Private Key for GitHub Secrets Source: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md Command to export a GPG private key to the clipboard for storage in repository secrets. This is a prerequisite for enabling commit signing in GitHub Actions. ```bash gpg --armor --export-secret-key email@example.com | pbcopy ``` -------------------------------- ### Action Inputs Source: https://github.com/peter-evans/create-pull-request/blob/main/README.md This section details all the available inputs for the create-pull-request action. All inputs are optional and will use sensible defaults if not provided. ```APIDOC ## Action Inputs All inputs are **optional**. If not set, sensible defaults will be used. ### Parameters #### Request Body Parameters - **token** (string) - Optional - The token that the action will use to create and update the pull request. Defaults to `GITHUB_TOKEN`. - **branch-token** (string) - Optional - The token that the action will use to create and update the branch. Defaults to the value of `token`. - **path** (string) - Optional - Relative path under `GITHUB_WORKSPACE` to the repository. Defaults to `GITHUB_WORKSPACE`. - **add-paths** (string) - Optional - A comma or newline-separated list of file paths to commit. Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. If no paths are specified, all new and modified files are added. - **commit-message** (string) - Optional - The message to use when committing changes. Defaults to `[create-pull-request] automated change`. - **committer** (string) - Optional - The committer name and email address in the format `Display Name `. Defaults to the GitHub Actions bot user on github.com (`github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>`). - **author** (string) - Optional - The author name and email address in the format `Display Name `. Defaults to the user who triggered the workflow run (`${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>`). - **signoff** (boolean) - Optional - Add [`Signed-off-by`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---signoff) line by the committer at the end of the commit log message. Defaults to `false`. - **branch** (string) - Optional - The pull request branch name. Defaults to `create-pull-request/patch`. - **delete-branch** (boolean) - Optional - Delete the `branch` if it doesn't have an active pull request associated with it. Defaults to `false`. - **branch-suffix** (string) - Optional - The branch suffix type when using the alternative branching strategy. Valid values are `random`, `timestamp` and `short-commit-hash`. - **base** (string) - Optional - Sets the pull request base branch. Defaults to the branch checked out in the workflow. - **push-to-fork** (string) - Optional - A fork of the checked-out parent repository to which the pull request branch will be pushed. e.g. `owner/repo-fork`. The pull request will be created to merge the fork's branch into the parent's base. - **sign-commits** (boolean) - Optional - Sign commits as `github-actions[bot]` when using `GITHUB_TOKEN`, or your own bot when using [GitHub App tokens](docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens). Defaults to `false`. - **title** (string) - Optional - The title of the pull request. Defaults to `Changes by create-pull-request action`. - **body** (string) - Optional - The body of the pull request. Defaults to `Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action`. - **body-path** (string) - Optional - The path to a file containing the pull request body. Takes precedence over `body`. - **labels** (string) - Optional - A comma or newline-separated list of labels. - **assignees** (string) - Optional - A comma or newline-separated list of assignees (GitHub usernames). - **reviewers** (string) - Optional - A comma or newline-separated list of reviewers (GitHub usernames) to request a review from. - **team-reviewers** (string) - Optional - A comma or newline-separated list of GitHub teams to request a review from. Note that a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token), or equivalent [GitHub App permissions](docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens), are required. - **milestone** (integer) - Optional - The number of the milestone to associate this pull request with. - **draft** (string) - Optional - Create a [draft pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). Valid values are `true` (only on create), `always-true` (on create and update), and `false`. Defaults to `false`. - **maintainer-can-modify** (boolean) - Optional - Indicates whether [maintainers can modify](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) the pull request. Defaults to `true`. ```