Skip to content

Commit 4b3fa62

Browse files
committed
Add check for empty comparison ref
Under some unexpected circumstances, the information used to determine the ref for the base of the comparison might be missing, which would result in an empty definition for the ref. Since the `actions/checkout` action defaults to checking out the tip of the default branch, this would not be reported and would result in spurious results. Better will be to cause the relevant workflow step to fail with a helpful error message.
1 parent 1af8ce2 commit 4b3fa62

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

.github/workflows/compare-performance.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ jobs:
4343
id: base-ref
4444
run: |
4545
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
46-
echo "::set-output name=ref::${{ github.event.inputs.comparison-ref }}"
46+
COMPARISON_REF="${{ github.event.inputs.comparison-ref }}"
4747
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
48-
echo "::set-output name=ref::${{ github.base_ref }}"
48+
COMPARISON_REF="${{ github.base_ref }}"
4949
elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
50-
PREV_TAG="$( \
50+
COMPARISON_REF="$( \
5151
git ls-remote \
5252
--quiet \
5353
--tags \
@@ -59,11 +59,17 @@ jobs:
5959
tail -2 | \
6060
head -1
6161
)"
62-
echo "::set-output name=ref::$PREV_TAG"
6362
else
64-
echo "::set-output name=ref::${{ github.event.before }}"
63+
COMPARISON_REF="${{ github.event.before }}"
6564
fi
6665
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+
6773
run:
6874
name: Run at ${{ matrix.data.ref }} (${{ matrix.data.description }})
6975
needs: init

0 commit comments

Comments
 (0)