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/setup-python@v2.2.2
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/checkout@v2.3.4
- name: Set up Python 3.8
uses: actions/setup-python@v2.2.2
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 'signorrayan@users.noreply.github.com'
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"