Skip to content

FailFastPeterEvansCreatePullRequest

peter-evans/create-pull-request has unsafe edge cases, use gh pr create instead.

Defined by FailFastActionsRule which supports workflows, actions in the "Default" ruleset along with FailFastUploadArtifact, FailFastPublishUnitTestResults, FailFastSoftpropsGhRelease.

Description

Action doesn't allow fast fail, and therefore black-listed.

From its documentation:

If there are no changes (i.e. no diff exists with the checked-out base branch), no pull request will be created and the action exits silently. -- README

This is error-prone: if the PR content generation accidentally breaks, there's no way to detect it. PR creation step just passes as if everything is all right. There are outputs from the action which could be checked for null/empty/undefined, but any user of this action needs to be aware of this. This is akin to C's numeric return codes, the world has moved away from that approach.

There's also confusion as seen in the issue list.

The only way to notice this is by checking the logs of the action:

Branch 'to-create' is not ahead of base 'main' and will not be created
and this line is not even a warning.

Without the ability to fail fast, this action is not fit for production usage.

The recommended replacement is gh pr create, which is a first party GitHub CLI tool with behaviors fit for the GitHub Actions environment.

Compliant example

Use the gh CLI to create a PR.

example.yml

on: push
jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - name: "Create Pull Request"
        env:
          TITLE: Example
          BODY: |
            Example PR description
            - Updated foo
            - Removed bar
        run: >
          gh pr create
          --title "${TITLE}"
          --body "${BODY}"
          --draft
          --label "report"
          --label "automated pr"

Non-compliant example

Using create-pull-request action.

example.yml

on: push
jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - name: "Create Pull Request"
        uses: peter-evans/create-pull-request@v6
        with:
          title: 'Example'
          body: |
            Example PR description
            - Updated foo
            - Removed bar
          labels: |
            report
            automated pr
          draft: true

  • Line 6: Use gh pr create to open a PR instead of Step["Create Pull Request"] in Job[example].