Skip to content

Commit c4a0e36

Browse files
authored
Create publish-release.yml
1 parent fbdaa66 commit c4a0e36

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

.github/workflows/publish-release.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Publish release with changelog
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+'
7+
- 'v[0-9]+.[0-9]+.[0-9]+'
8+
9+
jobs:
10+
create-release:
11+
name: Create GitHub release
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Determine previous tag
23+
id: previous_tag
24+
shell: bash
25+
run: |
26+
readarray -t tags < <(git tag --sort=-creatordate)
27+
current_tag=${GITHUB_REF_NAME}
28+
previous_tag=""
29+
30+
for tag in "${tags[@]}"; do
31+
if [[ $tag != "$current_tag" ]]; then
32+
previous_tag=$tag
33+
34+
break
35+
fi
36+
done
37+
38+
echo "previous_tag=$previous_tag" >> "$GITHUB_OUTPUT"
39+
echo "Previous tag: ${previous_tag:-<none>}"
40+
41+
- name: Generate changelog
42+
id: changelog
43+
shell: bash
44+
run: |
45+
previous_tag=${{ steps.previous_tag.outputs.previous_tag }}
46+
47+
if [[ -n $previous_tag ]]; then
48+
range="$previous_tag..HEAD"
49+
else
50+
range="HEAD"
51+
fi
52+
53+
echo "Changelog range: $range"
54+
55+
mapfile -t commits < <(
56+
git log --reverse "$range" --date=format:'%Y-%m-%d' \
57+
--pretty=format:'- %ad: [%h](https://github.com/${{ github.repository }}/commit/%H) %s'
58+
)
59+
60+
if [[ ${#commits[@]} == 0 ]]; then
61+
commits=("- No changes since last release")
62+
fi
63+
64+
{
65+
echo "changelog<<TXT"
66+
printf '%s\n' "${commits[@]}"
67+
echo "TXT"
68+
} >> "$GITHUB_OUTPUT"
69+
70+
- name: Create release archive
71+
id: archive
72+
shell: bash
73+
run: |
74+
project=$(basename "${{ github.repository }}")
75+
current_tag=${GITHUB_REF_NAME}
76+
archive_name="${project}-${current_tag}"
77+
78+
git archive --worktree-attributes --format=zip --output="${archive_name}.zip" "$current_tag"
79+
git archive --worktree-attributes --format=tar.gz --output="${archive_name}.tar.gz" "$current_tag"
80+
81+
sha256sum "${archive_name}.zip" > "${archive_name}.zip.sha256"
82+
sha256sum "${archive_name}.tar.gz" > "${archive_name}.tar.gz.sha256"
83+
84+
echo "archive_name=${archive_name}" >> "$GITHUB_OUTPUT"
85+
echo "Created archive: ${archive_name}.zip"
86+
echo "Created archive: ${archive_name}.tar.gz"
87+
echo "Created checksum file: ${archive_name}.zip.sha256"
88+
echo "Created checksum file: ${archive_name}.tar.gz.sha256"
89+
90+
- name: Create GitHub release
91+
id: create_github_release
92+
uses: softprops/action-gh-release@v2
93+
with:
94+
token: ${{ secrets.GITHUB_TOKEN }}
95+
tag_name: ${{ github.ref_name }}
96+
name: "${{ github.event.repository.name }} ${{ github.ref_name }}"
97+
body: |
98+
## Verification
99+
100+
To verify the integrity of the archives:
101+
102+
```bash
103+
sha256sum --check "${{ steps.archive.outputs.archive_name }}.zip.sha256"
104+
sha256sum --check "${{ steps.archive.outputs.archive_name }}.tar.gz.sha256"
105+
```
106+
107+
## Changelog
108+
109+
${{ steps.changelog.outputs.changelog }}
110+
files: |
111+
${{ steps.archive.outputs.archive_name }}.zip
112+
${{ steps.archive.outputs.archive_name }}.tar.gz
113+
${{ steps.archive.outputs.archive_name }}.zip.sha256
114+
${{ steps.archive.outputs.archive_name }}.tar.gz.sha256
115+
fail_on_unmatched_files: true
116+
draft: false
117+
prerelease: false

0 commit comments

Comments
 (0)