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

PR branch is not ahead of base 'main' and will not be created #3575

Open
petlitskiy opened this issue Dec 18, 2024 · 10 comments
Open

PR branch is not ahead of base 'main' and will not be created #3575

petlitskiy opened this issue Dec 18, 2024 · 10 comments

Comments

@petlitskiy
Copy link

Subject of the issue

Action creates PR from repo A to repo B. And (very rarely) we are faced with

 Branch 'deploy-pr-1498-...' is not ahead of base 'main' and will not be created

After we have renewed with new commits - we can recreate the target PR (refreshed with new commits as well).

Looks like another PR succeeded and merged to the main branch on repo B at the moment of creation of the first mentioned PR (from repo A).

Steps to reproduce

Is there any option on this action that provides retries of PR creation for some time with some pause periods?

@peter-evans
Copy link
Owner

Hi @petlitskiy

I'm not sure I understand your use case. If you show me your workflow(s) I might be able to help.

Is there any option on this action that provides retries of PR creation for some time with some pause periods?

The only retry that occurs is for retryable errors from the API. There's no other retry options.

@gomeology
Copy link

gomeology commented Jan 1, 2025

`
- name: Raise Pull Request
uses: peter-evans/create-pull-request@v7
permissions:
pull-requests: write
with:
token: ${{ secrets.TOKEN }}
commit-message: |
the first line is the commit message

        the commit description starts
        after a blank line and can be
        multiple lines
      #base: main defaults to check out branch
      committer: forgejo-runner[bot] <[email protected]>
      author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
      signoff: false
      branch: bot/updates
      delete-branch: true
      title: "Generated PR from ${{ env.GIT_COMMIT_SHORT_SHA }}"
      body: |
        This PR was automatically generated from commit ${{ env.GIT_COMMIT_SHORT_SHA }}.
        The author of the commit was ${{ github.actor }}.
        The commit message was: ${{ env.GIT_COMMIT_MESSAGE_SUBJECT }}.
      labels: |
        report
        automated pr
      draft: false

##[group]Checking the base repository state
[command]/usr/bin/git symbolic-ref HEAD --short
me
Working base is branch 'me'
[command]/usr/bin/git remote prune origin
##[endgroup]
Pull request branch to create or update set to 'bot/updates'
##[group]Configuring the committer and author
Configured git committer as 'forgejo-runner[bot] [email protected]'
Configured git author as 'zero [email protected]'
##[endgroup]
##[group]Create or update the pull request branch
[command]/usr/bin/git symbolic-ref HEAD --short
me
Working base is branch 'me'
[command]/usr/bin/git checkout --progress -B 93f53b0c-f653-478e-847e-e7777c70094a HEAD --
Switched to a new branch '93f53b0c-f653-478e-847e-e7777c70094a'
[command]/usr/bin/git status --porcelain -unormal
[command]/usr/bin/git diff --quiet
[command]/usr/bin/git diff --quiet --staged
Resetting working base branch 'me'
[command]/usr/bin/git checkout --progress me --
Switched to branch 'me'
Your branch is up to date with 'origin/me'.
[command]/usr/bin/git reset --hard origin/me
HEAD is now at 785e180 Quick commit
[command]/usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --unshallow origin bot/updates:refs/remotes/origin/bot/updates
fatal: couldn't find remote ref bot/updates
Pull request branch 'bot/updates' does not exist yet.
[command]/usr/bin/git checkout --progress -B bot/updates 93f53b0c-f653-478e-847e-e7777c70094a --
Switched to a new branch 'bot/updates'
[command]/usr/bin/git rev-list --right-only --count me...bot/updates
0
Branch 'bot/updates' is not ahead of base 'me' and will not be created
[command]/usr/bin/git rev-parse HEAD
785e1800c9649af2fb42ee78a1701c5d600ce3ed
[command]/usr/bin/git branch --delete --force 93f53b0c-f653-478e-847e-e7777c70094a
Deleted branch 93f53b0c-f653-478e-847e-e7777c70094a (was 785e180).
##[endgroup]
`

testing senario is created a fresh repo. added the workflow. created several test branches add random crap and sent it off to see if it create a pr request it says the same thing. branch is not ahead.

@peter-evans
Copy link
Owner

@gomeology I need to see the whole workflow, not just the action step. It matters what triggers the workflow and what changes you are making before the action runs.

@gomeology
Copy link

