Skip to content

Commit ab3ebf4

Browse files
committed
build: compare with the previous release when contains release tag
1 parent d50def6 commit ab3ebf4

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,39 @@ jobs:
77
changes:
88
name: Detect Changes
99
runs-on: ubuntu-latest
10-
permissions:
11-
pull-requests: read
1210
outputs:
1311
variants: ${{ steps.filter.outputs.changes }}
1412
steps:
1513
- name: Checkout code
1614
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: ${{ startsWith(github.ref, 'refs/tags/v') && 0 || 1 }}
17+
18+
- name: Retrieve the previous release version
19+
if: startsWith(github.ref, 'refs/tags/v')
20+
id: previous_release
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
# Attempt to get the tag of the second-to-last release
25+
PREVIOUS_TAG=$(gh release list --limit 2 --json tagName | jq -r '. | select(length > 1) | .[1].tagName')
26+
27+
if [[ -z "$PREVIOUS_TAG" ]]; then
28+
echo "No previous release found. Falling back to the first commit."
29+
REF=$(git rev-list --max-parents=0 HEAD)
30+
else
31+
echo "Found previous release: $PREVIOUS_TAG"
32+
REF=$PREVIOUS_TAG
33+
fi
34+
35+
echo "The reference point is: $REF"
36+
echo "ref=$REF" >> $GITHUB_OUTPUT
37+
1738
- uses: dorny/paths-filter@v3
1839
id: filter
1940
with:
2041
filters: .github/filters.yml
42+
base: ${{ startsWith(github.ref, 'refs/tags/v') && steps.previous_release.outputs.ref || '' }}
2143

2244
build:
2345
needs: changes

0 commit comments

Comments
 (0)