-
Notifications
You must be signed in to change notification settings - Fork 4
134 lines (117 loc) · 3.76 KB
/
main.yaml
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
name: Main
on: [push, pull_request]
jobs:
build:
name: Build
runs-on: "ubuntu-latest"
permissions:
id-token: write
packages: write
contents: write
attestations: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
check-latest: true
- name: Print Go Version
run: go version
- name: Compute Version
id: version
run: |
echo ${GITHUB_REF}
tag=${GITHUB_REF#refs/tags/}
publish="no"
release="no"
if [ "${tag}" != "${GITHUB_REF}" ]; then
tag=$(echo "${tag}" | sed -e 's/[^a-zA-Z0-9\-\.]/-/g')
version=${tag}
publish="yes"
release="yes"
fi
branch=${GITHUB_REF#refs/heads/}
if [[ -z "${version}" && "${branch}" != "${GITHUB_REF}" ]]; then
branch=$(echo "${branch}" | sed -e 's/[^a-zA-Z0-9\-\.]/-/g')
version=${branch}
if [[ ${branch} = "master" || "${branch}" = "develop" ]]; then
publish="yes"
fi
fi
pr=${GITHUB_REF#refs/pull/}
if [[ -z "${version}" && "${pr}" != "${GITHUB_REF}" ]]; then
pr=$(echo "${pr}" | sed -e 's/[^a-zA-Z0-9\-\.]/-/g')
version=${pr}
fi
if [ -z "${version}" ]; then
echo "Version could not be determined" >&2
exit 1
else
echo CI_VERSION=${version} >> $GITHUB_ENV
echo PUBLISH=${publish} >> $GITHUB_ENV
echo RELEASE=${release} >> $GITHUB_ENV
fi
- name: Test
run: |
make test
- name: Build
run: |
if [[ ${PUBLISH} = "yes" ]]; then
make release
else
make
fi
- uses: actions/attest-build-provenance@v2
if: ${{ env.PUBLISH == 'yes' }}
with:
subject-path: 'release/**/dockcmd*'
- name: Release Artifacts
if: ${{ env.RELEASE == 'yes' }}
run: |
gh release create ${CI_VERSION} --draft --verify-tag --title "Release ${CI_VERSION}"
gh release upload ${CI_VERSION} ./release/*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
if: ${{ env.PUBLISH == 'yes' }}
uses: docker/setup-qemu-action@v3
- name: Set up Buildx
if: ${{ env.PUBLISH == 'yes' }}
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Login to Docker HUB
if: ${{ env.PUBLISH == 'yes' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
if: ${{ env.PUBLISH == 'yes' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
if: ${{ env.PUBLISH == 'yes' }}
id: push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
build-args: |
VERSION=${{ env.CI_VERSION }}
tags: |
boxboat/dockcmd:${{ env.CI_VERSION }}
ghcr.io/boxboat/dockcmd:${{ env.CI_VERSION }}
- name: Attest ghcr image
if: ${{ env.PUBLISH == 'yes' }}
uses: actions/attest-build-provenance@v2
with:
subject-name: ghcr.io/boxboat/dockcmd
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true