Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guidance for creating a "Hotfix Backfill" PR #3495

Open
jasondamour opened this issue Nov 7, 2024 · 1 comment
Open

Guidance for creating a "Hotfix Backfill" PR #3495

jasondamour opened this issue Nov 7, 2024 · 1 comment

Comments

@jasondamour
Copy link

Subject of the issue

Hello,

In our repo we have a dev branch and a prod branch. If a commit is merged (with rebase) directly into prod (i.e. a "hotfix"), I want Github Actions to create a PR from a temporary branch with the new prod commits to dev (i.e. "backfilling hotfix").

Here is the configuration I've tried thus far:

on:
  pull_request:
    branches:
      - prod
    types:
      - closed

jobs:
  backfill:
    name: Backfill Hotfix Commits
    if:
      github.event.pull_request.merged == true &&
      startsWith(github.event.pull_request.head.ref, 'hotfix-')
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Open Pull Request
        id: create_pr
        uses: peter-evans/create-pull-request@v7
        with:
          token: ${{ secrets.SERVICE_ACCOUNT_GITHUB_TOKEN }}
          base: dev
          branch: |
           sync-dev-with-${{ github.event.pull_request.head.ref }}

Logs:

Checking the base repository state
  /usr/bin/git symbolic-ref HEAD --short
  prod

Pull request branch to create or update set to 'test-sync-dev-with-hotfix-20241106-test-hotfix-pr-2'

Create or update the pull request branch
  /usr/bin/git symbolic-ref HEAD --short
  prod
  Working base is branch 'prod'
  /usr/bin/git checkout --progress -B c626ceba-2990-4c1f-af60-fb1f8e078f7b HEAD --
  Switched to a new branch 'c626ceba-2990-4c1f-af60-fb1f8e078f7b'
  /usr/bin/git status --porcelain -unormal --
  /usr/bin/git diff --quiet --
  /usr/bin/git diff --quiet --staged --
  /usr/bin/git stash push --include-untracked
  No local changes to save
  Resetting working base branch 'prod'
  /usr/bin/git checkout --progress prod --
  Switched to branch 'prod'
  Your branch is up to date with 'origin/prod'.

  /usr/bin/git reset --hard origin/prod
  HEAD is now at b52347e fix: missing `-m` for invoke

  Rebasing commits made to branch 'prod' on to base branch 'dev'
  /usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force --depth=1 origin dev:dev
  remote: Total 5 (delta 4), reused 1 (delta 0), pack-reused 0 (from 0)        
  From https://github.com/x/x
   * [new branch]      dev        -> dev
   * [new branch]      dev        -> origin/dev
   * 
  /usr/bin/git checkout --progress dev --
  Switched to branch 'dev'

  /usr/bin/git rev-list --reverse prod..c626ceba-2990-4c1f-af60-fb1f8e078f7b .
  /usr/bin/git checkout --progress -B c626ceba-2990-4c1f-af60-fb1f8e078f7b HEAD --
  Switched to and reset branch 'c626ceba-2990-4c1f-af60-fb1f8e078f7b'

  /usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force --depth=1 origin dev:dev
  remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)      
  
  /usr/bin/git rev-list --right-only --count dev...c626ceba-2990-4c1f-af60-fb1f8e078f7b
  0

  /usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force --depth=10 origin test-sync-dev-with-hotfix-20241106-test-hotfix-pr-2:refs/remotes/origin/test-sync-dev-with-hotfix-20241106-test-hotfix-pr-2
  fatal: couldn't find remote ref test-sync-dev-with-hotfix-20241106-test-hotfix-pr-2

  Pull request branch 'test-sync-dev-with-hotfix-20241106-test-hotfix-pr-2' does not exist yet.
  /usr/bin/git checkout --progress -B test-sync-dev-with-hotfix-20241106-test-hotfix-pr-2 c626ceba-2990-4c1f-af60-fb1f8e078f7b --
  Switched to a new branch 'test-sync-dev-with-hotfix-20241106-test-hotfix-pr-2'

  /usr/bin/git rev-list --right-only --count dev...test-sync-dev-with-hotfix-20241106-test-hotfix-pr-2
  0

  Branch 'test-sync-dev-with-hotfix-20241106-test-hotfix-pr-2' is not ahead of base 'dev' and will not be created
  /usr/bin/git rev-parse dev
  42c96a3fa270dfe5a20ef10ff29cefcfd7aca5e4
  8e27f29531c1f2226fb23f956c18bfb6f9196359

Potentially important callouts:

  • This workflow is triggered on the PR Closed event, I'm not sure how that impacts git state using the default checkout action

    • I tried explicitly setting the ref on checkout to prod, same issues
  • It seems to me that the PR branch (test-sync-dev-with-hotfix-20241106-test-hotfix-pr-2) is actually ahead of dev, based on the commits in the logs above:

    • Prod is on b52347e (b52347ee221ddd8b9cb5b059dceb62a962f40987)
    • Dev is on 42c96a3fa270dfe5a20ef10ff29cefcfd7aca5e4
    • Locally if I run the same command as this action, I get a different result
➜  git rev-list --right-only 42c96a3fa270dfe5a20ef10ff29cefcfd7aca5e4...b52347ee221ddd8b9cb5b059dceb62a962f40987
b52347ee221ddd8b9cb5b059dceb62a962f40987
9224799f83439ae686f3ad14c3a8e5ef123ef3d6

➜  git rev-list --right-only --count 42c96a3fa270dfe5a20ef10ff29cefcfd7aca5e4...b52347ee221ddd8b9cb5b059dceb62a962f40987
2
  • The commit ID of prod logged by the action (which is the desired content of the PR) b52347ee221ddd8b9cb5b059dceb62a962f40987 does not exist on the prod branch

    • The same commit has a different SHA when I check the prod branch: 921e1a3afa102e3d96139f59b62a3e9deeda6978
  • It seems like the lack of diff in the action is caused by Rebasing commits made to branch 'prod' on to base branch 'dev'

    • Is there a way to disable this rebase step, if it masks the actually commits I want to merge?

One last note:

  • The action always fails silently. In use-cases like this, failure to create a PR is always an issue. Is it possible to optionally fail the action on failure to create PR?

Steps to reproduce

If this issue is describing a possible bug please provide (or link to) your GitHub Actions workflow.

@peter-evans
Copy link
Owner

Hi @jasondamour

What you are doing currently won't work because you aren't making any changes for the action to raise in a PR.

I've not tried to do anything like this before, but you could try checking out dev and then cherrypicking the hotfix commit onto dev. Then when the action runs it will raise that cherrypicked commit in a PR. See https://github.com/peter-evans/create-pull-request#create-your-own-commits

The action always fails silently. In use-cases like this, failure to create a PR is always an issue. Is it possible to optionally fail the action on failure to create PR?

If you always expect a PR to be created then you can check the action outputs in a step after the action has run.
https://github.com/peter-evans/create-pull-request#action-outputs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants