-
Notifications
You must be signed in to change notification settings - Fork 0
47 lines (38 loc) · 1.37 KB
/
release.yaml
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
name: Create Release with Changelog
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
- name: Extract changelog for the tag
id: changelog
run: |
# Get the current tag
CURRENT_TAG=${GITHUB_REF#refs/tags/}
# Extract changelog for the current tag using awk
CHANGELOG=$(grep -A 1000 "^## \[$CURRENT_TAG\]" CHANGELOG.md | sed -n '/^## \[v0.2.0\]/,/^<a name/{p}' | sed '$d')
# Handle no match (e.g., if the tag isn't in the changelog)
if [[ -z "$CHANGELOG" ]]; then
echo "Changelog for ${CURRENT_TAG} not found. Please ensure CHANGELOG.md is updated."
exit 1
fi
echo "CHANGELOG_CONTENT<<EOF" >> $GITHUB_ENV
echo "$CHANGELOG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: |
echo "${{ env.CHANGELOG_CONTENT }}" > temp_changelog.md
gh release create "$tag" \
--repo="$GITHUB_REPOSITORY" \
--title="Release ${tag#v}" \
--notes-file=temp_changelog.md