LANCommander/.github/workflows/LANCommander.Nightly.yml

482 lines
No EOL
18 KiB
YAML

name: LANCommander Nightly
on:
workflow_dispatch:
schedule:
# Runs every day at 3AM CST
# CST is UTC-6, so midnight CST = 09:00 UTC
- cron: '0 9 * * *'
env:
REGISTRY: ghcr.io
IMAGE_NAME: lancommander/lancommander
permissions:
contents: write
packages: write
id-token: write
attestations: write
jobs:
# --------------------------------------------------------------------------
# 1) PREP JOB: figure out the latest semver, build nightly version,
# check if there are commits since the last nightly tag. If none,
# skip the rest of the workflow.
# --------------------------------------------------------------------------
prep:
runs-on: ubuntu-latest
outputs:
version_semver: ${{ steps.set_version.outputs.VERSION_SEMVER }}
version_tag: ${{ steps.set_version.outputs.VERSION_TAG }}
changed: ${{ steps.check_diff.outputs.changed }}
build_dotnet_version: 10.0.100
steps:
- name: Check out code
uses: actions/checkout@v4
with:
# Ensure we get all tags so we can find the latest
fetch-depth: 0
- name: Determine last semver and build nightly version
id: set_version
shell: bash
run: |
# Fetch all tags
git fetch --tags
# Grab the last semver-ish tag (e.g., "v1.2.3", "v1.2.3-debug", or "1.2.3-nightly")
LAST_SEMVER_TAG="$(git tag --list --sort=-v:refname | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+' | head -n1)"
if [ -z "$LAST_SEMVER_TAG" ]; then
echo "No semver tag found; defaulting to 0.0.0"
LAST_SEMVER_TAG="0.0.0"
fi
# Remove prefix 'v' and any suffix like "-debug", "-nightly", etc.
CLEAN_TAG="$(echo "${LAST_SEMVER_TAG#v}" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')"
# Build a nightly version string, e.g., "1.2.3-nightly.20250127"
DATE=$(date +'%Y%m%d')
FINAL_VERSION="${CLEAN_TAG}-nightly.${DATE}"
echo "Last semver tag: $LAST_SEMVER_TAG"
echo "Clean semver tag: $CLEAN_TAG"
echo "Nightly version: $FINAL_VERSION"
# Set output variables for GitHub Actions
echo "VERSION_SEMVER=$CLEAN_TAG" >> $GITHUB_ENV
echo "VERSION_TAG=$FINAL_VERSION" >> $GITHUB_ENV
echo "::set-output name=VERSION_SEMVER::$CLEAN_TAG"
echo "::set-output name=VERSION_TAG::$FINAL_VERSION"
- name: Check if commits since last nightly tag
id: check_diff
shell: bash
run: |
# Fetch the last nightly tag
LAST_NIGHTLY_TAG="$(git tag --list --sort=-v:refname | grep -E 'nightly\.20[0-9]+' | head -n1 || true)"
if [ -z "$LAST_NIGHTLY_TAG" ]; then
echo "No previous nightly tag found. Marking as changed."
echo "::set-output name=changed::true"
exit 0
fi
# Check for commits since that tag
set +e # Disable exit on error temporarily
COMMITS=$(git log "${LAST_NIGHTLY_TAG}"..HEAD --oneline 2>/dev/null || true)
set -e # Re-enable exit on error
if [ -z "$COMMITS" ]; then
echo "No commits since last nightly tag: $LAST_NIGHTLY_TAG"
echo "::set-output name=changed::false"
else
echo "Found commits since $LAST_NIGHTLY_TAG"
echo "::set-output name=changed::true"
fi
# --------------------------------------------------------------------------
# 2) BUILD JOBS (Server/Launcher) - only run if changes == 'true'
# Each calls your local workflow YAML with correct indentation
# --------------------------------------------------------------------------
build_server_linux_arm64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Server.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: linux-arm64
build_arch: arm64
build_platform: Linux
build_configuration: Debug
build_server_linux_x64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Server.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: linux-x64
build_arch: x64
build_platform: Linux
build_configuration: Debug
build_server_osx_arm64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Server.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: osx-arm64
build_arch: arm64
build_platform: macOS
build_configuration: Debug
build_server_osx_x64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Server.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: osx-x64
build_arch: x64
build_platform: macOS
build_configuration: Debug
build_server_win_arm64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Server.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: win-arm64
build_arch: arm64
build_platform: Windows
build_configuration: Debug
build_server_win_x64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Server.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: win-x64
build_arch: x64
build_platform: Windows
build_configuration: Debug
build_launcher_linux_arm64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Launcher.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: linux-arm64
build_arch: arm64
build_platform: Linux
build_configuration: Debug
build_launcher_linux_x64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Launcher.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: linux-x64
build_arch: x64
build_platform: Linux
build_configuration: Debug
build_launcher_osx_arm64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Launcher.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: osx-arm64
build_arch: arm64
build_platform: macOS
build_configuration: Debug
build_launcher_osx_x64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Launcher.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: osx-x64
build_arch: x64
build_platform: macOS
build_configuration: Debug
build_launcher_win_arm64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Launcher.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: win-arm64
build_arch: arm64
build_platform: Windows
build_configuration: Debug
build_launcher_win_x64:
needs: [prep]
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
uses: ./.github/workflows/LANCommander.Launcher.yml
with:
build_dotnet_version: ${{ needs.prep.outputs.build_dotnet_version }}
version_semver: ${{ needs.prep.outputs.version_semver }}
version_tag: ${{ needs.prep.outputs.version_tag }}
build_runtime: win-x64
build_arch: x64
build_platform: Windows
build_configuration: Debug
# --------------------------------------------------------------------------
# 3) FINALIZE: if changes == 'true', gather artifacts + push Docker:nightly
# --------------------------------------------------------------------------
publish_docker_image:
needs:
- prep
- build_server_linux_arm64
- build_server_linux_x64
- build_server_osx_arm64
- build_server_osx_x64
- build_server_win_arm64
- build_server_win_x64
if: needs.prep.outputs.changed == 'true' && github.repository_owner == 'LANCommander'
runs-on: ubuntu-latest
steps:
# 3c) Build and push Docker image with tag "nightly"
- name: Checkout Repo for Docker build
uses: actions/checkout@v4
- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=nightly
type=raw,value=${{ needs.prep.outputs.version_tag }}
- name: Download Server x64 Artifacts
uses: actions/download-artifact@v4
with:
name: LANCommander.Server-Linux-x64-v${{ needs.prep.outputs.version_tag }}.zip
path: ./
- name: Download Server arm64 Artifacts
uses: actions/download-artifact@v4
with:
name: LANCommander.Server-Linux-arm64-v${{ needs.prep.outputs.version_tag }}.zip
path: ./
- name: Extract Server Artifacts x64
run: |
mkdir -p ./LANCommander.Server/published-amd64
unzip ./LANCommander.Server-Linux-x64-v${{ needs.prep.outputs.version_tag }}.zip -d ./LANCommander.Server/published-amd64
- name: Extract Server Artifacts arm64
run: |
mkdir -p ./LANCommander.Server/published-arm64
unzip ./LANCommander.Server-Linux-arm64-v${{ needs.prep.outputs.version_tag }}.zip -d ./LANCommander.Server/published-arm64
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Setup buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: ./LANCommander.Server
file: ./LANCommander.Server/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}:nightly
${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}:v${{ needs.prep.outputs.version_tag }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ needs.prep.outputs.version_tag }}
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
provenance: true
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- name: Save version to artifact
run: echo "${{ needs.prep.outputs.version_tag }}" > version.txt
- name: Upload version artifact
uses: actions/upload-artifact@v4
with:
name: version.${{ needs.prep.outputs.version_tag }}
path: version.txt
publish_nightly_release:
runs-on: ubuntu-latest
needs:
- prep
- publish_docker_image
- build_launcher_linux_arm64
- build_launcher_linux_x64
- build_launcher_osx_arm64
- build_launcher_osx_x64
- build_launcher_win_arm64
- build_launcher_win_x64
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Create Temp Directory
run: mkdir -p artifacts
- name: Download Server Linux ARM64
uses: actions/download-artifact@v4
with:
name: LANCommander.Server-Linux-arm64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Server Linux x64
uses: actions/download-artifact@v4
with:
name: LANCommander.Server-Linux-x64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Server macOS ARM64
uses: actions/download-artifact@v4
with:
name: LANCommander.Server-macOS-arm64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Server macOS x64
uses: actions/download-artifact@v4
with:
name: LANCommander.Server-macOS-x64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Server Windows ARM64
uses: actions/download-artifact@v4
with:
name: LANCommander.Server-Windows-arm64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Server Windows x64
uses: actions/download-artifact@v4
with:
name: LANCommander.Server-Windows-x64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Launcher Linux ARM64
uses: actions/download-artifact@v4
with:
name: LANCommander.Launcher-Linux-arm64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Launcher Linux x64
uses: actions/download-artifact@v4
with:
name: LANCommander.Launcher-Linux-x64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Launcher macOS ARM64
uses: actions/download-artifact@v4
with:
name: LANCommander.Launcher-macOS-arm64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Launcher macOS x64
uses: actions/download-artifact@v4
with:
name: LANCommander.Launcher-macOS-x64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Launcher Windows ARM64
uses: actions/download-artifact@v4
with:
name: LANCommander.Launcher-Windows-arm64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Launcher Windows x64
uses: actions/download-artifact@v4
with:
name: LANCommander.Launcher-Windows-x64-v${{ needs.prep.outputs.version_tag }}.zip
path: artifacts
- name: Download Launcher Linux ARM64 AppImage
uses: actions/download-artifact@v4
with:
name: LANCommander.Launcher-Linux-arm64-v${{ needs.prep.outputs.version_tag }}.AppImage
path: artifacts
- name: Download Launcher Linux x64 AppImage
uses: actions/download-artifact@v4
with:
name: LANCommander.Launcher-Linux-x64-v${{ needs.prep.outputs.version_tag }}.AppImage
path: artifacts
- name: Create or update nightly release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create the release if it doesn't exist, otherwise update its metadata
if gh release view nightly > /dev/null 2>&1; then
# Remove all existing assets so only this nightly's files remain
gh release view nightly --json assets -q '.assets[].name' | while read -r asset; do
gh release delete-asset nightly "$asset" -y
done
gh release edit nightly \
--prerelease \
--title "Nightly Build v${{ needs.prep.outputs.version_tag }}" \
--notes "This is the latest nightly build. These builds are generated automatically and should be considered unstable."
else
gh release create nightly \
--prerelease \
--title "Nightly Build v${{ needs.prep.outputs.version_tag }}" \
--notes "This is the latest nightly build. These builds are generated automatically and should be considered unstable."
fi
# Upload new artifacts
gh release upload nightly artifacts/*