I have a work flow which in one of its steps, if the commands finish with exit code 1 (failure), i want to run next command/job (fix the problem which caused previous command failure), but i don't want that exit code 1 affect on a workflow result status.
in this situation, if i have exit code 1, even if i fix the problem, the result status will be failure, but i want if the second command fixed the problem, the result status be succeed.
is it possible?
here is my workflow.yml:
if the job build with command run: black --check . have exit code 1, i want to run job reformat to fix the problem and push that in repository. the second job works fine, but final result label is failure!!
name: autoblack
on: [pull_request, push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.8
uses: actions/[email protected]
with:
python-version: 3.8
- name: Install Black
run: pip3 install git+git://github.com/psf/black
- name: Run black --check .
run: black --check .
reformat:
runs-on: ubuntu-latest
needs: [build]
if: always() && (needs.build.result == 'failure')
steps:
- uses: actions/[email protected]
- name: Set up Python 3.8
uses: actions/[email protected]
with:
python-version: 3.8
- name: Install Black
run: pip3 install git+git://github.com/psf/black
- name: If needed, commit black changes to the pull request
env:
NEEDS_CONTEXT: ${{ toJSON(needs) }}
run: |
black --fast .
git config --global user.name 'autoblack'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git checkout $GITHUB_HEAD_REF
echo "$NEEDS_CONTEXT"
git commit -am "fixup: Format Python code with Black"
git push
echo "$NEEDS_CONTEXT"
black --check || true? The|| truesuffix will ignore the command output error (always consider it as true) and allow to continue the workflow job or steps without returning failure. That way, you can eventually useblack --check &> output.txt || trueto create an output file and check in another step if this output file containsexit code 1or not (for example, withgrep -q) and save it as failure in a job output variable, to use in the second jobifcondition. - GuiFalourd