CI: modify to reusable workflow #910
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
name: Build, Lint and Test | |
on: | |
pull_request: {} | |
workflow_call: # defines it as reusable workflow | |
inputs: | |
repository: | |
description: The repo to checkout and run the workflow steps in | |
type: string | |
required: true | |
repository_ref: | |
description: The ref (branch, tag, commit-hash) of the `inputs.repository` | |
type: string | |
required: true | |
cmake_flags_extra: | |
description: additional flags to add to the common set of flags (see `.ci/build-kit/compile.sh`) | |
type: string | |
unit_tests: | |
description: Whether to run unit-tests or not | |
type: boolean | |
required: true | |
integration_tests: | |
description: Whether to run integration-tests or not | |
type: boolean | |
required: true | |
workflow_dispatch: | |
inputs: | |
runner: | |
description: Which runner to use | |
type: choice | |
default: 'ubuntu-22.04' | |
required: true | |
options: | |
- 'ubuntu-22.04' | |
- 'large-ubuntu-22.04-xxl' | |
schedule: | |
- cron: '37 13,1 * * *' | |
jobs: | |
build: | |
name: Build, Lint and Test | |
runs-on: ${{ inputs.runner || 'ubuntu-22.04' }} | |
steps: | |
- name: Format branch name for cache key | |
run: | | |
BRANCH_NAME_FOR_CACHE="${GITHUB_REF_NAME//-/_}" | |
echo "branch_name_for_cache=${BRANCH_NAME_FOR_CACHE}" >> "$GITHUB_ENV" | |
- name: Restore cache | |
uses: actions/cache/restore@v3 | |
id: restore-cache | |
with: | |
path: cache # keep in sync with "Store cache" | |
key: compile-${{ env.branch_name_for_cache }}-${{ github.sha }} | |
restore-keys: | | |
compile-${{ env.branch_name_for_cache }}- | |
compile- | |
- name: Checkout from `everest-core` the `.ci/` directory (reusable workflow mode, see https://stackoverflow.com/a/74123003/1168315) | |
uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
.ci | |
repository: EVerest/everest-core | |
ref: CI/reusable-workflow # TODO get reference in general, see https://stackoverflow.com/questions/74784735 resp. https://github.com/actions/toolkit/issues/1264 | |
- name: Checkout repo ${{ inputs.repository || 'EVerest/everest-core' }} | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ inputs.repository }} | |
ref: ${{ inputs.repository_ref }} | |
- name: Run clang-format | |
uses: everest/everest-ci/github-actions/[email protected] | |
with: | |
source-dir: . # FIXME Make sure `.` is the default to remove this line. | |
extensions: hpp,cpp | |
exclude: cache | |
- name: Pull build-kit image | |
run: | | |
docker pull --quiet ghcr.io/everest/build-kit-alpine:latest | |
docker image tag ghcr.io/everest/build-kit-alpine:latest build-kit | |
- name: Compile | |
env: | |
CMAKE_FLAGS_EXTRA: ${{ inputs.cmake_flags_extra || '-DEVC_ENABLE_CCACHE=1 -DISO15118_2_GENERATE_AND_INSTALL_CERTIFICATES=OFF' }} | |
run: | | |
docker run \ | |
--volume "$(pwd):/ext" \ | |
--workdir /ext \ | |
--env CMAKE_FLAGS_EXTRA="${CMAKE_FLAGS_EXTRA:?}" \ | |
--name compile-container \ | |
build-kit .ci/build-kit/compile.sh | |
- name: Unit tests | |
if: ${{ inputs.unit_tests || false }} | |
run: | | |
docker commit compile-container unit-tests-image | |
trap "cp build/Testing/Temporary/LastTest.log /tmp/ctest-report" EXIT | |
docker run \ | |
--volume "$(pwd):/ext" \ | |
--workdir /ext \ | |
--name test-container \ | |
unit-tests-image .ci/build-kit/unit_tests.sh | |
- name: Integration tests | |
if: ${{ inputs.integration_tests || true }} | |
working-directory: .ci/e2e/ | |
run: | | |
docker commit compile-container integration-tests-image | |
docker-compose run \ | |
--workdir /ext \ | |
e2e-test-server scripts/tests.sh | |
- name: FIXME make all files in `cache/` readable | |
# FIXME Workaround for non-readable certs in `cache/josev/[ID]/Josev/iso15118/shared/pki/iso15118_2/certs . See https://github.com/EVerest/everest-core/actions/runs/7286554315/job/19855498928#step:13:10 | |
if: always() | |
run: | | |
sudo chown --recursive $(id --user --name):$(id --user --name) cache/josev/ | |
- name: Store cache | |
uses: actions/cache/save@v3 | |
if: always() | |
with: | |
path: cache # keep in sync with "Restore cache" | |
key: ${{ steps.restore-cache.outputs.cache-primary-key }} | |
- name: Archive test results | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ctest-report | |
path: /tmp/ctest-report |