-
Notifications
You must be signed in to change notification settings - Fork 3
106 lines (91 loc) · 3.54 KB
/
ci.yaml
File metadata and controls
106 lines (91 loc) · 3.54 KB
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
name: ci
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
types: [opened, reopened, synchronize]
workflow_dispatch:
permissions:
contents: read
id-token: write
env:
IMAGE_NAME: d2k
jobs:
tag:
runs-on: ubuntu-latest
outputs:
value: ${{ steps.resolve.outputs.value }}
steps:
- name: "[preparation] resolve image tag"
id: resolve
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "value=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
else
echo "value=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
build:
runs-on: ubuntu-latest
needs: tag
steps:
- name: "[preparation] checkout the current branch"
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: "[preparation] set up golang"
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
- name: "[preparation] verify go mod tidy"
run: |
go mod tidy
if ! git diff --exit-code go.mod go.sum > /dev/null 2>&1; then
echo "::warning::go.mod or go.sum is out of date — please run 'go mod tidy' locally and commit the changes"
fi
- name: "[preparation] set up QEMU"
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
- name: "[preparation] set up Docker Buildx"
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: "[execution] build multi-arch image and export as OCI tarball"
if: github.event_name == 'pull_request'
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
with:
push: false
load: false
platforms: linux/amd64,linux/arm64
build-args: VERSION=${{ github.sha }}
tags: ${{ env.IMAGE_NAME }}:${{ needs.tag.outputs.value }}
outputs: type=oci,dest=/tmp/image.tar
- name: "[execution] save image tag metadata"
if: github.event_name == 'pull_request'
run: |
echo "${{ needs.tag.outputs.value }}" > /tmp/image-tag.txt
- name: "[execution] upload image artifact"
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pr-image
path: /tmp/image.tar
retention-days: 1
- name: "[execution] upload image tag artifact"
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pr-image-tag
path: /tmp/image-tag.txt
retention-days: 1
- name: "[preparation] log in to registry"
if: github.event_name != 'pull_request'
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: "[execution] build and push multi-arch image"
if: github.event_name != 'pull_request'
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
with:
push: true
platforms: linux/amd64,linux/arm64
build-args: VERSION=${{ github.sha }}
tags: portainerci/${{ env.IMAGE_NAME }}:${{ needs.tag.outputs.value }}
sbom: true
provenance: mode=max