-
Notifications
You must be signed in to change notification settings - Fork 8
87 lines (79 loc) · 2.94 KB
/
Copy pathauto-release.yml
File metadata and controls
87 lines (79 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Auto Release
# Triggers when a version bump commit lands on main (from a merged release PR)
on:
push:
branches: [main]
paths:
- 'pyproject.toml'
permissions:
contents: write
actions: write
jobs:
check:
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check.outputs.should_release }}
version: ${{ steps.check.outputs.version }}
tag: ${{ steps.check.outputs.tag }}
is_prerelease: ${{ steps.check.outputs.is_prerelease }}
steps:
- name: Check if this is a version bump commit
id: check
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
run: |
if [[ "$COMMIT_MSG" =~ ^chore:\ bump\ version\ to\ ([0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?) ]]; then
VERSION="${BASH_REMATCH[1]}"
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
if [[ "$VERSION" =~ rc ]]; then
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
fi
echo "Detected release: $VERSION"
else
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "Not a version bump commit, skipping."
fi
create-release:
needs: check
if: needs.check.outputs.should_release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check tag doesn't already exist
run: |
if git ls-remote --tags origin | grep -q "refs/tags/${{ needs.check.outputs.tag }}$"; then
echo "Tag ${{ needs.check.outputs.tag }} already exists!"
exit 1
fi
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PRERELEASE_FLAG=""
NOTES_START_FLAG=""
if [[ "${{ needs.check.outputs.is_prerelease }}" == "true" ]]; then
PRERELEASE_FLAG="--prerelease"
else
# Span notes from the previous stable release so changes that
# landed in intermediate RCs are included in the stable changelog.
PREV_STABLE="$(gh release list --exclude-pre-releases --exclude-drafts --limit 1 --json tagName --jq '.[0].tagName')"
if [[ -n "$PREV_STABLE" ]]; then
NOTES_START_FLAG="--notes-start-tag $PREV_STABLE"
fi
fi
gh release create "${{ needs.check.outputs.tag }}" \
--target "${{ github.sha }}" \
--title "${{ needs.check.outputs.tag }}" \
--generate-notes \
$NOTES_START_FLAG \
$PRERELEASE_FLAG
- name: Trigger downstream workflows
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh workflow run release.yml -f tag=${{ needs.check.outputs.tag }}
gh workflow run publish.yml