@peter-evans ok so maybe i misunderstood what this is doing. when looking at your example i have to add date+%S > report.txt. is this because it needs to be modified from within the workflow? Im new to this so bear with me. But I want to create a PR whenever a new push is made. I now added your date command line and I am getting "::error::Not found.%0A". im guessing this is because the token is not getting to where it needs to be. but here is the workflow. Can you also answer if i need the 'make changes to pull request' for this to work?

`
name: MyFunctions Module Testing and Analysis

on:
push:
Merge:

jobs:
test-and-analyze:
runs-on: docker
image: ubuntu-latest

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

  - name: Expose git commit data
    uses: https://github.com/rlespinasse/[email protected]

  - name: Print git commit data
    run: |
      echo "Get commit info"
      echo " - ${{ env.GIT_COMMIT_SHA }}"
      echo " - ${{ env.GIT_COMMIT_SHORT_SHA }}"
      echo "Get author info"
      echo " - ${{ env.GIT_COMMIT_AUTHOR }}"
      echo " - ${{ env.GIT_COMMIT_AUTHOR_NAME }}"
      echo " - ${{ env.GIT_COMMIT_AUTHOR_EMAIL }}"
      echo "Get committer info"
      echo " - ${{ env.GIT_COMMIT_COMMITTER }}"
      echo " - ${{ env.GIT_COMMIT_COMMITTER_NAME }}"
      echo " - ${{ env.GIT_COMMIT_COMMITTER_EMAIL }}"
      echo "Get message info"
      echo " - ${{ env.GIT_COMMIT_MESSAGE_SUBJECT }}"
      echo " - ${{ env.GIT_COMMIT_MESSAGE_SUBJECT_SANITIZED }}"
      echo " - ${{ env.GIT_COMMIT_MESSAGE_BODY }}"

  - name: Make changes to pull request
    run: date +%s > report.txt

  - name: Raise Pull Request
    uses: peter-evans/create-pull-request@v7
    permissions:
      pull-requests: write
    token: ${{ secrets.TOKEN }} #PAT
    commit-message: |
      the first line is the commit message

      the commit description starts
      after a blank line and can be
      multiple lines
    #base: main defaults to check out branch
    committer: forgejo-runner[bot] <[email protected]>
    author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@selfhosted.dev>
    signoff: false
    branch: bot/updates
    delete-branch: true
    title: "Generated PR from ${{ env.GIT_COMMIT_SHORT_SHA }}"
    body: |
      This PR was automatically generated from commit ${{ env.GIT_COMMIT_SHORT_SHA }}.
      The author of the commit was ${{ github.actor }}.
      The commit message was: ${{ env.GIT_COMMIT_MESSAGE_SUBJECT }}.
    labels: |
      report
      automated pr
    draft: false

`

@karateviktor
Copy link

karateviktor commented Feb 7, 2025

Hello,
I am facing the same issue =>

