Skip to content

Version Release

Version Release #11

Workflow file for this run

name: Version Release
on:
schedule:
- cron: '0 4 * * *' # Runs at 04:00 UTC every day
workflow_dispatch: # Allows manual triggering
inputs:
skip_release:
description: 'Skip release attachment'
required: true
default: 'false'
type: choice
options:
- 'true'
- 'false'
jobs:
check-branch:
runs-on: ubuntu-latest
outputs:
is_master: ${{ steps.check.outputs.is_master }}
steps:
- name: Check branch
id: check
run: |
echo "is_master=${{ github.ref == 'refs/heads/master' }}" >> $GITHUB_OUTPUT
bump-semver:
runs-on: ubuntu-latest
needs: [check-branch]
if: needs.check-branch.outputs.is_master == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0 # Ensure full history for diff comparisons
- name: Run bump semver script
run: |
chmod +x ./.github/bump_version.sh
./.github/bump_version.sh
- name: Commit version bump
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add VERSION || true
git diff-index --quiet HEAD || git commit -m "Bump version to $(cat VERSION) [skip ci]" || true
git push origin HEAD:master --follow-tags || true
evaluate-release:
runs-on: ubuntu-latest
needs: [check-branch, bump-semver]
if: needs.check-branch.outputs.is_master == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0 # Get full history for tag comparison
- name: Read raw version
id: version
run: |
VERSION=$(cat VERSION)
echo "raw_version=${VERSION}" >> $GITHUB_OUTPUT
- name: Get previous tag
id: previous-tag
run: |
git fetch --tags
# Default to v0.0.0 if no tags exist
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "prev_tag=${PREV_TAG}" >> $GITHUB_OUTPUT
echo "prev_version=${PREV_TAG#v}" >> $GITHUB_OUTPUT
- name: Compare versions
id: version-check
run: |
NEW_VERSION=${{ steps.version.outputs.raw_version }}
PREV_VERSION=${{ steps.previous-tag.outputs.prev_version }}
if [ "$NEW_VERSION" = "$PREV_VERSION" ]; then
echo "build_needed=false" >> $GITHUB_OUTPUT
echo "No new version detected, skipping build"
else
echo "build_needed=true" >> $GITHUB_OUTPUT
echo "RELEASE_NEEDED=true" >> $GITHUB_ENV
echo "new_tag=v${NEW_VERSION}" >> $GITHUB_ENV
fi
- name: Create semver tag and release
if: env.RELEASE_NEEDED == 'true'
uses: actions/create-release@v1
with:
tag_name: ${{ env.new_tag }}
release_name: ${{ env.new_tag }}
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
runs-on: windows-latest
needs: [check-branch, bump-semver, evaluate-release]
if: |
always() &&
(needs.check-branch.result == 'success') &&
(needs.bump-semver.result == 'success' || needs.bump-semver.result == 'skipped') &&
(needs.evaluate-release.result == 'success' || needs.evaluate-release.result == 'skipped') &&
(needs.check-branch.outputs.is_master != 'true' || needs.evaluate-release.outputs.build_needed == 'true')
env:
SKIP_RELEASE: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.skip_release || 'false' }}
steps:
- name: Setup VS Dev Environment
uses: microsoft/[email protected]
- name: Install Visual C++ components
uses: ilammy/msvc-dev-cmd@v1
- name: Checkout Framework
uses: actions/checkout@v4
with:
ref: develop
repository: 'MafiaHub/Framework'
path: 'fwk'
- name: Checkout Current Repository (modified)
uses: actions/checkout@v4
if: needs.check-branch.outputs.is_master == 'true'
with:
ref: master
path: 'temp_repo'
- name: Checkout Current Repository
uses: actions/checkout@v4
if: needs.check-branch.outputs.is_master != 'true'
with:
path: 'temp_repo'
- name: Setup Project Structure
shell: cmd
run: |
cd fwk
mkdir code\projects
xcopy /E /I ..\temp_repo code\projects\mafiamp
- name: Configure CMake
shell: cmd
working-directory: fwk
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release -G "Ninja"
- name: Build Project
shell: cmd
working-directory: fwk
run: cmake --build build --config Release
- name: Prepare Release Package
shell: cmd
working-directory: fwk
run: |
xcopy /E /I code\projects\mafiamp\gamemode build\bin\gamemode
copy code\projects\mafiamp\LICENSE.txt build\bin\
copy code\projects\mafiamp\NOTICE.txt build\bin\
- name: Read Version
id: version
working-directory: temp_repo
shell: cmd
run: |
for /f "delims=" %%i in (VERSION) do set VERSION=%%i
echo VERSION=%VERSION%>> %GITHUB_OUTPUT%
- name: Create Archive
shell: cmd
working-directory: fwk
run: |
powershell Compress-Archive -Path build\bin\* -DestinationPath mafiamp_release_${{ steps.version.outputs.VERSION }}.zip
- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: mafiamp-release
path: fwk/mafiamp_release_${{ steps.version.outputs.VERSION }}.zip
- name: Attach to Release
if: ${{ env.SKIP_RELEASE == 'false' }}
uses: softprops/action-gh-release@v1
with:
files: fwk/mafiamp_release_${{ steps.version.outputs.VERSION }}.zip
tag_name: ${{ steps.version.outputs.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Send Discord Notification
if: ${{ success() && env.SKIP_RELEASE == 'false' }}
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
title: "New Release Published! 🎉"
description: |
**Version:** ${{ steps.version.outputs.VERSION }}
**Download:** https://github.com/${{ github.repository }}/releases/download/${{ steps.version.outputs.VERSION }}/mafiamp_release_${{ steps.version.outputs.VERSION }}.zip
color: 0x00ff00
username: MafiaMP Release Bot