Skip to content

Commit

Permalink
Add Github action to test building with GCC and Clang
Browse files Browse the repository at this point in the history
  • Loading branch information
yut23 committed Dec 3, 2023
1 parent 48a8f10 commit 62d5d1d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/gen_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import json
import sys
from pathlib import Path

includes: list[dict[str, str]] = []
changed_files = json.loads(sys.argv[1])
for file in changed_files:
path = Path(file)
print(path)

includes.append({"dir": "2023", "target": "day01"})
includes.append({"dir": "2023", "target": "day02"})
includes.append({"dir": "2023", "target": "day03"})
includes.append({"dir": "2022", "target": "day19"})

matrix = {
"dir": [],
"target": [],
"compiler": ["clang++", "g++"],
}
print(
"::set-output name=matrix-combinations::"
+ json.dumps({**matrix, "include": includes})
)
44 changes: 44 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test builds

on:
push:
branches:
- main
workflow_dispatch:

jobs:
setup-matrix:
runs-on: ubuntu-latest
name: Test changed files
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v40
with:
json: true
files: |
*/src/day*.cpp
*/src/lib.h*
*/Makefile
# reference: https://stackoverflow.com/a/65094398
- name: Setup matrix combinations
id: setup-matrix-combinations
run: python ${GITHUB_WORKSPACE}/.github/workflows/gen_matrix.py "${{ steps.changed-files.outputs.all_changed_files }}"
outputs:
matrix-combinations: ${{ steps.setup-matrix-combinations.outputs.matrix-combinations }}

matrix-job:
runs-on: ubuntu-latest
needs: setup-matrix
strategy:
matrix:
${{ fromJson(needs.setup-matrix.outputs.matrix-combinations) }}
steps:
- name: Build targets
run: |
cd ${{ matrix.dir }}
make -j2 CXX=${{ matrix.compiler }} DISABLE_BEAR=TRUE build/release/${{ matrix.target }} build/debug/${{ matrix.target }}

0 comments on commit 62d5d1d

Please sign in to comment.