Skip to content

Commit 0a85cb6

Browse files
authored
Add workflow to automate release creation
This workflow automates the release creation process, handling versioning based on changes to the CHANGELOG.md or Icon.png files.
1 parent 8bceedc commit 0a85cb6

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
##############################
2+
# Workflow: Create Release
3+
# Version: 0.0.7
4+
##############################
5+
name: Create Release
6+
7+
on:
8+
workflow_call:
9+
inputs:
10+
version:
11+
description: 'Optional version override (e.g., v1.0.0)'
12+
required: false
13+
type: string
14+
15+
permissions:
16+
contents: write
17+
18+
jobs:
19+
create-release:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Detect changed files
29+
id: changes
30+
run: |
31+
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
32+
33+
echo "$CHANGED_FILES"
34+
35+
if echo "$CHANGED_FILES" | grep -q "CHANGELOG.md"; then
36+
echo "changelog=true" >> $GITHUB_OUTPUT
37+
else
38+
echo "changelog=false" >> $GITHUB_OUTPUT
39+
fi
40+
41+
if echo "$CHANGED_FILES" | grep -q "Icon.png"; then
42+
echo "icon=true" >> $GITHUB_OUTPUT
43+
else
44+
echo "icon=false" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Stop if no relevant changes
48+
if: steps.changes.outputs.changelog != 'true' && steps.changes.outputs.icon != 'true'
49+
run: |
50+
echo "No CHANGELOG.md or Icon.png changes detected. Skipping release."
51+
exit 0
52+
53+
- name: Determine Version (from input or changelog)
54+
if: steps.changes.outputs.changelog == 'true'
55+
run: |
56+
if [ -n "${{ inputs.version }}" ]; then
57+
VERSION="${{ inputs.version }}"
58+
else
59+
VERSION=$(grep -oP '^## \[\K[^]]+' CHANGELOG.md | head -n 1)
60+
fi
61+
62+
[[ "$VERSION" != v* ]] && VERSION="v$VERSION"
63+
64+
echo "VERSION=$VERSION" >> $GITHUB_ENV
65+
echo "VERSION_NO_V=${VERSION#v}" >> $GITHUB_ENV
66+
67+
- name: Determine Version (icon patch bump)
68+
if: steps.changes.outputs.changelog != 'true' && steps.changes.outputs.icon == 'true'
69+
run: |
70+
LATEST=$(gh release list --limit 1 --json tagName -q '.[0].tagName')
71+
72+
if [ -z "$LATEST" ]; then
73+
VERSION="v0.0.1"
74+
else
75+
VERSION_NO_V=${LATEST#v}
76+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION_NO_V"
77+
PATCH=$((PATCH + 1))
78+
VERSION="v$MAJOR.$MINOR.$PATCH"
79+
fi
80+
81+
echo "VERSION=$VERSION" >> $GITHUB_ENV
82+
echo "VERSION_NO_V=${VERSION#v}" >> $GITHUB_ENV
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
86+
- name: Extract Release Notes from CHANGELOG.md
87+
if: steps.changes.outputs.changelog == 'true'
88+
run: |
89+
awk '/## \['"${VERSION_NO_V}"'\]/{flag=1; next} /## \[/{flag=0} flag' CHANGELOG.md > release_notes.txt
90+
91+
if [ ! -s release_notes.txt ]; then
92+
echo "No release notes found for version ${VERSION_NO_V}."
93+
exit 1
94+
fi
95+
96+
- name: Generate Release Notes for Icon change
97+
if: steps.changes.outputs.changelog != 'true' && steps.changes.outputs.icon == 'true'
98+
run: |
99+
echo "Patch release: updated Icon.png" > release_notes.txt
100+
101+
- name: Check if release exists
102+
id: check_release
103+
run: |
104+
if gh release view "$VERSION" >/dev/null 2>&1; then
105+
echo "exists=true" >> $GITHUB_OUTPUT
106+
else
107+
echo "exists=false" >> $GITHUB_OUTPUT
108+
fi
109+
env:
110+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
112+
- name: Create GitHub Release
113+
if: steps.check_release.outputs.exists == 'false'
114+
run: |
115+
gh release create "$VERSION" \
116+
--title "$VERSION" \
117+
--notes-file release_notes.txt
118+
env:
119+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)