Skip to content

Commit 5beffc9

Browse files
committed
Add CI to build and upload this project.
1 parent 8f0cf48 commit 5beffc9

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

.github/workflows/cmake.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: CMake
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
defaults:
8+
run:
9+
shell: bash
10+
11+
env:
12+
project-name: pyromancer
13+
# Build mode for CMake, such as "Release" or "Debug".
14+
BUILD_TYPE: Release
15+
# Indicates the location of the vcpkg as a Git submodule of the project repository.
16+
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
17+
18+
jobs:
19+
build:
20+
runs-on: ${{ matrix.os }}
21+
strategy:
22+
fail-fast: true
23+
matrix:
24+
include:
25+
- os: windows-2019
26+
triplet: x64-windows
27+
platform-name: windows.x64
28+
- os: macos-12
29+
triplet: x64-osx
30+
platform-name: macos.x64
31+
- os: ubuntu-20.04
32+
triplet: x64-linux
33+
platform-name: linux.x64
34+
35+
env:
36+
# Indicates the CMake build directory where project files and binaries are being produced.
37+
CMAKE_BUILD_DIR: ${{ github.workspace }}/build
38+
39+
steps:
40+
# fetch-depth=0 and v1 are needed for 'git describe' to work correctly.
41+
- uses: actions/checkout@v1
42+
with:
43+
fetch-depth: 0
44+
submodules: true
45+
# Setup the build machine with the most recent versions of CMake and Ninja. Both are cached if not already: on subsequent runs both will be quickly restored from GitHub cache service.
46+
- uses: lukka/get-cmake@latest
47+
- name: Restore vcpkg and its artifacts
48+
uses: actions/cache@v2
49+
with:
50+
# The first path is where vcpkg generates artifacts while consuming the vcpkg.json manifest file.
51+
# The second path is the location of vcpkg (it contains the vcpkg executable and data files).
52+
# The other paths starting with '!' are exclusions: they contain temporary files generated during the build of the installed packages.
53+
path: |
54+
${{ env.CMAKE_BUILD_DIR }}/vcpkg_installed/
55+
${{ env.VCPKG_ROOT }}
56+
!${{ env.VCPKG_ROOT }}/buildtrees
57+
!${{ env.VCPKG_ROOT }}/packages
58+
!${{ env.VCPKG_ROOT }}/downloads
59+
# The key is composed in a way that it gets properly invalidated: this must happen whenever vcpkg's Git commit id changes, or the list of packages changes. In this case a cache miss must happen and a new entry with a new key with be pushed to GitHub the cache service.
60+
# The key includes: hash of the vcpkg.json file, the hash of the vcpkg Git commit id, and the used vcpkg's triplet. The vcpkg's commit id would suffice, but computing an hash out it does not harm.
61+
# Note: given a key, the cache content is immutable. If a cache entry has been created improperly, in order the recreate the right content the key must be changed as well, and it must be brand new (i.e. not existing already).
62+
key: ${{ matrix.triplet }}-${{ hashFiles('vcpkg.json', '.git/modules/vcpkg/HEAD') }}
63+
# On Windows runners, let's ensure to have the Developer Command Prompt environment setup correctly. As used here the Developer Command Prompt created is targeting x64 and using the default the Windows SDK.
64+
- uses: ilammy/msvc-dev-cmd@v1
65+
# Run CMake to generate Ninja project files, using the vcpkg's toolchain file to resolve and install the dependencies as specified in vcpkg.json.
66+
- name: Install dependencies and generate project files
67+
run: |
68+
cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -GNinja \
69+
-DVCPKG_TARGET_TRIPLET="${{ matrix.triplet }}" \
70+
-DCMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}"
71+
# Build the whole project with Ninja (which is spawn by CMake).
72+
- name: Build
73+
run: |
74+
cmake --build "${{ env.CMAKE_BUILD_DIR }}"
75+
- name: Show contents of the build directory
76+
run: find "${{ env.CMAKE_BUILD_DIR }}"
77+
# Sets env.archive-name, which is used to name the distribution folder and archive.
78+
- name: Set archive name
79+
run: |
80+
ARCHIVE_NAME=${{ env.project-name }}-`git describe --always`-${{ matrix.platform-name }}
81+
echo "Archive name set to: $ARCHIVE_NAME"
82+
echo "archive-name=$ARCHIVE_NAME" >> $GITHUB_ENV
83+
# Copy files from the CMake build and data directory into a new distribution folder.
84+
- name: Package distribution
85+
run: |
86+
mkdir -p dist/${{ env.archive-name }}
87+
cp "${{ env.CMAKE_BUILD_DIR }}/bin"/* dist/${{ env.archive-name }}
88+
cp -R data dist/${{ env.archive-name }}
89+
- name: Show contents of the dist directory
90+
run: find dist/${{ env.archive-name }}
91+
# Zip the distribution folder, using the platform appropriate tools.
92+
- name: Tar files
93+
if: runner.os != 'Windows'
94+
working-directory: ./dist
95+
run: |
96+
tar --format=ustar -czvf "../${{ env.archive-name }}.tar.gz" */
97+
- name: Archive files
98+
if: runner.os == 'Windows'
99+
shell: pwsh
100+
run: |
101+
Compress-Archive dist/*/ ${{ env.archive-name }}.zip
102+
# Upload archives as artifacts, these can be downloaded from the GitHub Actions page.
103+
- name: "Upload Artifact"
104+
uses: actions/upload-artifact@v2
105+
with:
106+
name: automated-builds
107+
path: ${{ env.archive-name }}.*
108+
retention-days: 7
109+
if-no-files-found: error
110+
# If a tag is pushed then a new archives are uploaded to GitHub Releases automatically.
111+
- name: Upload release
112+
if: startsWith(github.ref, 'refs/tags/')
113+
uses: svenstaro/upload-release-action@v2
114+
with:
115+
repo_token: ${{ secrets.GITHUB_TOKEN }}
116+
file: ${{ env.archive-name }}.*
117+
file_glob: true
118+
tag: ${{ github.ref }}
119+
overwrite: true

0 commit comments

Comments
 (0)