124 lines
3.5 KiB
YAML
124 lines
3.5 KiB
YAML
|
|
name: ci
|
|
|
|
# Build and test on every push and pull request.
|
|
# Upload unpacked files as Actions artifacts.
|
|
# Create ZIP archives only when publishing a release.
|
|
|
|
on:
|
|
push:
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
name: ${{ matrix.os }}
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
include:
|
|
- os: ubuntu-latest
|
|
label: linux
|
|
- os: macos-latest
|
|
label: macos
|
|
- os: windows-latest
|
|
label: windows
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Check the tag against the declared version
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
shell: bash
|
|
run: |
|
|
declared=$(sed -n 's/.*JOC_VERSION_STRING *"\([^"]*\)".*/\1/p' include/joc_version.h)
|
|
if [ -z "$declared" ] || [ "$GITHUB_REF_NAME" != "v$declared" ]; then
|
|
echo "the tag $GITHUB_REF_NAME does not match JOC_VERSION_STRING (${declared:-unset})" >&2
|
|
exit 1
|
|
fi
|
|
|
|
- name: Configure
|
|
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
|
|
|
|
- name: Build
|
|
run: cmake --build build --config Release --parallel
|
|
|
|
- name: Test
|
|
run: ctest --test-dir build --output-on-failure -C Release
|
|
|
|
- name: Stage
|
|
run: cmake --install build --config Release --prefix stage
|
|
|
|
# Place executables at the package root and libraries in lib/.
|
|
- name: Package
|
|
shell: bash
|
|
run: |
|
|
mkdir -p package/lib
|
|
cp -r stage/bin/. package/
|
|
cp -r stage/lib/. package/lib/
|
|
|
|
# GitHub automatically creates the artifact ZIP.
|
|
# Upload files directly to avoid nested ZIP archives.
|
|
- name: Upload
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: joc_cli_${{ matrix.label }}
|
|
path: package/
|
|
if-no-files-found: error
|
|
|
|
release:
|
|
# Only tagged builds create releases.
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
# Keep each platform's files in a separate directory.
|
|
- name: Collect build artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
pattern: joc_cli_*
|
|
path: dist
|
|
merge-multiple: false
|
|
|
|
# Create flat ZIP archives from the artifact contents.
|
|
# Restore executable permissions on Unix platforms.
|
|
- name: Create release archives
|
|
shell: bash
|
|
run: |
|
|
for platform in linux macos windows; do
|
|
dir="dist/joc_cli_${platform}"
|
|
|
|
if [ ! -d "$dir" ]; then
|
|
echo "Missing artifact: joc_cli_${platform}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$platform" != "windows" ]; then
|
|
chmod +x "$dir/joc_cli"
|
|
fi
|
|
|
|
(
|
|
cd "$dir"
|
|
cmake -E tar cf "../joc_cli_${platform}.zip" --format=zip -- *
|
|
)
|
|
done
|
|
|
|
- name: List release archives
|
|
run: ls -lh dist/*.zip
|
|
|
|
# Publish the archives directly to GitHub Releases.
|
|
- name: Publish
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1 \
|
|
|| gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \
|
|
--title "$GITHUB_REF_NAME" --generate-notes
|
|
gh release upload "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \
|
|
--clobber dist/*.zip
|