Skip to content

Commit b524c45

Browse files
authored
Merge pull request #81 from per1234/compare-tag
Use previous tag as base when "Compare Performance" workflow triggered by tag
2 parents 19a08e8 + 4b3fa62 commit b524c45

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

.github/workflows/compare-performance.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,42 @@ 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
41-
echo "::set-output name=ref::${{ github.event.inputs.comparison-ref }}"
46+
COMPARISON_REF="${{ github.event.inputs.comparison-ref }}"
4247
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
43-
echo "::set-output name=ref::${{ github.base_ref }}"
48+
COMPARISON_REF="${{ github.base_ref }}"
49+
elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
50+
COMPARISON_REF="$( \
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+
)"
4462
else
45-
echo "::set-output name=ref::${{ github.event.before }}"
63+
COMPARISON_REF="${{ github.event.before }}"
4664
fi
4765
66+
if [[ "$COMPARISON_REF" == "" ]]; then
67+
echo "::error::Unable to determine comparison ref"
68+
exit 1
69+
fi
70+
71+
echo "::set-output name=ref::$COMPARISON_REF"
72+
4873
run:
4974
name: Run at ${{ matrix.data.ref }} (${{ matrix.data.description }})
5075
needs: init

0 commit comments

Comments
 (0)