Skip to content

Release-Development #71

Release-Development

Release-Development #71

Workflow file for this run

name: Release-Development
on:
workflow_dispatch:
inputs:
compiler:
type: choice
description: What compiler to use?
required: true
default: YYC
options:
- YYC
- VM
schedule:
- cron: "0 0 * * *"
jobs:
build_needed:
name: Build needed?
runs-on: ubuntu-latest
env:
COMPILER: ${{ github.event.inputs.compiler || 'YYC' }}
outputs:
needed: ${{ steps.commit_check.outputs.needed }} # Output for skipping
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
lfs: true
- name: Check commit range
id: commit_check
run: |
# default to no build
echo "needed=false" >> $GITHUB_OUTPUT
# manual override
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "Manually triggered → build."
echo "needed=true" >> $GITHUB_OUTPUT
exit 0
fi
# determine commit range since last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
RANGE="$LAST_TAG..HEAD"
else
RANGE="HEAD"
fi
echo "Commit range: $RANGE"
# collect all commit messages in range
ALL_MSGS=$(git log $RANGE --pretty=%B)
echo "Messages in range:"
echo "$ALL_MSGS"
# only skip if every message matches exclude pattern
EXCLUDE="^(docs|chore|style|ci)"
if echo "$ALL_MSGS" | grep -vEq "$EXCLUDE"; then
echo "Found non-excluded commit → build needed."
echo "needed=true" >> $GITHUB_OUTPUT
else
echo "All commits are docs/chore/style/ci → skipping build."
fi
prepare_release:
name: Prepare the tags
runs-on: ubuntu-latest
needs: build_needed
if: needs.build_needed.outputs.needed == 'true'
outputs:
tag_name: ${{ steps.tag_info.outputs.tag_name }}
build_date: ${{ steps.tag_info.outputs.build_date }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set tag name
id: tag_info
run: |
BRANCH_SUFFIX="${GITHUB_REF_NAME##*/}"
DATE_TAG=$(date -u +"%Y-%m-%d-%H%M")
TAG_NAME="$BRANCH_SUFFIX/$DATE_TAG"
echo "Resolved DATE_TAG=$DATE_TAG"
echo "Resolved BRANCH_SUFFIX=$BRANCH_SUFFIX"
echo "Resolved TAG_NAME=$TAG_NAME"
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
echo "build_date=$DATE_TAG" >> $GITHUB_OUTPUT
- name: Cleanup old releases
run: |
# tag_name looks like: branch-name/date
TAG_NAME="${{ steps.tag_info.outputs.tag_name }}"
BRANCH_SUFFIX="${TAG_NAME%%/*}"
PREFIX="${BRANCH_SUFFIX}/"
echo "Checking releases with prefix: $PREFIX"
# Get tags starting with the prefix, sort reverse chronologically (best effort with default sort)
# Using gh release list is more reliable than just git tags if releases exist
TAGS=$(gh release list --limit 100 | awk '{print $1}' | grep "^${PREFIX}" | sort -r)
COUNT=0
RELEASES_TO_KEEP=10 # How many releases per branch prefix to keep
for TAG in $TAGS; do
COUNT=$((COUNT + 1))
if [ $COUNT -gt $RELEASES_TO_KEEP ]; then
echo "Deleting old release+tag: $TAG"
gh release delete "$TAG" -y --cleanup-tag || echo "Failed to delete release $TAG, maybe already deleted?"
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needs permissions to delete releases/tags
gamemaker_build:
name: Build
uses: ./.github/workflows/gamemaker_build.yml
secrets: inherit
needs: [prepare_release, build_needed]
if: needs.build_needed.outputs.needed == 'true'
with:
yyc: ${{ (github.event.inputs.compiler || 'YYC') == 'YYC' }}
build_date: ${{ needs.prepare_release.outputs.build_date }}
release:
name: Release
runs-on: ubuntu-latest
needs: [prepare_release, gamemaker_build]
if: needs.build_needed.outputs.needed == 'true'
permissions:
contents: write # Needed for softprops/action-gh-release
steps:
- name: Download built file artifact
uses: actions/download-artifact@v4
with:
name: built-file
path: ./build_output
- name: List downloaded files # Debug step
run: ls -R ./build_output
- name: Prepare Release Name
id: prep_release_name
run: |
rawTagName="${{ needs.prepare_release.outputs.tag_name }}"
# Use Bash parameter expansion: ${parameter//pattern/string}
# Replaces all occurrences of '/' with '-'
formattedTagName="${rawTagName//\//-}"
releaseName="ChapterMaster $formattedTagName"
echo "Calculated release name: $releaseName"
# Set the output using standard Bash redirection to the GITHUB_OUTPUT file
echo "release_name=$releaseName" >> $GITHUB_OUTPUT
- id: create_release
name: Create a release and upload the build
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.prep_release_name.outputs.release_name }}
tag_name: ${{ needs.prepare_release.outputs.tag_name }}
prerelease: true
generate_release_notes: true
make_latest: false
files: |
./build_output/${{ needs.gamemaker_build.outputs.built_file }}/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}