Skip to content

Commit 5b8a8a7

Browse files
committed
ci: Refactor ACT for more thorough usage
* All required files in the same file by using .actrc * Include example .secrets and .env * Update README with usage * Refactor actTest to make docker build steps optional with ENV
1 parent 005dae7 commit 5b8a8a7

9 files changed

+79
-56
lines changed

.github/act/.actrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--directory ../../
2+
--env-file .github/act/.env
3+
--secret-file .github/act/.secrets

.github/act/.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NO_DOCKER_BUILD=true

.github/act/.secrets.example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DOCKER_PASSWORD=
2+
DOCKER_USERNAME=
3+
GITHUB_TOKEN=

.github/act/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
Testing GH Actions with [ACT]
22

3+
Need to have credentials in a [`.secrets` file](https://nektosact.com/usage/index.html#secrets), copy and rename [`.secrets.example`](./secrets.example) to `.secrets`, then fill out blank fields. Required for docker/metadata-action to read...something. Fails with `Parameter token or opts.auth is required` if they are not supplied.
4+
5+
An ENV file can also be made by copy and renaming [`.env.example`](./env.example). Set `NO_DOCKER_BUILD=true` if you only want to test APP_VERSION and docker tags output.
6+
7+
Run the following **from this directory** to make use of `.actrc` and proper working directoy.
8+
39
### Test Branch Push
410

511
```shell
612
act -W '.github/act/actTest.yml' -e '.github/act/actBranchEvent.json'
713
```
814

915

10-
### Test Tag Push
16+
### Test Tag (Release) Push
1117

1218
```shell
1319
act -W '.github/act/actTest.yml' -e '.github/act/actTagEvent.json'
1420
```
21+
22+
23+
### Test Tag (Pre-Release) Push
24+
25+
```shell
26+
act -W '.github/act/actTest.yml' -e '.github/act/actTagPreEvent.json'
27+
```

.github/act/actBranchEvent.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"ref": "refs/heads/master",
3-
"sha": "e80ad81f051e2ff29e73c0401ad9b89a1b32c3f7"
3+
"sha": "005dae76ab51799d3d55112738e301cb1af0dafd"
44
}

.github/act/actTagEvent.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2-
"ref": "refs/tags/0.8.0",
3-
"ref_name": "0.8.0",
4-
"sha": "0a1a94d9ad4efa373f8d34aace5e7f0a3fff42ad"
2+
"ref": "refs/tags/0.8.4",
3+
"ref_name": "0.8.4",
4+
"before": "0000000000000000000000000000000000000000",
5+
"after": "005dae76ab51799d3d55112738e301cb1af0dafd",
6+
"sha": "005dae76ab51799d3d55112738e301cb1af0dafd",
7+
"base_ref": "refs/heads/master"
58
}

.github/act/actTagPreEvent.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"ref": "refs/tags/0.8.5-rc1",
3+
"ref_name": "0.8.5-rc1",
4+
"before": "0000000000000000000000000000000000000000",
5+
"after": "005dae76ab51799d3d55112738e301cb1af0dafd",
6+
"sha": "005dae76ab51799d3d55112738e301cb1af0dafd",
7+
"base_ref": "refs/heads/master"
8+
}

.github/act/actTest.yml

+35-33
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
name: Publish Docker image to Dockerhub
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- 'master'
78
tags:
89
- '*.*.*'
910
# don't trigger if just updating docs
1011
paths-ignore:
11-
- '**.md'
12+
- 'README.md'
13+
- '.github/**'
14+
- 'flatpak/**'
1215
# use release instead of tags once version is correctly parsed
1316
# https://github.com/docker/metadata-action/issues/422
1417
# https://github.com/docker/metadata-action/issues/240
@@ -17,16 +20,10 @@ on:
1720

1821
jobs:
1922

