-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Ability to fallback to a different branch on failure #105
Comments
@znarf You can always set For the second item we do have a feature on the backlog (no current timeframe) to have the outcome of a step be part of the steps context. |
@chrispat Thank you for pointing on For the second item, I guess that should not be complicated to implement, I shared a proof of concept as Pull Request, let me know what you think. |
@znarf the second item is not something that really should be implemented in a single action, it would need to be implemented in the runner so it is consistently applied to all actions. We do have a feature on our backlog to add |
@chrispat all right, let me know if there is an open issue so I can have a look. |
@znarf unfortunately those issues are not in a public repo. |
@chrispat Would the work be in https://github.com/actions/toolkit ? If yes, which of the packages https://github.com/actions/toolkit/tree/master/packages would be affected? |
@znarf the work has to happen in the runner which is they only place where state is stored between executions of different actions. |
this should be a small change. i'll open an ADR soon. |
Thinking more about this, i believe you will get hit with a retry if you rely on failure. A better solution might be to check if the branch exists (query REST API), and set an output that you can use in the Something like this:
However when 404, it appears octokit/request-action creates error annotations so i'm not sure thats what you want but it's close. Might be a good starting point. |
also i noticed it doesnt appear to set any outputs when 404 (not even |
I worked around this by testing for the existence of the branch using ‘git ls-remote’ then checking out the right branch. See: |
@ericsciple thank you for the elegant solution, I'll try that. |
closing. fwiw proposal here for adding step outcome actions/runner#274 |
i"m having an issue with the steps check. If I have the following: jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Test failed
id: failed
run: exit 1
- name: Test not failed
id: notfailed
if: success() || failure()
run: exit 0
- name: Should run
id: bar
if: steps.notfailed.outcome == 'success'
run: exit 0 The But if I write the step as - name: Should run
id: bar
if: steps.notfailed.outcome == 'success' || success()
run: exit 0 It works. It's like the step check is not enough? (Given that |
Any |
Maybe the documentation can be improved? I didn't understand what you mentioned from reading it, but reading your message it's super clear.
Maybe replace
With your message here
|
After reading all of this and the other issue I'm still not sure what would be the "best ™️ " way to achieve this 😅 Maybe someone can chime in with a most optimized example? My use case is to be able to do this private repos btw; I came up with this and it seems to work. The individual steps are "easy":
but it's quite a lot of boilerplate: - name: Extract branch name
run: echo "::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/})"
id: extract-branch
- name: Try to retrieve branch from otherrepo
uses: octokit/request-action@v2.x
id: get_branch_otherrepo
with:
route: GET /repos/user/otherrepo/branches/${{ steps.extract-branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_WITH_ACCESS_TO_OTHER_REPO }}
continue-on-error: true
- name: Determine which otherrepo branch to checkout
run: |
if [[ '${{ steps.get_branch_otherrepo.outputs.status }}' = '200' ]]; then
OTHERREPO_BRANCH="${{ steps.extract-branch.outputs.branch }}"
else
OTHERREPO_BRANCH=master
fi
echo "Otherrepo branch for checkout: $OTHERREPO_BRANCH"
echo "OTHERREPO_BRANCH=$OTHERREPO_BRANCH" >> $GITHUB_ENV
- name: Checkout otherrepo
uses: actions/checkout@v2
with:
repository: user/otherrepo
token: ${{ secrets.TOKEN_WITH_ACCESS_TO_OTHER_REPO }}
path: tmp/otherreppo
ref: ${{ env.OTHERREPO_BRANCH }} Before I started out, I had a brute force approach in that I
The downside was that action/checkout retries on errors and if the branch can't be found, it retries twice and we lose ~30 seconds or so. The elaborate approach I came up with has "0 seconds latency" basically. Thanks for any pointers/input! |
This is a feature request. Because it's an advanced feature, I understand that it might not be directly implemented but some smaller features would unlock it.
Use case
At Open Collective, we have 2 main repositories, one for our API and one for our Frontend. In our CI, we have e2e tests which are requiring a checkout of both API and Frontend to run.
master
in both projectsmaster
Frontend because they don't require any modifications of the Frontendfeat/new-events-page
) and we want the e2e test to use checkouts of these branches.Status Quo
We're using some magic script that is implementing the functionality using downloaded tarballs (didn't write that!) .
https://github.com/opencollective/opencollective-api/blob/master/scripts/ci_checkout_frontend.sh
GitHub Actions to the rescue
We would like to use a nicely written GitHub Action for that. My initial implementation would be:
opencollective/opencollective-api#3031
https://github.com/opencollective/opencollective-api/pull/3031/checks?check_run_id=343540511
It's almost working but unfortunately the first command is sending a CI failure and we can't proceed normally after.
Feature Request
The text was updated successfully, but these errors were encountered: