Skip to content

Rewrite release workflow: individual .rb assets, improved descriptions #2

Rewrite release workflow: individual .rb assets, improved descriptions

Rewrite release workflow: individual .rb assets, improved descriptions #2

Workflow file for this run

name: RPG Maker XP Release
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: write
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build Release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
IGNORED_PATHS="README.md|LICENSE|images/|\.github/|\.gitattributes|\.gitignore"
# ── Letzten Release-Tag ermitteln
LATEST_TAG=$(git tag -l 'v*-rpgxp-scripts' --sort=-v:refname | head -n1 || true)
if [ -z "$LATEST_TAG" ]; then
IS_FIRST_RELEASE=true
NEW_VERSION="v1.0.0"
DIFF=$(find . -name "*.rb" -not -path "./.git/*" | sed 's|^\./||' | sed 's/^/A\t/')
else
IS_FIRST_RELEASE=false
LAST_SHA=$(git rev-list -n1 "$LATEST_TAG" 2>/dev/null || true)
if [ -z "$LAST_SHA" ] || ! git cat-file -e "$LAST_SHA" 2>/dev/null; then
IS_FIRST_RELEASE=true
NEW_VERSION="v1.0.0"
DIFF=$(find . -name "*.rb" -not -path "./.git/*" | sed 's|^\./||' | sed 's/^/A\t/')
else
DIFF=$(git diff --name-status "$LAST_SHA" HEAD -- '*.rb' | grep -vP "\t($IGNORED_PATHS)" || echo "")
fi
if [ "$IS_FIRST_RELEASE" = false ]; then
CURRENT=$(echo "$LATEST_TAG" | sed 's/^v//' | sed 's/-rpgxp-scripts$//')
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
MINOR=$(echo "$CURRENT" | cut -d. -f2)
PATCH=$(echo "$CURRENT" | cut -d. -f3)
HAS_NEW_FOLDER=false
if [ -n "$DIFF" ]; then
while IFS=$'\t' read -r status filepath; do
if [[ "$status" == A* ]]; then
folder=$(echo "$filepath" | cut -d'/' -f1)
if ! git ls-tree --name-only "$LAST_SHA" | grep -qF "$folder"; then
HAS_NEW_FOLDER=true
break
fi
fi
done <<< "$DIFF"
fi
if [ "$HAS_NEW_FOLDER" = true ]; then
MINOR=$((MINOR + 1))
PATCH=0
else
PATCH=$((PATCH + 1))
fi
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
fi
fi
TAG_NAME="${NEW_VERSION}-rpgxp-scripts"
if [ -z "$DIFF" ]; then
echo "No script changes detected. Skipping release."
exit 0
fi
total_files=$(echo "$DIFF" | grep -c . || echo "0")
# ── Kategorien vorbereiten
scripts_added=()
scripts_removed=()
scripts_modified=()
while IFS=$'\t' read -r status filepath; do
[ -z "$status" ] && continue
folder=$(echo "$filepath" | cut -d'/' -f1)
readable=$(echo "$folder" | sed 's/^[0-9]*-//' | sed 's/-/ /g')
case "$status" in
A*) scripts_added+=("$readable") ;;
D*) scripts_removed+=("$readable") ;;
*) scripts_modified+=("$readable") ;;
esac
done <<< "$DIFF"
count_added=${#scripts_added[@]}
count_removed=${#scripts_removed[@]}
count_modified=${#scripts_modified[@]}
# ── Release Notes zusammenbauen
BODY=""
RELEASE_DATE=$(date -u +"%d-%m-%Y")
RELEASE_TIME=$(date -u +"%I:%M %p UTC")
BODY+="**Release: $RELEASE_DATE at $RELEASE_TIME**"$'\n\n'
if [ "$IS_FIRST_RELEASE" = true ]; then
BODY+="This release contains $total_files RPG Maker XP scripts designed to improve gameplay mechanics and visual presentation. Each script is a drop-in replacement that maintains full compatibility with the standard RPG Maker XP framework while adding new functionality."$'\n\n'
for s in "${scripts_added[@]}"; do
BODY+="• ⠀Added ${s}"$'\n'
done
else
parts=()
[ $count_added -gt 0 ] && parts+=("$count_added added")
[ $count_modified -gt 0 ] && parts+=("$count_modified updated")
[ $count_removed -gt 0 ] && parts+=("$count_removed removed")
summary=$(IFS=", "; echo "${parts[*]}")
BODY+="This release includes ${summary} script(s)."$'\n\n'
if [ $count_added -gt 0 ]; then
for s in "${scripts_added[@]}"; do
BODY+="• ⠀Added ${s}"$'\n'
done
fi
if [ $count_modified -gt 0 ]; then
for s in "${scripts_modified[@]}"; do
BODY+="• ⠀Enhanced ${s}"$'\n'
done
fi
if [ $count_removed -gt 0 ]; then
for s in "${scripts_removed[@]}"; do
BODY+="• ⠀Removed ~~${s}~~"$'\n'
done
fi
fi
BODY+=$'\n'"**Note:** If you encounter any bugs or issues, please don't hesitate to open an issue. For any questions or to start a discussion, feel free to initiate a discussion on the GitHub repository."
# ── Release-Assets sammeln (einzelne .rb Dateien)
ASSET_FILES=()
while IFS=$'\t' read -r status filepath; do
[ -z "$status" ] && continue
[[ "$status" == D* ]] && continue
[ -f "$filepath" ] && ASSET_FILES+=("$filepath")
done <<< "$DIFF"
if [ ${#ASSET_FILES[@]} -eq 0 ]; then
echo "No files to include in the release."
exit 0
fi
echo "Assets to upload (${#ASSET_FILES[@]}):"
printf " %s\n" "${ASSET_FILES[@]}"
# ── Release erstellen
echo "$BODY" > /tmp/release_notes.md
echo ""
echo "Release Notes:"
cat /tmp/release_notes.md
echo ""
echo "Creating release: $TAG_NAME"
gh release create "$TAG_NAME" \
"${ASSET_FILES[@]}" \
--title "RPG Maker XP Script Library $NEW_VERSION" \
--notes-file /tmp/release_notes.md \
--latest
echo "Release '$TAG_NAME' created successfully!"