HttpError: Branch not found
bzurkowski opened this issue · 5 comments
Describe the Issue
More frequently than before I observe the following error when executing the branch deploy action:
Error: HttpError: Branch <environment>-branch-deploy-lock not found
at /runner/_work/_actions/github/branch-deploy/v7.0.0/webpack:/branch-deploy-action/node_modules/@octokit/request/dist-node/index.js:86:1
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at createLock (/runner/_work/_actions/github/branch-deploy/v7.0.0/webpack:/branch-deploy-action/src/functions/lock.js:70:1)
at lock (/runner/_work/_actions/github/branch-deploy/v7.0.0/webpack:/branch-deploy-action/src/functions/lock.js:600:1)
at run (/runner/_work/_actions/github/branch-deploy/v7.0.0/webpack:/branch-deploy-action/src/main.js:444:1)
Error: Branch <environment>-branch-deploy-lock not found
The issue originates in here:
// Create the lock branch if it doesn't exist
await createBranch(octokit, context, branchName)
// Create the lock file
await createLock(
octokit,
context,
ref,
reason,
sticky,
environment,
global,
reactionId
)
It seems that the newly created lock branch is not always available when the createLock
method is called, which is responsible for updating the lock file in that branch.
Indeed, I checked and the lock file is not present on the branch when the action fails.
Action Configuration
- name: Gate branch deployment
id: branch-deploy
uses: github/branch-deploy@v7.0.0
with:
trigger: .deploy app
lock_trigger: .lock app
unlock_trigger: .unlock app
help_trigger: .help app
noop_trigger: .plan app
environment: dev
environment_targets: dev,prod
production_environment: prod
stable_branch: master
prefix_only: true
skip_completing: true
reaction: eyes
Relevant Actions Log Output
No response
Extra Information
No response
👋 Hey again @bzurkowski! Funny you should open this issue because I was just about to open an issue around this myself!
I have been seeing this issue creep up more as well. There have been a few availability issues in the past few days and I have a hunch that what is happening here is that the operation to create the branch is having a bit of lag. So even though our await createBranch()
call completes, something isn't quite settled enough to instantly make a call to place a file on that branch with await createLock()
. I think what needs to happen here is some retry/back-off logic.
So rather than just instantly trying to create a file, and crash the Action if it fails, we have some logic that makes X number of attempts and each time it sleeps for a little bit longer before it final fails. This should make this call to write the lock file on the branch a bit more resistant to failure.
Edit: Looks like octokit supports retries so we don't have to reinvent the wheel
If this happens again, can you check something for me @bzurkowski? I am curious if you go to check the branches
tab, if the lock branch exists a little bit after this failure occurs? I have a hunch that it will, but just want to make sure something else isn't failing that completely prevents the branch from being created.
I'm fairly confident that the branch is just taking longer to "appear" via the API and we are making another API call nearly instantly afterwards to create a file without and retry logic.
Thanks!
@GrantBirki I checked that already and the branch was present after the failure. The action failed on inserting the lock file via the createLock
method called straight after creating the branch. I confirmed that the branch was missing the file.
Excellent! I saw the same as well on my end. Working on a fix now 🚀
Custom plugins can be injected into the Action's version of Octokit like so -> https://github.com/actions/toolkit/blob/91d3933eb52b351f437151400a88ba7d57442a9b/packages/github/src/github.ts#L18