Create or update the pull request branch
/usr/bin/git symbolic-ref HEAD --short
master
Working base is branch 'master'
/usr/bin/git checkout --progress -B 31f5a6fb-XXX HEAD --
Switched to a new branch '31f5a6fb-XXX'
..
No local changes to save
Resetting working base branch 'master'
/usr/bin/git checkout --progress master --
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
/usr/bin/git reset --hard origin/master
HEAD is now at 2adXXX Namespace as per XXX (#1780)
/usr/bin/git rev-list --right-only --count master...31f5a6fb-XXX
0
/usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force --depth=10 origin new-branch-name:refs/remotes/origin/new-branch-name
fatal: couldn't find remote ref new-branch-name
Pull request branch 'new-branch-name' does not exist yet.
/usr/bin/git checkout --progress -B new-branch-name 31f5a6fb-XXX --
Switched to a new branch 'new-branch-name'
/usr/bin/git rev-list --right-only --count master...new-branch-name
0
Branch 'new-branch-name' is not ahead of base 'master' and will not be created
/usr/bin/git rev-parse HEAD ..
/usr/bin/git branch --delete --force 31f5a6fb-XXX
Deleted branch 31f5a6fb-XXX (was 2adXXX).
/usr/bin/git checkout --progress master --
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

I checked earlier successful runs and it created the new branch if it didn't exist =>

Pull request branch 'gsd-pipelines.XXX' does not exist yet.
/usr/bin/git checkout --progress -B gsd-pipelines.XXX ac89XXX --
Switched to a new branch 'gsd-pipelines.XXX'
/usr/bin/git rev-list --right-only --count master...gsd-pipelines.XXX
1
Created branch 'gsd-pipelines.XXX'

This is a "new" issues which arised in the last ~2 months. Before that it was running fine.
We are using create-pull-request@v6. Ill try update to v7 and see if it fixes this..

@julienroubieu
Copy link

Hi @peter-evans, we're having the same issue here, on both v6 and v7.
When the branch does not exist it's not created. When it exists it's deleted.

I'm including the output from v7 below.
The tasks before download updated i18n files.

Initializing the repository
  /usr/bin/git init /home/runner/work/myproject/myproject
  hint: Using 'master' as the name for the initial branch. This default branch name
  hint: is subject to change. To configure the initial branch name to use in all
  hint: of your new repositories, which will suppress this warning, call:
  hint:
  hint:   git config --global init.defaultBranch <name>
  hint:
  hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
  hint: 'development'. The just-created branch can be renamed via this command:
  hint:
  hint:   git branch -m <name>
  Initialized empty Git repository in /home/runner/work/myproject/myproject/.git/
  /usr/bin/git remote add origin https://github.com/org/myproject
Disabling automatic garbage collection
  /usr/bin/git config --local gc.auto 0
Setting up auth
  /usr/bin/git config --local --name-only --get-regexp core\.sshCommand
  /usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :"
  /usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader
  /usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :"
  /usr/bin/git config --local http.https://github.com/.extraheader AUTHORIZATION: basic ***
Fetching the repository
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +c23e474a8b65ef2262551b0dae1b58ffa1768ea2:refs/remotes/origin/master
  From https://github.com/org/myproject
   * [new ref]         c23e474a8b65ef2262551b0dae1b58ffa1768ea2 -> origin/master
Determining the checkout info
/usr/bin/git sparse-checkout disable
/usr/bin/git config --local --unset-all extensions.worktreeConfig
Checking out the ref
  /usr/bin/git checkout --progress --force -B master refs/remotes/origin/master
  Reset branch 'master'
  branch 'master' set up to track 'origin/master'.
/usr/bin/git log -1 --format=%H
c23e474a8b65ef2262551b0dae1b58ffa1768ea2

-------

Run phrase -t $PHRASE_AUTH_TOKEN pull
  phrase -t $PHRASE_AUTH_TOKEN pull
  shell: /usr/bin/bash -e {0}
  env:
    PHRASE_AUTH_TOKEN: ***
Downloaded Dutch to src/messages/nl.json
Downloaded English to src/messages/en.json
Downloaded French to src/messages/fr.json
Downloaded German to src/messages/de.json
Downloaded Italian to src/messages/it.json
Downloaded Portuguese to src/messages/pt.json
Downloaded Spanish to src/messages/es.json

-------

Run phrase -t $PHRASE_AUTH_TOKEN pull
  phrase -t $PHRASE_AUTH_TOKEN pull
  shell: /usr/bin/bash -e {0}
  env:
    PHRASE_AUTH_TOKEN: ***
Downloaded de to src/i18n/locales/de.json
Downloaded en to src/i18n/locales/en.json
Downloaded es to src/i18n/locales/es.json
Downloaded fr to src/i18n/locales/fr.json
Downloaded it to src/i18n/locales/it.json
Downloaded nl to src/i18n/locales/nl.json
Downloaded pt to src/i18n/locales/pt.json

-------

Run peter-evans/create-pull-request@v7
  with:
    add-paths: "legacy/apps/myproject/src/messages/*.json"
  "apps/front/src/i18n/locales/*.json"
  
    body: Automated update of translation files
    branch: translations-pull
    commit-message: Updates translation files
    title: Automated Translation Update
    base: master
    delete-branch: true
    token: ***
    committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
    author: me <[email protected]>
    signoff: false
    sign-commits: false
    draft: false
    maintainer-can-modify: true

> Prepare git configuration
  /usr/bin/git config --global --name-only --get-regexp safe.directory /home/runner/work/myproject/myproject
  /usr/bin/git config --global --add safe.directory /home/runner/work/myproject/myproject
  /usr/bin/git config --local --get remote.origin.url
  https://github.com/org/myproject
  /usr/bin/git config --local --name-only --get-regexp http.https://github.com/.extraheader ^AUTHORIZATION:
  http.https://github.com/.extraheader
  /usr/bin/git config --local --get-regexp http.https://github.com/.extraheader ^AUTHORIZATION:
  http.https://github.com/.extraheader AUTHORIZATION: basic ***
  /usr/bin/git config --local --unset http.https://github.com/.extraheader ^AUTHORIZATION:
  Unset config key 'http.https://github.com/.extraheader'

> Determining the base and head repositories
Pull request branch target repository set to org/myproject

> Configuring credential for HTTPS authentication
  /usr/bin/git config --local http.https://github.com/.extraheader AUTHORIZATION: basic ***
  /usr/bin/git rev-parse --git-dir
  .git

> Checking the base repository state
  /usr/bin/git symbolic-ref HEAD --short
  master
  Working base is branch 'master'
  /usr/bin/git remote prune origin
Pull request branch to create or update set to 'translations-pull'

> Configuring the committer and author
  Configured git committer as 'github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>'
  Configured git author as 'me <[email protected]>'

> Create or update the pull request branch
  /usr/bin/git symbolic-ref HEAD --short
  master
  Working base is branch 'master'
  /usr/bin/git checkout --progress -B a5b19f57-9ae7-45c8-bd5f-9fb8056a342a HEAD --
  Switched to a new branch 'a5b19f57-9ae7-45c8-bd5f-9fb8056a342a'
  M	apps/front/src/i18n/locales/de.json
  M	apps/front/src/i18n/locales/en.json
  M	apps/front/src/i18n/locales/es.json
  M	apps/front/src/i18n/locales/fr.json
  M	apps/front/src/i18n/locales/it.json
  M	apps/front/src/i18n/locales/nl.json
  M	apps/front/src/i18n/locales/pt.json
  M	legacy/apps/myproject/src/messages/de.json
  M	legacy/apps/myproject/src/messages/en.json
  M	legacy/apps/myproject/src/messages/es.json
  M	legacy/apps/myproject/src/messages/fr.json
  M	legacy/apps/myproject/src/messages/it.json
  M	legacy/apps/myproject/src/messages/nl.json
  M	legacy/apps/myproject/src/messages/pt.json
  /usr/bin/git status --porcelain -unormal -- "legacy/apps/myproject/src/messages/*.json" "apps/front/src/i18n/locales/*.json"
  /usr/bin/git diff --quiet -- "legacy/apps/myproject/src/messages/*.json" "apps/front/src/i18n/locales/*.json"
  /usr/bin/git diff --quiet --staged -- "legacy/apps/myproject/src/messages/*.json" "apps/front/src/i18n/locales/*.json"
  /usr/bin/git stash push --include-untracked
  Saved working directory and index state WIP on a5b19f57-9ae7-45c8-bd5f-9fb8056a342a: c23e474 PROJ-24 Upgrades github action (#344)
  Resetting working base branch 'master'
  /usr/bin/git checkout --progress master --
  Switched to branch 'master'
  Your branch is up to date with 'origin/master'.
  /usr/bin/git reset --hard origin/master
  HEAD is now at c23e474 PROJ-24 Upgrades github action (#344)
  /usr/bin/git rev-list --right-only --count master...a5b19f57-9ae7-45c8-bd5f-9fb8056a342a
  0
  /usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force --depth=10 origin translations-pull:refs/remotes/origin/translations-pull
  fatal: couldn't find remote ref translations-pull
  Pull request branch 'translations-pull' does not exist yet.
  /usr/bin/git checkout --progress -B translations-pull a5b19f57-9ae7-45c8-bd5f-9fb8056a342a --
  Switched to a new branch 'translations-pull'
  /usr/bin/git rev-list --right-only --count master...translations-pull
  0
  Branch 'translations-pull' is not ahead of base 'master' and will not be created
  /usr/bin/git rev-parse master
  c23e474a8b65ef2262551b0dae1b58ffa1768ea2
  /usr/bin/git -c core.quotePath=false show --raw --cc --no-renames --no-abbrev --format=%H%n%T%n%P%n%G?%n%s%n%b%n###EOB### c23e474a8b65ef2262551b0dae1b58ffa1768ea2
  c23e474a8b65ef2262551b0dae1b58ffa1768ea2
  6f278dbf2c132c0e8d1aedcaaf3ae913ea80c5ca
  
  E
  PROJ-24 Upgrades github action (#344)
  This workflow is currently not working.
  We're having this issue: peter-evans/create-pull-request#3575
  Upgrading to the newest action version to see how it behaves on master.
  ###EOB###
  
  :000000 100644 0000000000000000000000000000000000000000 947f8839ed7e01ca8d44d8eff4e3b4909567557b A	.dockerignore
  :000000 100644 0000000000000000000000000000000000000000 ded3226083d2a22b5330f50f6ecfc0ded9a0ea16 A	.github/workflows/ci.yml
  [...]
  :000000 100644 0000000000000000000000000000000000000000 5550518b74b0126779113087c82ad3f3fc8d5dfe A	pnpm-workspace.yaml
  :000000 100644 0000000000000000000000000000000000000000 79672d1060eac535388045477ea94a5a1b24db15 A	turbo.json
  /usr/bin/git rev-parse translations-pull
  c23e474a8b65ef2262551b0dae1b58ffa1768ea2
  /usr/bin/git branch --delete --force a5b19f57-9ae7-45c8-bd5f-9fb8056a342a
  Deleted branch a5b19f57-9ae7-45c8-bd5f-9fb8056a342a (was c23e474).
  /usr/bin/git checkout --progress master --
  Switched to branch 'master'
  Your branch is up to date with 'origin/master'.
  /usr/bin/git stash pop
  On branch master
  Your branch is up to date with 'origin/master'.
  
  Changes not staged for commit:
    (use "git add <file>..." to update what will be committed)
    (use "git restore <file>..." to discard changes in working directory)
  	modified:   apps/front/src/i18n/locales/de.json
  	modified:   apps/front/src/i18n/locales/en.json
  	modified:   apps/front/src/i18n/locales/es.json
  	modified:   apps/front/src/i18n/locales/fr.json
  	modified:   apps/front/src/i18n/locales/it.json
  	modified:   apps/front/src/i18n/locales/nl.json
  	modified:   apps/front/src/i18n/locales/pt.json
  	modified:   legacy/apps/myproject/src/messages/de.json
  	modified:   legacy/apps/myproject/src/messages/en.json
  	modified:   legacy/apps/myproject/src/messages/es.json
  	modified:   legacy/apps/myproject/src/messages/fr.json
  	modified:   legacy/apps/myproject/src/messages/it.json
  	modified:   legacy/apps/myproject/src/messages/nl.json
  	modified:   legacy/apps/myproject/src/messages/pt.json
  
  no changes added to commit (use "git add" and/or "git commit -a")
  Dropped refs/stash@{0} (93b17b09ebee8be62566784f431a6614c7c5cdf3)

> Setting outputs
  pull-request-branch = translations-pull
  pull-request-operation = none
  pull-request-head-sha = c23e474a8b65ef2262551b0dae1b58ffa1768ea2
  pull-request-commits-verified = false

> Restore git configuration
  /usr/bin/git config --local --name-only --get-regexp http.https://github.com/.extraheader ^AUTHORIZATION:
  http.https://github.com/.extraheader
  /usr/bin/git config --local --get-regexp http.https://github.com/.extraheader ^AUTHORIZATION:
  http.https://github.com/.extraheader AUTHORIZATION: basic ***
  /usr/bin/git config --local --unset http.https://github.com/.extraheader ^AUTHORIZATION:
  Unset config key 'http.https://github.com/.extraheader'
  /usr/bin/git config --local http.https://github.com/.extraheader AUTHORIZATION: basic ***
  Persisted git credentials restored
  /usr/bin/git config --global --unset safe.directory /home/runner/work/myproject/myproject

@peter-evans
Copy link
Owner

@julienroubieu According to the log, the action is not creating the pull request because there is no diff between the changes you are making in the workflow and master. If there's no diff then no pull request can be made.

  /usr/bin/git rev-list --right-only --count master...translations-pull
  0
  Branch 'translations-pull' is not ahead of base 'master' and will not be created

@julienroubieu
Copy link

Hi @peter-evans. The workflow is running from master and, as you can see in the ouput, does have some modified files after pulling from Phrase:

Switched to a new branch 'a5b19f57-9ae7-45c8-bd5f-9fb8056a342a'
  M	apps/front/src/i18n/locales/de.json
  M	apps/front/src/i18n/locales/en.json
  M	apps/front/src/i18n/locales/es.json
  ...

Am I misunderstanding how this action works, shouldn't it add and commit these modified files into a new translations-pull branch?

From what I'm seeing, these changes are stashed from branch a5b19f57-9ae7-45c8-bd5f-9fb8056a342a, but never popped nor committed before comparison with master. Is this expected?

@peter-evans
Copy link
Owner

@julienroubieu I think your problem is the add-paths input value. Please check here for how to configure that correctly.

    add-paths: "legacy/apps/myproject/src/messages/*.json"
  "apps/front/src/i18n/locales/*.json"

Try:

    add-paths: |
      legacy/apps/myproject/src/messages/*.json
      apps/front/src/i18n/locales/*.json

@julienroubieu
Copy link

Hi Peter, good catch! Apparently the quotes were the issue, I had this:

          add-paths: |
            "legacy/apps/myproject/src/messages/*.json"
            "apps/front/src/i18n/locales/*.json"

I removed the quotes and the action worked as expected.

Thank you!

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

5 participants