20-
test:
23+
push_to_registry:
2124
name: Build and push container images
25+
if: github.event_name != 'pull_request'
2226
runs-on: ubuntu-latest
23-
# strategy:
24-
# fail-fast: false
25-
# matrix:
26-
# include:
27-
# - dockerfile: ./Dockerfile
28-
# suffix: ''
29-
# platforms: 'linux/amd64'
3027
steps:
3128
- name: Check out the repo
3229
uses: actions/checkout@v4
@@ -46,11 +43,6 @@ jobs:
4643
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
4744
echo "COMMIT_BRANCH=$branchName" >> $GITHUB_ENV
4845
49-
# - name: Set push event short ref
50-
# run: |
51-
# shortEventRef=${github.event.push.ref:10}
52-
# echo "SHORT_REF=$shortEventRef" >> $GITHUB_ENV
53-
5446
- name: Check App Version
5547
env:
5648
# use release instead of tags once version is correctly parsed
@@ -62,26 +54,38 @@ jobs:
6254
run: |
6355
echo $APP_VERSION
6456
65-
# - name: Extract metadata (tags, labels) for Docker
66-
# id: meta
67-
# uses: docker/metadata-action@v5
68-
# with:
69-
# # generate Docker tags based on the following events/attributes
70-
# # https://github.com/docker/metadata-action/issues/247#issuecomment-1511259674 for NOT is default branch, eventually
71-
# tags: |
72-
# type=raw,value=latest,enable={{endsWith(github.ref, 'master')}},suffix=${{ matrix.suffix }}
73-
# type=ref,event=branch,enable=${{ !endsWith(github.ref, 'master') }},suffix=${{ matrix.suffix }}
74-
# type=semver,pattern={{version}},suffix=${{ matrix.suffix }}
75-
# flavor: |
76-
# latest=false
57+
- name: Extract metadata (tags, labels) for Docker
58+
id: meta
59+
uses: docker/metadata-action@v5
60+
with:
61+
# generate Docker tags based on the following events/attributes
62+
# https://github.com/docker/metadata-action/issues/247#issuecomment-1511259674 for NOT is default branch, eventually
63+
tags: |
64+
type=edge
65+
66+
# maybe re-enable branch-named tags in the futures
67+
#type=ref,event=branch,enable=${{ !endsWith(github.ref, 'master') }}
68+
69+
# tag non-prelease as latest -- has a higher priority than regular tag so it shows first in registries
70+
type=match,pattern=\d.\d.\d$,priority=901
71+
72+
# tag all semver (include pre-release)
73+
type=semver,pattern={{version}}
74+
# flavor: |
75+
# latest=false
7776

7877
- name: Set up QEMU
7978
uses: docker/setup-qemu-action@v3
79+
id: qemu
80+
if: ${{ !env.NO_DOCKER_BUILD }}
8081

81-
# - name: Set up Docker Buildx
82-
# uses: docker/setup-buildx-action@v3
82+
- name: Set up Docker Buildx
83+
uses: docker/setup-buildx-action@v3
84+
if: ${{ steps.qemu.outcome == 'success' }}
85+
continue-on-error: true
8386

8487
- name: Build and push Docker image
88+
if: ${{ steps.qemu.outcome == 'success' }}
8589
env:
8690
# use release instead of tags once version is correctly parsed
8791
#APP_VERSION: ${{ github.event.release.tag_name }}
@@ -95,9 +99,7 @@ jobs:
9599
# https://github.com/docker/build-push-action/issues/1026#issue-2041857786
96100
build-args: |
97101
APP_BUILD_VERSION=${{env.APP_VERSION}}
98-
file: ${{ matrix.dockerfile }}
99102
push: false
100-
tags: mstest:latest
101-
#tags: ${{ steps.meta.outputs.tags }}
102-
#labels: ${{ steps.meta.outputs.labels }}
103-
#platforms: ${{ matrix.platforms }}
103+
tags: ${{ steps.meta.outputs.tags }}
104+
labels: ${{ steps.meta.outputs.labels }}
105+
platforms: linux/amd64,linux/arm64

.github/workflows/publishImage.yml

+8-18
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ jobs:
4343
if: github.event_name != 'pull_request'
4444
runs-on: ubuntu-latest
4545
needs: test
46-
strategy:
47-
fail-fast: false
48-
matrix:
49-
include:
50-
- dockerfile: ./Dockerfile
51-
suffix: ''
52-
platforms: 'linux/amd64,linux/arm64'
53-
# - dockerfile: ./alpine.Dockerfile
54-
# suffix: '-alpine'
55-
# platforms: 'linux/amd64,linux/arm64'
5646
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
5747
permissions:
5848
packages: write
@@ -95,16 +85,17 @@ jobs:
9585
# https://github.com/docker/metadata-action/issues/247#issuecomment-1511259674 for NOT is default branch, eventually
9686
tags: |
9787
type=edge
98-
type=ref,event=branch,enable=${{ !endsWith(github.ref, 'master') }}
88+
89+
# maybe re-enable branch-named tags in the futures
90+
#type=ref,event=branch,enable=${{ !endsWith(github.ref, 'master') }}
9991
10092
# tag non-prelease as latest -- has a higher priority than regular tag so it shows first in registries
101-
type=semver,pattern={{major}}.{{minor}}.{{patch}},value=latest,priority=901
93+
type=match,pattern=\d.\d.\d$,priority=901
10294
10395
# tag all semver (include pre-release)
10496
type=semver,pattern={{version}}
105-
flavor: |
106-
latest=false
107-
# suffix=${{ matrix.suffix }},onlatest=false
97+
# flavor: |
98+
# latest=false
10899

109100
- name: Set up QEMU
110101
uses: docker/setup-qemu-action@v3
@@ -126,8 +117,7 @@ jobs:
126117
# https://github.com/docker/build-push-action/issues/1026#issue-2041857786
127118
build-args: |
128119
APP_BUILD_VERSION=${{env.APP_VERSION}}
129-
file: ${{ matrix.dockerfile }}
130-
push: ${{ !env.ACT}}
120+
push: ${{ !env.ACT }}
131121
tags: ${{ steps.meta.outputs.tags }}
132122
labels: ${{ steps.meta.outputs.labels }}
133-
platforms: ${{ matrix.platforms }}
123+
platforms: linux/amd64,linux/arm64

0 commit comments

Comments
 (0)