113 lines
3.6 KiB
YAML
113 lines
3.6 KiB
YAML
|
|
name: ci
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- main
|
|
schedule:
|
|
- cron: '0 1 * * 0'
|
|
|
|
# https://docs.docker.com/build/ci/github-actions/share-image-jobs/
|
|
# just using caches instead of artifact upload.
|
|
jobs:
|
|
docker-build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: docker/setup-buildx-action@v2
|
|
- uses: actions/setup-go@v3
|
|
with:
|
|
go-version: '1.20'
|
|
-
|
|
name: Create docker cache folder
|
|
run: mkdir -p /tmp/docker
|
|
-
|
|
name: Hash dockerfile
|
|
id: dockerfile-hash
|
|
uses: https://gitea.com/actions/go-hashfiles@v0.0.1
|
|
with:
|
|
patterns: builder.Dockerfile
|
|
-
|
|
name: Restore docker image
|
|
id: cache-docker
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: /tmp/docker
|
|
key: ${{ runner.os }}-docker-${{ steps.dockerfile-hash.outputs.hash }}
|
|
-
|
|
name: Build docker builder-image
|
|
if: steps.cache-docker.outputs.cache-hit != 'true'
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: .
|
|
file: builder.Dockerfile
|
|
tags: cproject-builder:latest
|
|
outputs: type=docker,dest=/tmp/docker/${{ runner.os }}-builder-image.tar
|
|
-
|
|
name: Upload docker image
|
|
if: steps.cache-docker.outputs.cache-hit != 'true'
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: ${{ runner.os }}-docker-${{ steps.dockerfile-hash.outputs.hash }}
|
|
path: /tmp/docker/${{ runner.os }}-builder-image.tar
|
|
retention-days: 3
|
|
|
|
build-and-test:
|
|
runs-on: ubuntu-latest
|
|
needs: docker-build
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: docker/setup-buildx-action@v2
|
|
- uses: actions/setup-go@v3
|
|
with:
|
|
go-version: '1.20'
|
|
-
|
|
name: Hash dockerfile
|
|
id: dockerfile-hash
|
|
uses: https://gitea.com/actions/go-hashfiles@v0.0.1
|
|
with:
|
|
patterns: builder.Dockerfile
|
|
-
|
|
name: Download docker image
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: ${{ runner.os }}-docker-${{ steps.dockerfile-hash.outputs.hash }}
|
|
path: /tmp/docker/${{ runner.os }}-builder-image.tar
|
|
-
|
|
name: Build library
|
|
uses: https://git.brocklobsta.net/brock/docker-run-action@v4
|
|
with:
|
|
tarball: /tmp/docker/${{ runner.os }}-builder-image.tar
|
|
image: cproject-builder:latest
|
|
options: --volumes-from ${{ env.JOB_CONTAINER_NAME }}
|
|
run: |
|
|
/bin/bash -c "cd ${{ github.workspace }}; rm -rf build; cmake -B build; cmake --build build"
|
|
-
|
|
name: Test library
|
|
uses: https://git.brocklobsta.net/brock/docker-run-action@v4
|
|
with:
|
|
tarball: /tmp/docker/${{ runner.os }}-builder-image.tar
|
|
image: cproject-builder:latest
|
|
options: --volumes-from ${{ env.JOB_CONTAINER_NAME }}
|
|
run: |
|
|
/bin/bash -c "cd ${{ github.workspace }}/tests/unittest; ceedling clobber; ceedling gcov:all; ceedling utils:gcov"
|
|
-
|
|
name: Archive coverage results
|
|
shell: bash
|
|
run: |
|
|
staging="reports-${{github.run_number}}"
|
|
mkdir -p "$staging"
|
|
cp -r tests/unittest/build/artifacts/gcov "$staging"
|
|
tar czf "$staging.tar.gz" "$staging"
|
|
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
|
|
-
|
|
name: Archive artifacts
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: reports-${{github.run_number}}
|
|
path: ${{ env.ASSET }}
|
|
retention-days: 3
|
|
|
|
# TODO: delete cache on merge.
|