这是indexloc提供的服务,不要输入任何密码
Skip to content

Update README with implementation link #15

Update README with implementation link

Update README with implementation link #15

# CMake CI across multiple platforms + upload only the binary + release on tag
name: CMake on multiple platforms
on:
push:
branches: [ "main" ]
tags: [ "v*" ]
pull_request:
branches: [ "main" ]
# Needed so we can create releases
permissions:
contents: write
env:
APP_NAME: UCraft
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
steps:
- uses: actions/checkout@v4
- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
echo "artifact-name=${{ env.APP_NAME }}-${{ runner.os }}-${{ matrix.c_compiler }}" >> "$GITHUB_OUTPUT"
echo "staging-dir=${{ github.workspace }}/build/out" >> "$GITHUB_OUTPUT"
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}
# --- Collect just the binary and rename it per platform/compiler ---
- name: Stage binary (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$buildDir = "${{ steps.strings.outputs.build-output-dir }}\src\Release"
$outDir = "${{ steps.strings.outputs.staging-dir }}"
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
$exe = Get-ChildItem -Path $buildDir -Filter *.exe -File | Select-Object -First 1
if (-not $exe) { throw "No .exe found in $buildDir" }
$dest = Join-Path $outDir "${{ steps.strings.outputs.artifact-name }}.exe"
Copy-Item $exe.FullName $dest -Force
Write-Host "Staged $($exe.Name) -> $dest"
- name: Stage binary (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
set -euo pipefail
build_dir="${{ steps.strings.outputs.build-output-dir }}/src"
out_dir="${{ steps.strings.outputs.staging-dir }}"
mkdir -p "$out_dir"
# pick the first executable regular file in build/src, excluding shared libs
bin_path="$(find "$build_dir" -maxdepth 1 -type f -executable ! -name '*.so' | head -n 1 || true)"
if [[ -z "${bin_path}" ]]; then
echo "No executable found in $build_dir" >&2
exit 1
fi
dest="${out_dir}/${{ steps.strings.outputs.artifact-name }}"
cp -f "$bin_path" "$dest"
chmod +x "$dest"
echo "Staged $(basename "$bin_path") -> $dest"
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.strings.outputs.artifact-name }}
path: ${{ steps.strings.outputs.staging-dir }}/*
if-no-files-found: error
retention-days: 7
release:
if: startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-latest
steps:
- name: Download binaries
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: List downloaded files (debug)
run: ls -la dist
- name: Generate checksums
run: |
cd dist
find . -type f -print0 | xargs -0 sha256sum > SHA256SUMS.txt
cd -
- name: Create GitHub Release and upload binaries
uses: softprops/action-gh-release@v2
with:
files: |
dist/**/*
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}