Update citations fails on pull request close trigger
vincerubinetti opened this issue · 8 comments
The process '/usr/bin/git' failed with exit code 1
The update-citations
workflow runs on pull request activity, including the "close" event. That is so the build-preview
workflow can delete the PR preview folder on the gh-pages
branch when the PR is closed.
I believe the error being reported is because the git ref (needed forupdate-citations
) no longer exists when the pull request is closed.
In reality, when it's a pull request and it's being closed, update-citations
should not run, only build-preview
should. Need to add checks for this.
Strangely though, pull request closes are running just fine on this repo itself:
https://github.com/greenelab/lab-website-template/actions/runs/4756829187/jobs/8452900055
I think I have a similar problem.
I get the following error on update-citations with the on-schedule action:
Create or update the pull request
Attempting creation of pull request
Error: GitHub Actions is not permitted to create or approve pull requests.
The only difference is that I now have one more paper published that should be updated on the list. It is already in my ORCID.
The full message:
Run peter-evans/create-pull-request@v4
(node:1865) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Save persisted git credentials
Determining the base and head repositories
Pull request branch target repository set to NVL-Lab/NVL-Lab.github.io
Configuring credential for HTTPS authentication
/usr/bin/git config --local http.https://github.com/.extraheader AUTHORIZATION: basic ***
Checking the base repository state
/usr/bin/git symbolic-ref HEAD --short
main
Working base is branch 'main'
/usr/bin/git remote prune origin
Pull request branch to create or update set to 'citation-update'
Configuring the committer and author
Configured git committer as 'GitHub <noreply@github.com>'
Configured git author as 'senis000 <senis000@users.noreply.github.com>'
Create or update the pull request branch
/usr/bin/git symbolic-ref HEAD --short
main
Working base is branch 'main'
/usr/bin/git checkout --progress -B 94294e8a-ff65-4619-8bfb-ade6c8d8d12f HEAD --
Switched to a new branch '94294e8a-ff65-4619-8bfb-ade6c8d8d12f'
M _cite/.cache/cache.db
M _data/citations.yaml
/usr/bin/git status --porcelain -unormal --
M _cite/.cache/cache.db
M _data/citations.yaml
Uncommitted changes found. Adding a commit.
/usr/bin/git add -A
/usr/bin/git -c author.name=senis000 -c author.email=senis000@users.noreply.github.com -c committer.name=GitHub -c committer.email=noreply@github.com commit -m [create-pull-request] automated change
[94294e8a-ff65-4619-8bfb-ade6c8d8d12f acb844a] [create-pull-request] automated change
Author: senis000 <senis000@users.noreply.github.com>
2 files changed, 16 insertions(+)
/usr/bin/git reset --hard
HEAD is now at acb844a [create-pull-request] automated change
/usr/bin/git clean -f -d
Resetting working base branch 'main'
/usr/bin/git checkout --progress main --
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
/usr/bin/git reset --hard origin/main
HEAD is now at cc7ecbd Update sources.yaml
/usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --unshallow --force origin citation-update:refs/remotes/origin/citation-update
fatal: couldn't find remote ref citation-update
Pull request branch 'citation-update' does not exist yet.
/usr/bin/git checkout --progress -B citation-update 94294e8a-ff65-4619-8bfb-ade6c8d8d12f --
Switched to a new branch 'citation-update'
/usr/bin/git rev-list --right-only --count main...citation-update
1
Created branch 'citation-update'
/usr/bin/git rev-parse HEAD
acb844aa34ba83be8d5ebf56b9[22](https://github.com/NVL-Lab/NVL-Lab.github.io/actions/runs/5238681725/jobs/9457809209#step:9:23)abdea0d15ca4
/usr/bin/git branch --delete --force 94294e8a-ff65-4619-8bfb-ade6c8d8d12f
Deleted branch 94294e8a-ff65-4619-8bfb-ade6c8d8d12f (was acb844a).
Pushing pull request branch to 'origin/citation-update'
/usr/bin/git push --force-with-lease origin HEAD:refs/heads/citation-update
remote:
remote: Create a pull request for 'citation-update' on GitHub by visiting:
remote: https://github.com/NVL-Lab/NVL-Lab.github.io/pull/new/citation-update
remote:
To https://github.com/NVL-Lab/NVL-Lab.github.io
* [new branch] HEAD -> citation-update
Create or update the pull request
Attempting creation of pull request
Error: GitHub Actions is not permitted to create or approve pull requests.
Restore persisted git credentials
/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
So the events went like this.
- Got a new paper published.
- Tried to manually run update-citations because after some days it wasn't showing the new paper. It failed.
- I made a commit with some small changes in a figure. It failed (see error below)
- I waited, thinking that maybe it needed time for some update in the orcid or the databases. Just wishful thinking.
- The page went on an on-schedule action and failed (error above)
- I'm sending this message. Not sure if the error is related or not.
Sorry forgot to add that I tried to make a small change to the repo and see how it worked on "push to main".
This is the error I got then:
Error: Invalid status code: 1
And this is the whole error message:
Run stefanzweifel/git-auto-commit-action@v4
Started: bash /home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/entrypoint.sh
INPUT_REPOSITORY value: .
INPUT_STATUS_OPTIONS:
INPUT_FILE_PATTERN: .
INPUT_BRANCH value:
From https://github.com/NVL-Lab/NVL-Lab.github.io
* [new branch] gh-pages -> origin/gh-pages
M _cite/.cache/cache.db
M _data/citations.yaml
Your branch is up to date with 'origin/main'.
INPUT_ADD_OPTIONS:
INPUT_FILE_PATTERN: .
INPUT_COMMIT_OPTIONS:
INPUT_COMMIT_USER_NAME: github-actions[bot]
INPUT_COMMIT_USER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
INPUT_COMMIT_MESSAGE: Update citations
INPUT_COMMIT_AUTHOR: senis000 <senis000@users.noreply.github.com>
[main 6943bde] Update citations
Author: senis000 <senis000@users.noreply.github.com>
2 files changed, 16 insertions(+)
INPUT_TAGGING_MESSAGE:
No tagging message supplied. No tag will be added.
INPUT_PUSH_OPTIONS:
remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: error: Changes must be made through a pull request.
To https://github.com/NVL-Lab/NVL-Lab.github.io
! [remote rejected] main -> main (protected branch hook declined)
error: failed to push some refs to 'https://github.com/NVL-Lab/NVL-Lab.github.io'
Error: Invalid status code: 1
at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
at ChildProcess.emit (node:events:5[27](https://github.com/NVL-Lab/NVL-Lab.github.io/actions/runs/5210746002/jobs/9429127367#step:8:28):[28](https://github.com/NVL-Lab/NVL-Lab.github.io/actions/runs/5210746002/jobs/9429127367#step:8:29))
at maybeClose (node:internal/child_process:1092:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:[30](https://github.com/NVL-Lab/NVL-Lab.github.io/actions/runs/5210746002/jobs/9429127367#step:8:31)2:5) {
code: 1
}
Error: Invalid status code: 1
at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
at ChildProcess.emit (node:events:[52](https://github.com/NVL-Lab/NVL-Lab.github.io/actions/runs/5210746002/jobs/9429127367#step:8:53)7:28)
at maybeClose (node:internal/child_process:1092:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
https://github.com/NVL-Lab/NVL-Lab.github.io/actions
INPUT_PUSH_OPTIONS:
remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: error: Changes must be made through a pull request.
For this error, I believe you have a branch protection rule set, such that you can't push directly to main and need to make a PR. This is good, but conflicts with the ability to run automatic citations directly on main. We ran into this in this issue on greenelab.com too. Currently, GitHub doesn't provide a way to make an exception to a branch protection rule for a GitHub Actions run, so you either need to remove the protection rule, or only do pull requests.
Error: GitHub Actions is not permitted to create or approve pull requests.
Have you enabled PRs in the GitHub Actions settings of your repo?
That solved it!
Sorry, I completely forgot I turned the rules on after editing the website.
Thanks for your help, and sorry again for piggybacking on the thread!
This issue, as originally described, doesn't seem to be happening anymore.
This recent failure on PR close is actually due to a citation error in the update-citations
workflow (this was me closing someone else's PR they accidentally opened against the template itself, that's why the citations were bad). This recent success shows there's no problem.
But that raises the point that that workflow shouldn't really be running on PR close, it's a waste of time (even if only 30s).
Reminder to look into skip calling update citations if the PR type is "closed".
Nevermind, it still is happening in the greenelab.com instance of the template. Definitely want to skip every step/job/workflow possible on PR close (I think the only one that needs to stay is whatever is running the pr-prevew action, so it can remove the pr-preview files from the gh-pages branch).
Another bad thing about this is that, while it shouldn't really affect anything on your site (I'm pretty sure), it does make debugging harder because it overwrites the last ✅ with an ❌ in the github ui:
This originally passed, but when the pr got merged and the workflow ran again on close, it failed and updated that to a failure. The successful run is still there in the logs, it's just that that commit status icon doesn't take you to the right one. It also makes it looks like all of your prs have failed, when they may not have, which makes it harder to spot real errors.
As such, removing the enhancement label. This will be important to fix quickly.
Also, because the closing is failing, the pr-preview action isn't able to clean up closed prs:
https://github.com/greenelab/greenelab.com/tree/gh-pages/preview