-
Notifications
You must be signed in to change notification settings - Fork 12
159 lines (137 loc) · 5.74 KB
/
container.yml
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Build container image
on:
push:
branches: [ main, devel ]
tags: [ v*.*.* ]
pull_request:
types: [ assigned, opened, synchronize, reopened ]
schedule:
- cron: "0 13 * * 1"
workflow_dispatch:
env:
# build for multiple platforms when not a pull-request
PLATFORMS: ${{ fromJSON('[ "linux/amd64", "linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/ppc64le" ]')[ github.event_name != 'pull_request' ] }}
# how to name the image
IMAGENAME: speedtest
TESTIMAGE: "${{ github.repository_owner }}/speedtest:testing"
# dockerhub credentials
DOCKERHUB_USER: ansemjo
#DOCKERHUB_TOKEN - add as secret value
jobs:
container:
name: build image 📦
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare Tags
id: prep
shell: bash
run: |
TAGS=()
case "${GITHUB_REF}" in
# version releases
refs/tags/*)
VERSION="${GITHUB_REF#refs/tags/}"
if [[ ${VERSION} =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
V=("${BASH_REMATCH[@]}")
TAGS+=("${{ env.IMAGENAME }}:${V[1]}" \
"${{ env.IMAGENAME }}:${V[1]}.${V[2]}" \
"${{ env.IMAGENAME }}:${V[1]}.${V[2]}.${V[3]}")
else
TAGS+=("${{ env.IMAGENAME }}:${VERSION}")
fi
;&
# branch heads (+ fallthorugh)
refs/heads/*)
TAGS+=("${{ env.IMAGENAME }}:latest")
TAGS=$({ IFS=","; echo "${TAGS[*]/#/${{ env.DOCKERHUB_USER }}/}","${TAGS[*]/#/ghcr.io/${{ github.repository_owner }}/}"; })
;;
# pull requests
refs/pull/*)
TAGS=("${{ github.repository_owner }}/${{ env.IMAGENAME }}:pr-${{ github.event.number }}")
;;
esac
echo "TAGS ${TAGS}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "head=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Login to Docker Hub
uses: docker/[email protected]
if: ${{ github.event_name != 'pull_request' && steps.prep.outputs.head != 'devel' }}
with:
username: ${{ env.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/[email protected]
if: ${{ github.event_name != 'pull_request' && steps.prep.outputs.head != 'devel' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and export to Docker
uses: docker/[email protected]
with:
context: .
file: ./container/Dockerfile
push: false
load: true
tags: ${{ env.TESTIMAGE }}
- name: Run a test measurement in built image
run: |
docker run --rm ${{ env.TESTIMAGE }} measure
- name: Build and push
uses: docker/[email protected]
if: ${{ github.event_name != 'pull_request' && steps.prep.outputs.head != 'devel' }}
with:
context: .
file: ./container/Dockerfile
platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
dependabot:
# https://nicolasiensen.github.io/2022-07-23-automating-dependency-updates-with-dependabot-github-auto-merge-and-github-actions/
name: merge dependabot pr 🏗️
needs: [ container ]
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' }}
permissions:
pull-requests: write
contents: write
steps:
- name: Get Dependabot metadata
id: dependabot-metadata
uses: dependabot/[email protected]
- name: Enable auto-merge for PR
run: |
gh pr merge --auto --rebase "$PR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ github.event.pull_request.html_url }}
- name: Approve patch and minor updates
if: ${{ steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' || steps.dependabot-metadata.outputs.update-type == 'version-update:semver-minor' }}
run: |
gh pr review "$PR" --approve --body "Automatically **approving** this pull request because it includes a **patch or minor** update."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ github.event.pull_request.html_url }}
- name: Comment on major updates
if: ${{ steps.dependabot-metadata.outputs.update-type == 'version-update:semver-major' }}
run: |
gh pr comment "$PR" --body "Requires manual approval due to **major update**."
gh pr edit "$PR" --add-label "dependabot-major"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ github.event.pull_request.html_url }}