-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (54 loc) · 2.04 KB
/
coverage-tests.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Workflow to check code coverage on push.
# This action caches the built Docker image for a month unless any change in the Dockerfile.
name: 100% Coverage
on:
workflow_dispatch:
pull_request:
branches:
- main
env:
PATH_CACHE: /tmp/docker-img-arch
jobs:
go:
name: Run tests on Go via container
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Create image tag
id: imagetag
run: |
HASH_IMAGE=${{ hashFiles('./.github/Dockerfile') }}
VARIANT=$(TZ=UTC-9 date '+%Y%m')
TAG="${HASH_IMAGE:0:7}:${VARIANT}"
PATH_TAR=${{ env.PATH_CACHE }}"/tar"
echo "::set-output name=TAG::${TAG}"
echo "::set-output name=PATH_TAR::${PATH_TAR}"
- name: Cache or restore image archive
id: cache
uses: actions/cache@v2
with:
path: ${{ env.PATH_CACHE }}
key: ${{ steps.imagetag.outputs.TAG }}
- name: Load Docker images if exist
if: steps.cache.outputs.cache-hit == 'true'
run: |
docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_coverage_1.tar
- name: Pull base images if no-exist
if: steps.cache.outputs.cache-hit != 'true'
run: |
: # Pull images before build for stability
docker pull golang:1.15-alpine
- name: Build Docker images if no-exists
if: steps.cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ steps.imagetag.outputs.PATH_TAR }}
: # Build container images
docker-compose --file ./.github/docker-compose.yml build coverage
- name: Save built images if no-exists
if: steps.cache.outputs.cache-hit != 'true'
run: |
docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_coverage_1.tar github_coverage:latest
- name: Run code coverage
run: docker-compose --file ./.github/docker-compose.yml up --abort-on-container-exit coverage