Skip to content

Commit

Permalink
ci: Refactor ACT for more thorough usage
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
FoxxMD committed Sep 27, 2024
1 parent 005dae7 commit 5b8a8a7
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .github/act/.actrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--directory ../../
--env-file .github/act/.env
--secret-file .github/act/.secrets
1 change: 1 addition & 0 deletions .github/act/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NO_DOCKER_BUILD=true
3 changes: 3 additions & 0 deletions .github/act/.secrets.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DOCKER_PASSWORD=
DOCKER_USERNAME=
GITHUB_TOKEN=
15 changes: 14 additions & 1 deletion .github/act/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
Testing GH Actions with [ACT]

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.

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.

Run the following **from this directory** to make use of `.actrc` and proper working directoy.

### Test Branch Push

```shell
act -W '.github/act/actTest.yml' -e '.github/act/actBranchEvent.json'
```


### Test Tag Push
### Test Tag (Release) Push

```shell
act -W '.github/act/actTest.yml' -e '.github/act/actTagEvent.json'
```


### Test Tag (Pre-Release) Push

```shell
act -W '.github/act/actTest.yml' -e '.github/act/actTagPreEvent.json'
```
2 changes: 1 addition & 1 deletion .github/act/actBranchEvent.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ref": "refs/heads/master",
"sha": "e80ad81f051e2ff29e73c0401ad9b89a1b32c3f7"
"sha": "005dae76ab51799d3d55112738e301cb1af0dafd"
}
9 changes: 6 additions & 3 deletions .github/act/actTagEvent.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"ref": "refs/tags/0.8.0",
"ref_name": "0.8.0",
"sha": "0a1a94d9ad4efa373f8d34aace5e7f0a3fff42ad"
"ref": "refs/tags/0.8.4",
"ref_name": "0.8.4",
"before": "0000000000000000000000000000000000000000",
"after": "005dae76ab51799d3d55112738e301cb1af0dafd",
"sha": "005dae76ab51799d3d55112738e301cb1af0dafd",
"base_ref": "refs/heads/master"
}
8 changes: 8 additions & 0 deletions .github/act/actTagPreEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ref": "refs/tags/0.8.5-rc1",
"ref_name": "0.8.5-rc1",
"before": "0000000000000000000000000000000000000000",
"after": "005dae76ab51799d3d55112738e301cb1af0dafd",
"sha": "005dae76ab51799d3d55112738e301cb1af0dafd",
"base_ref": "refs/heads/master"
}
68 changes: 35 additions & 33 deletions .github/act/actTest.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: Publish Docker image to Dockerhub

on:
workflow_dispatch:
push:
branches:
- 'master'
tags:
- '*.*.*'
# don't trigger if just updating docs
paths-ignore:
- '**.md'
- 'README.md'
- '.github/**'
- 'flatpak/**'
# use release instead of tags once version is correctly parsed
# https://github.com/docker/metadata-action/issues/422
# https://github.com/docker/metadata-action/issues/240
Expand All @@ -17,16 +20,10 @@ on:

jobs:

test:
push_to_registry:
name: Build and push container images
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# include:
# - dockerfile: ./Dockerfile
# suffix: ''
# platforms: 'linux/amd64'
steps:
- name: Check out the repo
uses: actions/checkout@v4
Expand All @@ -46,11 +43,6 @@ jobs:
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
echo "COMMIT_BRANCH=$branchName" >> $GITHUB_ENV
# - name: Set push event short ref
# run: |
# shortEventRef=${github.event.push.ref:10}
# echo "SHORT_REF=$shortEventRef" >> $GITHUB_ENV

- name: Check App Version
env:
# use release instead of tags once version is correctly parsed
Expand All @@ -62,26 +54,38 @@ jobs:
run: |
echo $APP_VERSION
# - name: Extract metadata (tags, labels) for Docker
# id: meta
# uses: docker/metadata-action@v5
# with:
# # generate Docker tags based on the following events/attributes
# # https://github.com/docker/metadata-action/issues/247#issuecomment-1511259674 for NOT is default branch, eventually
# tags: |
# type=raw,value=latest,enable={{endsWith(github.ref, 'master')}},suffix=${{ matrix.suffix }}
# type=ref,event=branch,enable=${{ !endsWith(github.ref, 'master') }},suffix=${{ matrix.suffix }}
# type=semver,pattern={{version}},suffix=${{ matrix.suffix }}
# flavor: |
# latest=false
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
# generate Docker tags based on the following events/attributes
# https://github.com/docker/metadata-action/issues/247#issuecomment-1511259674 for NOT is default branch, eventually
tags: |
type=edge
# maybe re-enable branch-named tags in the futures
#type=ref,event=branch,enable=${{ !endsWith(github.ref, 'master') }}
# tag non-prelease as latest -- has a higher priority than regular tag so it shows first in registries
type=match,pattern=\d.\d.\d$,priority=901
# tag all semver (include pre-release)
type=semver,pattern={{version}}
# flavor: |
# latest=false

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
id: qemu
if: ${{ !env.NO_DOCKER_BUILD }}

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

- name: Build and push Docker image
if: ${{ steps.qemu.outcome == 'success' }}
env:
# use release instead of tags once version is correctly parsed
#APP_VERSION: ${{ github.event.release.tag_name }}
Expand All @@ -95,9 +99,7 @@ jobs:
# https://github.com/docker/build-push-action/issues/1026#issue-2041857786
build-args: |
APP_BUILD_VERSION=${{env.APP_VERSION}}
file: ${{ matrix.dockerfile }}
push: false
tags: mstest:latest
#tags: ${{ steps.meta.outputs.tags }}
#labels: ${{ steps.meta.outputs.labels }}
#platforms: ${{ matrix.platforms }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
26 changes: 8 additions & 18 deletions .github/workflows/publishImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ jobs:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: test
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./Dockerfile
suffix: ''
platforms: 'linux/amd64,linux/arm64'
# - dockerfile: ./alpine.Dockerfile
# suffix: '-alpine'
# platforms: 'linux/amd64,linux/arm64'
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
packages: write
Expand Down Expand Up @@ -95,16 +85,17 @@ jobs:
# https://github.com/docker/metadata-action/issues/247#issuecomment-1511259674 for NOT is default branch, eventually
tags: |
type=edge
type=ref,event=branch,enable=${{ !endsWith(github.ref, 'master') }}
# maybe re-enable branch-named tags in the futures
#type=ref,event=branch,enable=${{ !endsWith(github.ref, 'master') }}
# tag non-prelease as latest -- has a higher priority than regular tag so it shows first in registries
type=semver,pattern={{major}}.{{minor}}.{{patch}},value=latest,priority=901
type=match,pattern=\d.\d.\d$,priority=901
# tag all semver (include pre-release)
type=semver,pattern={{version}}
flavor: |
latest=false
# suffix=${{ matrix.suffix }},onlatest=false
# flavor: |
# latest=false

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -126,8 +117,7 @@ jobs:
# https://github.com/docker/build-push-action/issues/1026#issue-2041857786
build-args: |
APP_BUILD_VERSION=${{env.APP_VERSION}}
file: ${{ matrix.dockerfile }}
push: ${{ !env.ACT}}
push: ${{ !env.ACT }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.platforms }}
platforms: linux/amd64,linux/arm64

0 comments on commit 5b8a8a7

Please sign in to comment.