mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
shell: bash on the self-hosted Windows runner resolved to the WSL launcher at C:\Windows\System32\bash.exe (Git Bash isn't on the NETWORK SERVICE account's PATH), so Resolve version died with 'no installed distributions'. Default the build job's run steps to Windows PowerShell 5.1 (always present) and rewrite Resolve version accordingly, dropping the bash/WSL dependency from the native-Windows build.
114 lines
4.2 KiB
YAML
114 lines
4.2 KiB
YAML
name: Build
|
|
|
|
on:
|
|
push:
|
|
branches: ['**']
|
|
tags: ['v*']
|
|
# Manual escape hatch (e.g. when push webhooks are throttled during a
|
|
# GitHub Actions incident). Run from the Actions UI:
|
|
# - select a `vX.Y.Z` tag ref -> release build of that tag, OR
|
|
# - run from a branch and pass `tag: vX.Y.Z` -> release build that
|
|
# creates/attaches the release to that tag.
|
|
# Leave `tag` blank on a branch run for a plain dev build (artifact).
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: 'Release tag to build (e.g. v2.0.0). Blank = dev build.'
|
|
required: false
|
|
default: ''
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
# Decide which runner the build lands on. `runs-on` is fixed before a job
|
|
# starts and a job pointed at an offline self-hosted runner queues forever
|
|
# instead of failing over — so we probe first and hand the label down.
|
|
pick-runner:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
label: ${{ steps.pick.outputs.label }}
|
|
steps:
|
|
- name: Probe for an online self-hosted runner
|
|
id: pick
|
|
env:
|
|
# Listing runners needs repo-admin access; the default GITHUB_TOKEN
|
|
# does NOT have it. Create a PAT (classic: `repo`; fine-grained:
|
|
# Administration → read) and store it as the RUNNER_CHECK_TOKEN
|
|
# secret. If the secret is missing, we fall back to windows-latest.
|
|
GH_TOKEN: ${{ secrets.RUNNER_CHECK_TOKEN }}
|
|
run: |
|
|
label=windows-latest
|
|
if [ -n "$GH_TOKEN" ]; then
|
|
online=$(gh api "repos/${{ github.repository }}/actions/runners" \
|
|
--jq '[.runners[] | select(.status=="online") | select([.labels[].name] | index("self-hosted"))] | length' \
|
|
2>/dev/null || echo 0)
|
|
if [ "${online:-0}" -gt 0 ]; then
|
|
label=self-hosted
|
|
fi
|
|
fi
|
|
echo "Selected runner: $label"
|
|
echo "label=$label" >> "$GITHUB_OUTPUT"
|
|
|
|
build:
|
|
needs: pick-runner
|
|
runs-on: ${{ needs.pick-runner.outputs.label }}
|
|
# Windows PowerShell 5.1 is always present; the runner's default `pwsh`
|
|
# (PowerShell Core) is not installed by default, and `shell: bash` on a
|
|
# self-hosted box resolves to the WSL launcher in System32.
|
|
defaults:
|
|
run:
|
|
shell: powershell
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
|
|
# Resolve the effective version once so every step below agrees.
|
|
# is_release=true when a vX.Y.Z tag is in play (pushed tag,
|
|
# dispatched-from-tag, or a `tag` input); the embedded addon's
|
|
# `## Version:` and the compiled CLASSIC_API_VERSION are both
|
|
# stamped from it at embed/compile time (see cmake/embed_addon.cmake)
|
|
# — no source edit.
|
|
- name: Resolve version
|
|
id: ver
|
|
env:
|
|
INPUT_TAG: ${{ inputs.tag }}
|
|
run: |
|
|
if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch' -and $env:INPUT_TAG) {
|
|
$tag = $env:INPUT_TAG
|
|
} elseif ($env:GITHUB_REF -like 'refs/tags/v*') {
|
|
$tag = $env:GITHUB_REF_NAME
|
|
} else {
|
|
$tag = ''
|
|
}
|
|
$isRelease = if ($tag) { 'true' } else { 'false' }
|
|
Add-Content -Path $env:GITHUB_OUTPUT -Value "tag=$tag" -Encoding utf8
|
|
Add-Content -Path $env:GITHUB_OUTPUT -Value "is_release=$isRelease" -Encoding utf8
|
|
|
|
- name: Configure (release)
|
|
if: steps.ver.outputs.is_release == 'true'
|
|
run: cmake -B build -A Win32 "-DCLASSICAPI_TAG=${{ steps.ver.outputs.tag }}"
|
|
|
|
- name: Configure (dev)
|
|
if: steps.ver.outputs.is_release != 'true'
|
|
run: cmake -B build -A Win32
|
|
|
|
- name: Build
|
|
run: cmake --build build --config Release
|
|
|
|
- name: Upload artifact
|
|
if: steps.ver.outputs.is_release != 'true'
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: ClassicAPI-${{ github.sha }}
|
|
path: build/Release/ClassicAPI.dll
|
|
|
|
- name: Release
|
|
if: steps.ver.outputs.is_release == 'true'
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
tag_name: ${{ steps.ver.outputs.tag }}
|
|
files: build/Release/ClassicAPI.dll
|
|
generate_release_notes: true
|