Files
CI/.github/workflows/build-windows.yml
T
collecting 2c0e0a3262 Nuke MSVC
2026-05-11 03:49:32 -04:00

228 lines
8.1 KiB
YAML
Executable File

name: Build Citron (Windows)
concurrency:
group: build-windows-nightly-${{ github.ref }}
cancel-in-progress: true
on:
workflow_dispatch: {}
jobs:
check-version:
name: Check if new version available
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.compare.outputs.should_build }}
new_hash: ${{ steps.upstream.outputs.hash_short }}
new_hash_full: ${{ steps.upstream.outputs.hash_full }}
steps:
- name: Checkout this repo
uses: actions/checkout@v4
- name: Get upstream commit hash
id: upstream
run: |
REPO_URL="https://github.com/citron-neo/emulator.git"
FULL_HASH=$(git ls-remote "$REPO_URL" HEAD | cut -f1)
SHORT_HASH=$(echo "$FULL_HASH" | cut -c1-7)
echo "hash_short=$SHORT_HASH" >> $GITHUB_OUTPUT
echo "hash_full=$FULL_HASH" >> $GITHUB_OUTPUT
- name: Get last built version
id: last_built
run: |
LAST_HASH=$(cat LATEST_VERSION | tr -d '\n' || echo "none")
echo "last_hash=$LAST_HASH" >> $GITHUB_OUTPUT
- name: Check if release exists
id: release_check
run: |
if gh release view nightly-windows --repo "${{ github.repository }}" > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Compare versions
id: compare
run: |
if [ "${{ steps.upstream.outputs.hash_short }}" != "${{ steps.last_built.outputs.last_hash }}" ]; then
echo "should_build=true" >> $GITHUB_OUTPUT
elif [ "${{ steps.release_check.outputs.exists }}" != "true" ]; then
echo "should_build=true" >> $GITHUB_OUTPUT
else
echo "should_build=false" >> $GITHUB_OUTPUT
fi
build-clangtron:
name: "Citron Build (Windows Clangtron - x64)"
needs: [check-version]
if: needs.check-version.outputs.should_build == 'true'
runs-on: ubuntu-latest
timeout-minutes: 240
env:
CPM_SOURCE_CACHE: /home/runner/.cache/cpm
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Clone Citron Source (Clangtron)
run: |
ATTEMPT=0
MAX_ATTEMPTS=999
while true; do
ATTEMPT=$((ATTEMPT + 1))
echo "Attempt $ATTEMPT of $MAX_ATTEMPTS: Cloning Citron..."
rm -rf citron
if git clone "https://github.com/citron-neo/emulator.git" citron; then
echo "Clone successful on attempt $ATTEMPT."
break
fi
if [ $ATTEMPT -ge $MAX_ATTEMPTS ]; then
echo "Failed after $MAX_ATTEMPTS attempts."
exit 1
fi
echo "Clone failed. Retrying in 15 seconds..."
sleep 15
done
- name: Init required submodules
working-directory: ./citron
run: |
echo "CPM manages all dependencies — no submodules needed for Clangtron"
- name: Cache CPM and Toolchain (Clangtron)
uses: actions/cache@v4
with:
path: /home/runner/.cache/cpm
key: clangtron-cache-${{ runner.os }}-${{ hashFiles('citron/CMakeModules/dependencies.cmake', 'citron/build-clangtron-windows.sh') }}
restore-keys: |
clangtron-cache-${{ runner.os }}-
- name: Get Version (Clangtron)
id: version
working-directory: ./citron
run: |
git fetch --tags
VERSION=$(git rev-parse --short HEAD)
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
- name: Skip BOLT build (not needed for --pgo none)
run: |
echo '#!/bin/bash' | sudo tee /usr/local/bin/llvm-bolt-21
echo '#!/bin/bash' | sudo tee /usr/local/bin/merge-fdata-21
sudo chmod +x /usr/local/bin/llvm-bolt-21
sudo chmod +x /usr/local/bin/merge-fdata-21
- name: Setup Clangtron Build Environment
working-directory: ./citron
run: |
chmod +x build-clangtron-windows.sh
./build-clangtron-windows.sh setup
echo "${HOME}/.cache/cpm/llvm-mingw/bin" >> "$GITHUB_PATH"
- name: Build Citron (Clangtron LTO)
working-directory: ./citron
run: |
export CITRON_BUILD_TYPE=Release
./build-clangtron-windows.sh use --pgo none --lto full
- name: Package Windows Build (Clangtron)
run: |
mkdir -p dist
BIN_DIR="./citron/build/use-nopgo/bin"
if [ ! -d "$BIN_DIR" ]; then
echo "::error::Build output not found at $BIN_DIR"
exit 1
fi
cd "$BIN_DIR"
zip -r "${GITHUB_WORKSPACE}/dist/Citron-windows-nightly-${{ steps.version.outputs.VERSION }}-x64-clangtron.zip" .
- name: Upload Windows Build (Clangtron)
uses: actions/upload-artifact@v4
with:
name: Citron-Windows-Nightly-Clangtron-x64
path: "dist/*.zip"
release:
if: ${{ github.ref_name == 'main' }}
name: "Release"
needs: [check-version, build-clangtron]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download Windows artifacts
uses: actions/download-artifact@v4
with:
pattern: Citron-Windows-Nightly-*
merge-multiple: true
path: ./release-artifacts
- name: Get Version from Filename
shell: bash
run: |
FILENAME=$(basename "$(ls ./release-artifacts/Citron-windows-nightly-*-x64-clangtron.zip)")
VERSION=${FILENAME#Citron-windows-nightly-}
VERSION=${VERSION%-x64-clangtron.zip}
echo "APP_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Delete Previous Release
run: gh release delete "nightly-windows" --repo "${{ github.repository }}" --cleanup-tag -y || true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set Build Date
run: echo "BUILD_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Release Artifacts
uses: softprops/action-gh-release@v2
with:
name: "Continuous Build (Windows Nightly: ${{ env.APP_VERSION }})"
tag_name: "nightly-windows"
prerelease: false
files: |
release-artifacts/*-x64-clangtron.zip
body: |
**Citron Upstream Commit:** [`${{ needs.check-version.outputs.new_hash }}`](https://github.com/citron-neo/emulator/commit/${{ needs.check-version.outputs.new_hash_full }})
This build is based on the latest Citron emulator source code from the upstream repository.
**Build Details:**
- Platform: Windows (x64)
- Toolchain: Clangtron (Clang LTO cross-compiled from Linux)
- Build Type: Release
- Date: ${{ env.BUILD_DATE }}
- name: Update LATEST_VERSION
if: success()
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
echo "${{ env.APP_VERSION }}" > LATEST_VERSION
git add LATEST_VERSION
git commit -m "Update LATEST_VERSION to ${{ env.APP_VERSION }} [skip ci]" || exit 0
for i in {1..5}; do
git pull --rebase origin main && git push && break || sleep 2
done
- name: Post to Discord
if: success()
run: |
DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/tag/nightly-windows"
DATE=$(date +'%Y-%m-%d')
WEBHOOK_URL="${{ secrets.DISCORD_WEBHOOK }}"
if [ -z "$WEBHOOK_URL" ]; then
echo "DISCORD_WEBHOOK is not set; skipping Discord notification."
exit 0
fi
curl -H "Content-Type: application/json" \
-d "{\"content\":\"🪟 **New Windows Build Available!**\n\nšŸ“¦ **Version:** \`${{ env.APP_VERSION }}\`\nšŸ“… **Date:** ${DATE}\nšŸ”§ **Toolchain:** Clangtron (Clang LTO)\nšŸ”— **Download:** $DOWNLOAD_URL\"}" \
"$WEBHOOK_URL"