Skip to content

Commit ada5447

Browse files
committed
Add GitHub Actions workflow for automatic releases
Create rpgxp-release.yml that triggers on .rb file changes and creates versioned releases with the tag format v{x}.{y}.{z}-rpgxp-scripts. New script folders bump the minor version, modified scripts bump the patch version. First release includes all scripts, subsequent releases only include changed and new files.
1 parent 4563052 commit ada5447

File tree

1 file changed

+195
-0
lines changed

1 file changed

+195
-0
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
name: RPG Maker XP Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- '**/*.rb'
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
create-release:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout Repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Build Release
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
run: |
26+
set -euo pipefail
27+
28+
IGNORED_PATHS="README.md|LICENSE|img/|\.github/|\.gitattributes|\.gitignore"
29+
30+
# ── Letzten Release-Tag ermitteln
31+
LATEST_TAG=$(git tag -l 'v*-rpgxp-scripts' --sort=-v:refname | head -n1 || true)
32+
33+
if [ -z "$LATEST_TAG" ]; then
34+
IS_FIRST_RELEASE=true
35+
NEW_VERSION="v1.0.0"
36+
DIFF=$(find . -name "*.rb" -not -path "./.git/*" | sed 's|^\./||' | sed 's/^/A\t/')
37+
else
38+
IS_FIRST_RELEASE=false
39+
LAST_SHA=$(git rev-list -n1 "$LATEST_TAG" 2>/dev/null || true)
40+
41+
if [ -z "$LAST_SHA" ] || ! git cat-file -e "$LAST_SHA" 2>/dev/null; then
42+
IS_FIRST_RELEASE=true
43+
NEW_VERSION="v1.0.0"
44+
DIFF=$(find . -name "*.rb" -not -path "./.git/*" | sed 's|^\./||' | sed 's/^/A\t/')
45+
else
46+
DIFF=$(git diff --name-status "$LAST_SHA" HEAD -- '*.rb' | grep -vP "\t($IGNORED_PATHS)" || echo "")
47+
fi
48+
49+
if [ "$IS_FIRST_RELEASE" = false ]; then
50+
# Version aus dem letzten Tag parsen
51+
CURRENT=$(echo "$LATEST_TAG" | sed 's/^v//' | sed 's/-rpgxp-scripts$//')
52+
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
53+
MINOR=$(echo "$CURRENT" | cut -d. -f2)
54+
PATCH=$(echo "$CURRENT" | cut -d. -f3)
55+
56+
# Prüfen ob neue Ordner hinzugefügt wurden
57+
HAS_NEW_FOLDER=false
58+
if [ -n "$DIFF" ]; then
59+
while IFS=$'\t' read -r status filepath; do
60+
if [[ "$status" == A* ]]; then
61+
folder=$(echo "$filepath" | cut -d'/' -f1)
62+
if ! git ls-tree --name-only "$LAST_SHA" | grep -qF "$folder"; then
63+
HAS_NEW_FOLDER=true
64+
break
65+
fi
66+
fi
67+
done <<< "$DIFF"
68+
fi
69+
70+
if [ "$HAS_NEW_FOLDER" = true ]; then
71+
MINOR=$((MINOR + 1))
72+
PATCH=0
73+
else
74+
PATCH=$((PATCH + 1))
75+
fi
76+
77+
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
78+
fi
79+
fi
80+
81+
TAG_NAME="${NEW_VERSION}-rpgxp-scripts"
82+
83+
if [ -z "$DIFF" ]; then
84+
echo "Keine Script-Änderungen erkannt. Release wird übersprungen."
85+
exit 0
86+
fi
87+
88+
total_files=$(echo "$DIFF" | grep -c . || echo "0")
89+
90+
# ── Kategorien vorbereiten
91+
scripts_added=()
92+
scripts_removed=()
93+
scripts_modified=()
94+
95+
while IFS=$'\t' read -r status filepath; do
96+
[ -z "$status" ] && continue
97+
folder=$(echo "$filepath" | cut -d'/' -f1)
98+
name=$(basename "$filepath")
99+
display="${name%.rb} ($folder)"
100+
101+
case "$status" in
102+
A*) scripts_added+=("$display") ;;
103+
D*) scripts_removed+=("$display") ;;
104+
*) scripts_modified+=("$display") ;;
105+
esac
106+
done <<< "$DIFF"
107+
108+
count_added=${#scripts_added[@]}
109+
count_removed=${#scripts_removed[@]}
110+
count_modified=${#scripts_modified[@]}
111+
112+
# ── Release Notes zusammenbauen
113+
BODY=""
114+
RELEASE_DATE=$(date -u +"%d-%m-%Y")
115+
RELEASE_TIME=$(date -u +"%I:%M %p UTC")
116+
BODY+="**Released: $RELEASE_DATE at $RELEASE_TIME**"$'\n\n'
117+
118+
if [ "$IS_FIRST_RELEASE" = true ]; then
119+
BODY+="Initial release containing $total_files RPG Maker XP scripts across all script collections."$'\n\n'
120+
121+
BODY+="**Included Scripts ($total_files)**"$'\n\n'
122+
for s in "${scripts_added[@]}"; do
123+
BODY+="• ⠀**${s}** added"$'\n'
124+
done
125+
BODY+=$'\n'
126+
else
127+
parts=()
128+
[ $count_added -gt 0 ] && parts+=("$count_added added")
129+
[ $count_modified -gt 0 ] && parts+=("$count_modified modified")
130+
[ $count_removed -gt 0 ] && parts+=("$count_removed removed")
131+
summary=$(IFS=", "; echo "${parts[*]}")
132+
BODY+="Update with $summary script(s)."$'\n\n'
133+
134+
if [ $count_added -gt 0 ]; then
135+
BODY+="**Added ($count_added)**"$'\n\n'
136+
for s in "${scripts_added[@]}"; do
137+
BODY+="• ⠀**${s}** added"$'\n'
138+
done
139+
BODY+=$'\n'
140+
fi
141+
142+
if [ $count_modified -gt 0 ]; then
143+
BODY+="**Modified ($count_modified)**"$'\n\n'
144+
for s in "${scripts_modified[@]}"; do
145+
BODY+="• ⠀**${s}** updated"$'\n'
146+
done
147+
BODY+=$'\n'
148+
fi
149+
150+
if [ $count_removed -gt 0 ]; then
151+
BODY+="**Removed ($count_removed)**"$'\n\n'
152+
for s in "${scripts_removed[@]}"; do
153+
BODY+="• ⠀~~${s}~~ removed"$'\n'
154+
done
155+
BODY+=$'\n'
156+
fi
157+
fi
158+
159+
# ── ZIP-Asset erstellen
160+
echo "Creating release archive..."
161+
162+
if [ "$IS_FIRST_RELEASE" = true ]; then
163+
find . -name "*.rb" -not -path "./.git/*" | zip -@ -q /tmp/rpgxp-scripts.zip
164+
else
165+
FILE_LIST=""
166+
while IFS=$'\t' read -r status filepath; do
167+
[ -z "$status" ] && continue
168+
[[ "$status" == D* ]] && continue
169+
[ -f "$filepath" ] && FILE_LIST+="$filepath"$'\n'
170+
done <<< "$DIFF"
171+
172+
if [ -z "$FILE_LIST" ]; then
173+
echo "No files to include in the release asset."
174+
exit 0
175+
fi
176+
177+
echo -n "$FILE_LIST" | zip -@ -q /tmp/rpgxp-scripts.zip
178+
fi
179+
180+
DATA_SIZE=$(du -h /tmp/rpgxp-scripts.zip | cut -f1)
181+
echo " Archive size: $DATA_SIZE"
182+
183+
# ── Release erstellen
184+
echo "$BODY" > /tmp/release_notes.md
185+
echo "Release Notes:"
186+
cat /tmp/release_notes.md
187+
188+
echo "Creating release: $TAG_NAME"
189+
gh release create "$TAG_NAME" \
190+
/tmp/rpgxp-scripts.zip \
191+
--title "RPG Maker XP Script Library $NEW_VERSION" \
192+
--notes-file /tmp/release_notes.md \
193+
--latest
194+
195+
echo "Release '$TAG_NAME' successfully created!"

0 commit comments

Comments
 (0)