name: Create GitHub Release on Version Change on: push: branches: master jobs: check-version: runs-on: ubuntu-latest outputs: new_version: ${{ steps.detect.outputs.new_version }} should_release: ${{ steps.detect.outputs.should_release }} previous_version: ${{ steps.detect.outputs.previous_version }} steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all history to check tags - name: Read current VERSION id: read_current run: | if [ ! -f VERSION ]; then echo "Error: VERSION file missing" exit 1 fi CURRENT=$(cat VERSION | tr -d '[:space:]') echo "current=$CURRENT" >> $GITHUB_OUTPUT echo "Current version in file: $CURRENT" - name: Find latest release tag id: latest_tag run: | # Get the most recent tag that looks like a version (vX.Y.Z) LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") if [ -z "$LATEST_TAG" ]; then echo "No previous tags found. This is the first release." echo "previous=" >> $GITHUB_OUTPUT echo "should_release=true" >> $GITHUB_OUTPUT echo "new_version=${{ steps.read_current.outputs.current }}" >> $GITHUB_OUTPUT else # Strip the 'v' prefix if present for comparison PREV_VERSION=${LATEST_TAG#v} echo "previous=$PREV_VERSION" >> $GITHUB_OUTPUT CURRENT=${{ steps.read_current.outputs.current }} if [ "$CURRENT" == "$PREV_VERSION" ]; then echo "Version unchanged ($CURRENT). Skipping release." echo "should_release=false" >> $GITHUB_OUTPUT echo "new_version=$CURRENT" >> $GITHUB_OUTPUT else echo "Version changed! $PREV_VERSION -> $CURRENT" echo "should_release=true" >> $GITHUB_OUTPUT echo "new_version=$CURRENT" >> $GITHUB_OUTPUT fi fi create-release: needs: check-version if: needs.check-version.outputs.should_release == 'true' runs-on: ubuntu-latest permissions: contents: write # Required to create releases and tags steps: - name: Checkout code uses: actions/checkout@v4 - name: Prepare Release Artifacts run: | # Create a directory for the release mkdir -p release-artifacts # Copy relevant files to the artifact folder # Adjust these paths based on what you want to release cp -r . release-artifacts/ # Remove hidden files and .git folder to keep it clean rm -rf release-artifacts/.git rm -rf release-artifacts/.github rm -rf release-artifacts/.gitignore # Create a tarball tar -czvf "SPT-Server-v${{ needs.check-version.outputs.new_version }}.tar.gz" -C release-artifacts . # Create a zip file zip -r "SPT-Server-v${{ needs.check-version.outputs.new_version }}.zip" release-artifacts/ - name: Create GitHub Release uses: softprops/action-gh-release@v1 with: tag_name: v${{ needs.check-version.outputs.new_version }} name: Release v${{ needs.check-version.outputs.new_version }} body: | ## 🚀 New Release: v${{ needs.check-version.outputs.new_version }} Automated release triggered by an update to the `VERSION` file. ### 📦 Download - [Download .tar.gz](#) (Link generated automatically) - [Download .zip](#) (Link generated automatically) ### 📝 Changes - Updated version to ${{ needs.check-version.outputs.new_version }} - (Add manual notes here if needed) files: | SPT-Server-v${{ needs.check-version.outputs.new_version }}.tar.gz SPT-Server-v${{ needs.check-version.outputs.new_version }}.zip generate_release_notes: true draft: false prerelease: false