Skip to content

Major refactoring of nightly builds GitHub Actions workflow #80

Major refactoring of nightly builds GitHub Actions workflow

Major refactoring of nightly builds GitHub Actions workflow #80

name: nightly-builds
on: push
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: windows-latest
cmake_preset: windows-x86-debug
build_conf: Debug
devenv_arch: amd64_x86
env:
# Indicates the location of the vcpkg as a Git submodule of the project repository.
VCPKG_ROOT: ${{ github.workspace }}/external/vcpkg
# Tells vcpkg where binary packages are stored.
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/external/vcpkg/bincache
# Let's use GitHub Action cache as storage for the vcpkg Binary Caching feature.
VCPKG_BINARY_SOURCES: 'clear;x-gha,readwrite'
steps:
# Set env vars needed for vcpkg to leverage the GitHub Action cache as a storage
# for Binary Caching.
- name: Set env vars needed for vcpkg to leverage the GitHub Action cache
uses: actions/github-script@v6
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Create build environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{github.workspace}}/build
- uses: ilammy/[email protected]
if: runner.os == 'Windows'
with:
arch: ${{ matrix.devenv_arch }}
- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@v4
- name: "Create directory '${{ env.VCPKG_DEFAULT_BINARY_CACHE }}'"
shell: bash
run: mkdir -p $VCPKG_DEFAULT_BINARY_CACHE
# Restore vcpkg from the GitHub Action cache service. Note that packages are restored by vcpkg's binary caching
# when it is being run afterwards by CMake.
- name: Restore vcpkg
uses: actions/cache@v3
with:
# The first path is the location of vcpkg: it contains the vcpkg executable and data files, as long as the
# built package archives (aka binary cache) which are located by VCPKG_DEFAULT_BINARY_CACHE env var.
# The other paths starting with '!' are exclusions: they contain termporary files generated during the build of the installed packages.
path: |
${{ env.VCPKG_ROOT }}
!${{ env.VCPKG_ROOT }}/buildtrees
!${{ env.VCPKG_ROOT }}/packages
!${{ env.VCPKG_ROOT }}/downloads
!${{ env.VCPKG_ROOT }}/installed
# The key is composed in a way that it gets properly invalidated whenever a different version of vcpkg is being used.
key: |
${{ hashFiles( '.git/modules/external/vcpkg/HEAD' )}}
- name: Configure CMake
working-directory: ${{ github.workspace }}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake "${{ github.workspace }}" --preset ${{ matrix.cmake_preset }}
- name: Build
working-directory: ${{github.workspace}}/build
run: cmake --build . --parallel 4
- name: Prepare artifacts
shell: bash
run: |
ls -l build/
mkdir publish/
mkdir artifacts/
cp build/${{ matrix.build_conf }}/bin/gsm-library.dll publish/gsm-library.dll
cp build/${{ matrix.build_conf }}/bin/gsm-loader.exe publish/gsm-loader.exe
cp -r resources/program_dir/* publish
# we forced to do this split because Git on Windows can't use zip, bruh
- name: Pack artifact files to archive (Windows)
if: runner.os == 'Windows'
run: |
Compress-Archive -Path publish\* -Destination artifacts\goldsrc-monitor_${{ matrix.cmake_preset }}.zip
- name: Upload artifacts
uses: actions/[email protected]
with:
name: artifact-${{ matrix.cmake_preset }}
path: artifacts/*
release:
name: release-builds
runs-on: ubuntu-latest
needs: [build]
if: ${{ github.ref == 'refs/heads/master' }}
steps:
- name: Fetch artifacts
uses: actions/[email protected]
with:
path: artifacts/
- name: Remove old release
uses: dev-drprasad/[email protected]
with:
delete_release: true
tag_name: continuous
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Repackage binaries and allow GitHub to process removed release for few seconds
shell: bash
continue-on-error: true
run: |
cd artifacts/
for i in artifact-*; do
mv "$i"/* .
rm -rf "$i"
done
ls -R .
cd ../
sleep 20s
- name: Upload new release
uses: softprops/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: artifacts/*
tag_name: continuous
draft: false
prerelease: true
name: GoldSrc Monitor Continuous Build