Skip to content

Commit

Permalink
Move repeated workflow logic into custom actions
Browse files Browse the repository at this point in the history
  • Loading branch information
yut23 committed Jan 23, 2024
1 parent f1bcb13 commit 03bfbbf
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 88 deletions.
31 changes: 31 additions & 0 deletions .github/actions/answer-test-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'Run answer tests'
description: 'Helper for workflows/answer-tests.yml'
inputs:
compiler:
description: 'C++ compiler executable'
required: true
stdlib:
description: 'C++ standard library to use (libstdc++ or libc++)'
required: false
default: libstdc++

runs:
using: 'composite'
steps:
- shell: bash
working-directory: ${{ matrix.TARGET.directory }}
env:
CXX: ${{ inputs.compiler }}
USE_LIBCXX: ${{ inputs.stdlib == 'libc++' && 'TRUE' || 'FALSE' }}
run: |
echo
echo '::group::Compiler version'
$CXX --version
echo '::endgroup::'
echo '::group::Build target'
make --silent clean
make build/release/${{ matrix.TARGET.name }}
echo '::endgroup::'
echo
./run_answer_tests.sh ${{ matrix.TARGET.name }}
26 changes: 26 additions & 0 deletions .github/actions/build-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'Build target'
description: 'Helper for workflows/test-build.yml'
inputs:
compiler:
description: 'C++ compiler executable'
required: true
stdlib:
description: 'C++ standard library to use (libstdc++ or libc++)'
required: false
default: libstdc++

runs:
using: 'composite'
steps:
- shell: bash
working-directory: ${{ matrix.TARGET.directory }}
env:
CXX: ${{ inputs.compiler }}
USE_LIBCXX: ${{ inputs.stdlib == 'libc++' && 'TRUE' || 'FALSE' }}
run: |
echo
echo '::group::Compiler version'
$CXX --version
echo '::endgroup::'
echo
make -j4 DISABLE_SANITIZERS=TRUE build/release/${{ matrix.TARGET.name }} build/debug/${{ matrix.TARGET.name }} build/fast/${{ matrix.TARGET.name }}
31 changes: 31 additions & 0 deletions .github/actions/unit-test-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'Run unit tests'
description: 'Helper for workflows/unit-tests.yml'
inputs:
compiler:
description: 'C++ compiler executable'
required: true
stdlib:
description: 'C++ standard library to use (libstdc++ or libc++)'
required: false
default: libstdc++

