ci: commitlint: when range is invalid (eg force push), check last 20

This is imperfect but better than nothing, and should avoid spurious
failures on force pushes to PRs.
This commit is contained in:
Simon Michael 2021-07-13 11:36:26 -10:00
parent 4d04da94fb
commit 82b74ec41e
4 changed files with 44 additions and 16 deletions

View File

@ -100,14 +100,21 @@ jobs:
# git log "$GITHUB_BASE_REF"..
# bin/commitlint "$GITHUB_BASE_REF"..
# keep synced in all workflows which do this
- name: Check commit messages
# For a PR, the range will be: master..origin/$GITHUB_HEAD_REF
# For a push it will be: $BEFORE..
# For a force push, BEFORE is the previous HEAD, and on github (though not locally) this is an "invalid revision range".
# In this and any case where the range is invalid, we'll just check the last N commits.
# related: https://stackoverflow.com/questions/64708371/how-to-run-github-workflow-on-every-commit-of-a-push
env:
BEFORE: ${{ github.event.before }}
# for a PR this will be: origin/master..origin/$GITHUB_HEAD_REF
# for a push it will be: $BEFORE..
# for a force push, BEFORE is the previous HEAD, and on github (not locally) this is an "invalid revision range"
NUM: 20
run: |
bin/commitlint ${BEFORE:-origin/master}..${GITHUB_HEAD_REF:+origin/$GITHUB_HEAD_REF}
RANGE=${BEFORE:-origin/master}..${GITHUB_HEAD_REF:+origin/$GITHUB_HEAD_REF}
git rev-list --quiet $RANGE \
&& bin/commitlint $RANGE \
|| ( echo "could not identify commits, checking last $NUM instead:"; bin/commitlint -$NUM )
# things to be cached/restored:

View File

@ -57,14 +57,21 @@ jobs:
with:
fetch-depth: 0
# keep synced in all workflows which do this
- name: Check commit messages
# For a PR, the range will be: master..origin/$GITHUB_HEAD_REF
# For a push it will be: $BEFORE..
# For a force push, BEFORE is the previous HEAD, and on github (though not locally) this is an "invalid revision range".
# In this and any case where the range is invalid, we'll just check the last N commits.
# related: https://stackoverflow.com/questions/64708371/how-to-run-github-workflow-on-every-commit-of-a-push
env:
BEFORE: ${{ github.event.before }}
# for a PR this will be: origin/master..origin/$GITHUB_HEAD_REF
# for a push it will be: $BEFORE..
# for a force push, BEFORE is the previous HEAD, and on github (not locally) this is an "invalid revision range"
NUM: 20
run: |
bin/commitlint ${BEFORE:-origin/master}..${GITHUB_HEAD_REF:+origin/$GITHUB_HEAD_REF}
RANGE=${BEFORE:-origin/master}..${GITHUB_HEAD_REF:+origin/$GITHUB_HEAD_REF}
git rev-list --quiet $RANGE \
&& bin/commitlint $RANGE \
|| ( echo "could not identify commits, checking last $NUM instead:"; bin/commitlint -$NUM )
# things to be cached/restored:

View File

@ -64,14 +64,21 @@ jobs:
# git log "$GITHUB_BASE_REF"..
# bin/commitlint "$GITHUB_BASE_REF"..
# keep synced in all workflows which do this
- name: Check commit messages
# For a PR, the range will be: master..origin/$GITHUB_HEAD_REF
# For a push it will be: $BEFORE..
# For a force push, BEFORE is the previous HEAD, and on github (though not locally) this is an "invalid revision range".
# In this and any case where the range is invalid, we'll just check the last N commits.
# related: https://stackoverflow.com/questions/64708371/how-to-run-github-workflow-on-every-commit-of-a-push
env:
BEFORE: ${{ github.event.before }}
# for a PR this will be: master..origin/$GITHUB_HEAD_REF
# for a push it will be: $BEFORE..
# for a force push, BEFORE is the previous HEAD, and on github (not locally) this is an "invalid revision range"
NUM: 20
run: |
bin/commitlint ${BEFORE:-origin/master}..${GITHUB_HEAD_REF:+origin/$GITHUB_HEAD_REF}
RANGE=${BEFORE:-origin/master}..${GITHUB_HEAD_REF:+origin/$GITHUB_HEAD_REF}
git rev-list --quiet $RANGE \
&& bin/commitlint $RANGE \
|| ( echo "could not identify commits, checking last $NUM instead:"; bin/commitlint -$NUM )
# things to be cached/restored:

View File

@ -47,14 +47,21 @@ jobs:
with:
fetch-depth: 0
# keep synced in all workflows which do this
- name: Check commit messages
# For a PR, the range will be: master..origin/$GITHUB_HEAD_REF
# For a push it will be: $BEFORE..
# For a force push, BEFORE is the previous HEAD, and on github (though not locally) this is an "invalid revision range".
# In this and any case where the range is invalid, we'll just check the last N commits.
# related: https://stackoverflow.com/questions/64708371/how-to-run-github-workflow-on-every-commit-of-a-push
env:
BEFORE: ${{ github.event.before }}
# for a PR this will be: origin/master..origin/$GITHUB_HEAD_REF
# for a push it will be: $BEFORE..
# for a force push, BEFORE is the previous HEAD, and on github (not locally) this is an "invalid revision range"
NUM: 20
run: |
bin/commitlint ${BEFORE:-origin/master}..${GITHUB_HEAD_REF:+origin/$GITHUB_HEAD_REF}
RANGE=${BEFORE:-origin/master}..${GITHUB_HEAD_REF:+origin/$GITHUB_HEAD_REF}
git rev-list --quiet $RANGE \
&& bin/commitlint $RANGE \
|| ( echo "could not identify commits, checking last $NUM instead:"; bin/commitlint -$NUM )
# things to be cached/restored: