1+ # It runs unit tests on various versions of Go.
2+ name : go1.17+
3+
4+ on :
5+ workflow_dispatch :
6+ push :
7+ branches : [ main ]
8+ schedule :
9+ # Runs at 19:10 UTC on day-of-month 1 (Every day-of-month 1 at AM 04:10 JST, my time)
10+ # See: https://crontab.guru/
11+ - cron : ' 10 19 1 * *'
12+
13+ env :
14+ PATH_CACHE : /tmp/docker-img-arch
15+
16+ jobs :
17+ go :
18+ name : Run tests on Go via container
19+ runs-on : ubuntu-latest
20+ steps :
21+ - name : Checkout repo
22+ uses : actions/checkout@v2
23+
24+ - name : Create hash for image tagging
25+ id : imagehash
26+ uses : KEINOS/gh-action-hash-for-cache@main
27+ with :
28+ path : |
29+ ./.github/Dockerfile
30+ ./go.mod
31+ variant : $(TZ=UTC-9 date '+%Y%m')
32+
33+ - name : Export cache paths and tags
34+ id : imagetag
35+ run : |
36+ HASH="${{ steps.imagehash.outputs.hash }}"
37+ TAG="${HASH:0:7}:cached"
38+ PATH_TAR=${{ env.PATH_CACHE }}"/tar"
39+ echo "::set-output name=TAG::${TAG}"
40+ echo "::set-output name=PATH_TAR::${PATH_TAR}"
41+
42+ - name : Enable cache/restore image archive
43+ id : cache
44+ uses : actions/cache@v2
45+ with :
46+ path : ${{ env.PATH_CACHE }}
47+ key : ${{ steps.imagehash.outputs.hash }}
48+
49+ - name : Load Docker images if exist
50+ if : steps.cache.outputs.cache-hit == 'true'
51+ run : |
52+ docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_17_1.tar
53+ docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_18_1.tar
54+ docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_latest_1.tar
55+
56+ - name : Pull base images if no-exist
57+ if : steps.cache.outputs.cache-hit != 'true'
58+ run : |
59+ : # Pull images one-by-one for stability
60+ docker pull golang:1.17-alpine
61+ docker pull golang:1.18-alpine
62+ docker pull golang:alpine
63+
64+ - name : Build Docker images if no-exists
65+ if : steps.cache.outputs.cache-hit != 'true'
66+ run : |
67+ mkdir -p ${{ steps.imagetag.outputs.PATH_TAR }}
68+ : # Build container images
69+ docker-compose --file ./.github/docker-compose.yml build
70+
71+ - name : Save built images if no-exists
72+ if : steps.cache.outputs.cache-hit != 'true'
73+ run : |
74+ docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_17_1.tar github_v1_17:latest
75+ docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_18_1.tar github_v1_18:latest
76+ docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_latest_1.tar github_latest:latest
77+
78+ - name : Run tests on Go 1.17
79+ run : docker-compose --file ./.github/docker-compose.yml run v1_17
80+ - name : Run tests on Go 1.18
81+ run : docker-compose --file ./.github/docker-compose.yml run v1_18
82+ - name : Run tests on latest Go
83+ run : docker-compose --file ./.github/docker-compose.yml run latest
0 commit comments