runs:
using: 'composite'
steps:
- shell: bash
working-directory: ${{ matrix.TARGET.directory }}
env:
CXX: ${{ inputs.compiler }}
USE_LIBCXX: ${{ inputs.stdlib == 'libc++' && 'TRUE' || 'FALSE' }}
run: |
echo
echo '::group::Compiler version info'
$CXX --version
echo '::endgroup::'
echo '::group::Build target'
make --silent clean
make build/debug/${{ matrix.TARGET.name }}
echo '::endgroup::'
echo
make ${{ matrix.TARGET.name }}
51 changes: 18 additions & 33 deletions .github/workflows/answer-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,37 @@ jobs:
matrix:
TARGET: ${{ fromJson(needs.setup-matrix.outputs.targets) }}
container: ${{ needs.docker-build.outputs.image }}
defaults:
run:
shell: bash
working-directory: ${{ matrix.TARGET.directory }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Mark git checkout as safe
shell: bash
working-directory: ${{ matrix.TARGET.directory }}
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

- name: Run answer tests (clang++)
timeout-minutes: 2
run: |
export CXX=clang++ USE_LIBCXX=FALSE
echo '::group::make output'
$CXX --version
make --silent clean
make build/release/${{ matrix.TARGET.name }}
echo '::endgroup::'
./run_answer_tests.sh ${{ matrix.TARGET.name }}
id: clang
uses: ./.github/actions/answer-test-action
with:
compiler: clang++

- name: Run answer tests (g++)
timeout-minutes: 2
if: always()
run: |
export CXX=g++ USE_LIBCXX=FALSE
echo '::group::make output'
$CXX --version
make --silent clean
make build/release/${{ matrix.TARGET.name }}
echo '::endgroup::'
./run_answer_tests.sh ${{ matrix.TARGET.name }}
id: gcc
# ignore failures in the previous step
if: success() || steps.clang.conclusion == 'failure'
uses: ./.github/actions/answer-test-action
with:
compiler: g++

- name: Run answer tests (clang++-17, libc++)
timeout-minutes: 2
if: always()
run: |
export CXX=clang++-17 USE_LIBCXX=TRUE
echo '::group::make output'
$CXX --version
make --silent clean
make build/release/${{ matrix.TARGET.name }}
echo '::endgroup::'
./run_answer_tests.sh ${{ matrix.TARGET.name }}
# ignore failures in the previous two steps
if: success() || steps.clang.conclusion == 'failure' || steps.gcc.conclusion == 'failure'
uses: ./.github/actions/answer-test-action
with:
compiler: clang++-17
stdlib: libc++
4 changes: 3 additions & 1 deletion .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ on:
ubuntu-version:
required: true
type: string
default: 22.04
llvm-version:
required: true
type: string
default: 17
rebuild:
required: false
required: true
type: boolean
default: true

Expand Down
37 changes: 16 additions & 21 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,29 @@ jobs:
matrix:
TARGET: ${{ fromJson(needs.setup-matrix.outputs.targets) }}
container: ${{ needs.docker-build.outputs.image }}
defaults:
run:
shell: bash
working-directory: ${{ matrix.TARGET.directory }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Build target (clang++)
run: |
export CXX=clang++ USE_LIBCXX=FALSE
$CXX --version
make --silent clean
make -j4 DISABLE_SANITIZERS=TRUE build/release/${{ matrix.TARGET.name }} build/debug/${{ matrix.TARGET.name }} build/fast/${{ matrix.TARGET.name }}
id: clang
uses: ./.github/actions/build-action
with:
compiler: clang++

- name: Build target (g++)
if: always()
run: |
export CXX=g++ USE_LIBCXX=FALSE
$CXX --version
make --silent clean
make -j4 DISABLE_SANITIZERS=TRUE build/release/${{ matrix.TARGET.name }} build/debug/${{ matrix.TARGET.name }} build/fast/${{ matrix.TARGET.name }}
id: gcc
# ignore failures in the previous step
if: success() || steps.clang.conclusion == 'failure'
uses: ./.github/actions/build-action
with:
compiler: g++

- name: Build target (clang++-17, libc++)
if: always()
run: |
export CXX=clang++-17 USE_LIBCXX=TRUE
$CXX --version
make --silent clean
make -j4 DISABLE_SANITIZERS=TRUE build/release/${{ matrix.TARGET.name }} build/debug/${{ matrix.TARGET.name }} build/fast/${{ matrix.TARGET.name }}
# ignore failures in the previous two steps
if: success() || steps.clang.conclusion == 'failure' || steps.gcc.conclusion == 'failure'
uses: ./.github/actions/build-action
with:
compiler: clang++-17
stdlib: libc++
49 changes: 16 additions & 33 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,29 @@ jobs:
matrix:
TARGET: ${{ fromJson(needs.setup-matrix.outputs.targets) }}
container: ${{ needs.docker-build.outputs.image }}
defaults:
run:
shell: bash
working-directory: ${{ matrix.TARGET.directory }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Run unit tests (clang++)
run: |
export CXX=clang++ USE_LIBCXX=FALSE
echo '::group::make output'
$CXX --version
make --silent clean
make build/debug/${{ matrix.TARGET.name }}
echo '::endgroup::'
make ${{ matrix.TARGET.name }}
id: clang
uses: ./.github/actions/unit-test-action
with:
compiler: clang++

- name: Run unit tests (g++)
if: always()
run: |
export CXX=g++ USE_LIBCXX=FALSE
echo '::group::make output'
$CXX --version
make --silent clean
make build/debug/${{ matrix.TARGET.name }}
echo '::endgroup::'
make ${{ matrix.TARGET.name }}
id: gcc
# ignore failures in the previous step
if: success() || steps.clang.conclusion == 'failure'
uses: ./.github/actions/unit-test-action
with:
compiler: g++

- name: Run unit tests (clang++-17, libc++)
if: always()
run: |
export CXX=clang++-17 USE_LIBCXX=TRUE
echo '::group::make output'
$CXX --version
make --silent clean
make build/debug/${{ matrix.TARGET.name }}
echo '::endgroup::'
make ${{ matrix.TARGET.name }}
# ignore failures in the previous two steps
if: success() || steps.clang.conclusion == 'failure' || steps.gcc.conclusion == 'failure'
uses: ./.github/actions/unit-test-action
with:
compiler: clang++-17
stdlib: libc++

0 comments on commit 03bfbbf

Please sign in to comment.