Skip to content

Commit 1af8ce2

Browse files
committed
Use previous tag as base when "Compare Performance" workflow triggered by tag
The engine has three trigger events, each with their own base ref: - push: parent commit - pull request: PR base ref - manual trigger: arbitrary ref selected by the user The `push` event is triggered by both commit pushes and tag pushes. It turns out the github context field that provides the parent commit ref is set to `0000000000000000000000000000000000000000` on a tag push, which caused the workflow to fail. Although it would be possible to get the parent commit ref via a git command, this isn't a useful comparison to get from a tag push. The more useful comparison will be against the previous tag.
1 parent 19a08e8 commit 1af8ce2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

.github/workflows/compare-performance.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,32 @@ jobs:
3434
base-ref: ${{ steps.base-ref.outputs.ref }}
3535

3636
steps:
37+
# Repo is required to get the previous tag ref that is the base of the comparison on tag push triggered run.
38+
- name: Checkout repository
39+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
40+
uses: actions/checkout@v2
41+
3742
- name: Determine comparison ref
3843
id: base-ref
3944
run: |
4045
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
4146
echo "::set-output name=ref::${{ github.event.inputs.comparison-ref }}"
4247
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
4348
echo "::set-output name=ref::${{ github.base_ref }}"
49+
elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
50+
PREV_TAG="$( \
51+
git ls-remote \
52+
--quiet \
53+
--tags \
54+
--refs \
55+
--sort=version:refname | \
56+
cut \
57+
--delimiter='/' \
58+
--fields=3 | \
59+
tail -2 | \
60+
head -1
61+
)"
62+
echo "::set-output name=ref::$PREV_TAG"
4463
else
4564
echo "::set-output name=ref::${{ github.event.before }}"
4665
fi

0 commit comments

Comments
 (0)