Various fixes from my development branch #43
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This starter workflow is for a CMake project running on multiple platforms | |
name: build and package | |
on: | |
push: | |
branches: [ "main", "develop" ] | |
pull_request: | |
branches: [ "main", "develop" ] | |
jobs: | |
env: | |
runs-on: ubuntu-latest | |
outputs: | |
cmake-build-dir: ${{ steps.compute-env.outputs.cmake-build-dir }} | |
artifact-name: ${{ steps.compute-env.outputs.artifact-name }} | |
artifact-dir: ${{ steps.compute-env.outputs.artifact-dir }} | |
build-type: ${{ steps.compute-env.outputs.build-type }} | |
release-name: ${{ steps.compute-env.outputs.release-name }} | |
release-tag: ${{ steps.compute-env.outputs.release-tag }} | |
steps: | |
# Get the code | |
- uses: actions/checkout@v4 | |
# Extract VERSION from resource.h and format it | |
# Set global variables and variables based on the branch name | |
- name: Compute env | |
id: compute-env | |
run: | | |
VERSION=$(grep -oP 'FILE_VERSION\s+\K\d+(,\s+\d+){2}' src/Res/resource.h | sed -E 's/[, ]+/./g') | |
echo "cmake-build-dir=cmake-build" >> "$GITHUB_OUTPUT" | |
echo "artifact-dir=artifacts" >> "$GITHUB_OUTPUT" | |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then | |
echo "Setting production environment variables..." | |
echo "build-type=Release" >> "$GITHUB_OUTPUT" | |
echo "release-name=ATD Version $VERSION Release" >> "$GITHUB_OUTPUT" | |
echo "artifact-name=AT-$VERSION" >> "$GITHUB_OUTPUT" | |
echo "release-tag=v$VERSION" >> "$GITHUB_OUTPUT" | |
elif [ "${{ github.ref }}" == "refs/heads/develop" ]; then | |
echo "Setting development environment variables..." | |
echo "build-type=Release" >> "$GITHUB_OUTPUT" | |
echo "release-name=ATD Version $VERSION Pre-Release" >> "$GITHUB_OUTPUT" | |
echo "artifact-name=AT-$VERSION-preview" >> "$GITHUB_OUTPUT" | |
echo "release-tag=v$VERSION-preview" >> "$GITHUB_OUTPUT" | |
else | |
echo "Setting branch environment variables..." | |
echo "build-type=Debug" >> "$GITHUB_OUTPUT" | |
echo "release-name=ATD Version $VERSION Preview" >> "$GITHUB_OUTPUT" | |
echo "artifact-name=AT-$VERSION-${{ github.sha }}" >> "$GITHUB_OUTPUT" | |
echo "release-tag=v$VERSION-${{ github.sha }}" >> "$GITHUB_OUTPUT" | |
fi | |
cat $GITHUB_OUTPUT | |
build: | |
needs: env | |
runs-on: ${{ matrix.os }} | |
strategy: | |
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. | |
fail-fast: false | |
# Set up a matrix to run the following 2 configurations: | |
# 1. <Windows, Release or Debug, latest MSVC compiler toolchain on the default runner image, default generator> | |
# 2. <Linux, Release or Debug, latest GCC compiler toolchain on the default runner image, default generator> | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-13] | |
name: ['linux', 'windows', 'macos'] | |
build_type: | |
- ${{ needs.env.outputs.build-type }} | |
c_compiler: [gcc, cl] | |
exclude: # exclude all by default | |
- os: windows-latest | |
- os: ubuntu-latest | |
- os: macos-13 | |
include: # only include the configurations we want | |
- os: windows-latest | |
c_compiler: cl | |
cpp_compiler: cl | |
name: 'windows' | |
build_type: ${{ needs.env.outputs.build-type }} | |
- os: ubuntu-latest | |
c_compiler: gcc | |
cpp_compiler: g++ | |
name: 'linux' | |
build_type: ${{ needs.env.outputs.build-type }} | |
- os: macos-13 | |
c_compiler: gcc | |
cpp_compiler: g++ | |
name: 'macos' | |
build_type: ${{ needs.env.outputs.build-type }} | |
# Execute this for each matrix | |
# Warning: Don't get ${{ github.workspace }} from elsewhere! (like precomputed from env job) | |
# as GitHub actually set a different path for Windows that make the build fail | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Install Linux dependencies | |
if: matrix.name == 'linux' | |
run: | | |
sudo apt-get update | |
sudo apt-get install libjansson-dev libsdl2*-dev | |
- name: Setup homebrew (macOS) | |
if: matrix.name == 'macos' | |
id: set-up-homebrew | |
uses: Homebrew/actions/setup-homebrew@master | |
- name: Install macOS dependencies | |
if: matrix.name == 'macos' | |
# Temporary fix, see https://github.com/actions/setup-python/issues/577 | |
run: | | |
rm /usr/local/bin/2to3-3.12 || true | |
rm /usr/local/bin/idle3.12 || true | |
rm /usr/local/bin/pydoc3.12 || true | |
rm /usr/local/bin/python3.12 || true | |
rm /usr/local/bin/python3.12-config || true | |
rm /usr/local/bin/2to3 || true | |
rm /usr/local/bin/idle3 || true | |
rm /usr/local/bin/pydoc3 || true | |
rm /usr/local/bin/python3 || true | |
rm /usr/local/bin/python3-config || true | |
brew install cmake sdl2 sdl2_mixer sdl2_image sdl2_ttf jansson | |
- name: Configure CMake | |
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. | |
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type | |
# Make it verbose with -DCMAKE_VERBOSE_MAKEFILE=ON | |
run: > | |
cmake -B ${{ needs.env.outputs.cmake-build-dir }} | |
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} | |
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} | |
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} | |
-S ${{ github.workspace }} | |
- name: Build | |
# Build the program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). | |
run: cmake --build ${{ needs.env.outputs.cmake-build-dir }} --config ${{ matrix.build_type }} | |
# Package the build results (windows) | |
- name: Package artifact | |
id: artifact-win | |
if: matrix.name == 'windows' | |
run: | | |
# Set variables | |
$artifactName = "${{ needs.env.outputs.artifact-name }}-${{ matrix.name }}.zip" | |
$artifactPath = "${{ needs.env.outputs.artifact-dir }}/$artifactName" | |
# Create the artifact directory if it doesn't exist | |
if (!(Test-Path -Path ${{ needs.env.outputs.artifact-dir }} -PathType Container)) { | |
New-Item -Path ${{ needs.env.outputs.artifact-dir }} -ItemType Directory -Force | |
} | |
# Compress the files into the artifact | |
Compress-Archive -Path "${{ needs.env.outputs.cmake-build-dir }}/${{ matrix.build_type }}/*" -DestinationPath $artifactPath -Update | |
# Output artifact information | |
Write-Host "Building windows $artifactName" | |
Write-Host "artifact-name=$artifactName" | |
Write-Host "artifact-path=$artifactPath" | |
echo "artifact-name=$artifactName" >> $Env:GITHUB_OUTPUT | |
echo "artifact-path=$artifactPath" >> $Env:GITHUB_OUTPUT | |
# Package the build results (linux) | |
- name: Package artifact | |
id: artifact-linux | |
if: matrix.name == 'linux' || matrix.name == 'macos' | |
run: | | |
echo "Building linux ${{ needs.env.outputs.artifact-name }}-${{ matrix.name }}.tar" | |
ARTIFACT_NAME=${{ needs.env.outputs.artifact-name }}-${{ matrix.name }}.tar | |
ARTIFACT_PATH=${{ needs.env.outputs.artifact-dir }}/$ARTIFACT_NAME | |
mkdir -p ${{ needs.env.outputs.artifact-dir }} | |
tar -cvf $ARTIFACT_PATH -C ${{ github.workspace }}/${{ needs.env.outputs.cmake-build-dir }}/${{ matrix.build_type }} . | |
echo "artifact-name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT" | |
echo "artifact-path=$ARTIFACT_PATH" >> "$GITHUB_OUTPUT" | |
cat $GITHUB_OUTPUT | |
- name: Upload sentry debug files | |
shell: pwsh | |
# Only publish on main/dev build & windows | |
if: matrix.name == 'windows' && (github.ref_name == 'main' || github.ref_name == 'develop') && vars.SENTRY_ORG != '' | |
env: | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
SENTRY_ORG: ${{ vars.SENTRY_ORG }} | |
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }} | |
# SENTRY_URL: https://sentry.io/ | |
run: | | |
curl -sL https://github.com/getsentry/sentry-cli/releases/download/2.32.1/sentry-cli-Windows-x86_64.exe > sentry-cli.exe | |
./sentry-cli.exe debug-files upload ${{ needs.env.outputs.cmake-build-dir }}/${{ matrix.build_type }}/ | |
- name: Publish artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ steps.artifact-win.outputs.artifact-name || steps.artifact-linux.outputs.artifact-name }} | |
path: ${{ steps.artifact-win.outputs.artifact-path || steps.artifact-linux.outputs.artifact-path }} | |
release: | |
runs-on: ubuntu-latest | |
needs: [ build, env ] | |
if: github.ref_name == 'main' || github.ref_name == 'develop' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create tag | |
shell: bash | |
run: | | |
git tag -f ${{ needs.env.outputs.release-tag }} | |
git push origin -f ${{ needs.env.outputs.release-tag }} | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: ${{ needs.env.outputs.artifact-name }}* | |
path: ${{ needs.env.outputs.artifact-dir }} | |
merge-multiple: true | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
target_commitish: ${{ github.sha }} | |
name: ${{ needs.env.outputs.release-name }} | |
tag_name: ${{ needs.env.outputs.release-tag }} | |
prerelease: ${{ github.ref_name == 'develop' }} | |
draft: ${{ github.ref_name == 'main' || github.ref_name == 'develop' }} | |
files: | | |
${{ needs.env.outputs.artifact-dir }}/${{ needs.env.outputs.artifact-name }}* |