-
Notifications
You must be signed in to change notification settings - Fork 39
150 lines (123 loc) · 4.84 KB
/
release.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
---
name: "Release"
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
jobs:
goreleaser:
name: "Build and release packages"
runs-on: ubuntu-latest
permissions:
id-token: write # For cosign
packages: write # For GHCR
contents: read # Not required for public repositories, but for clarity
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
- name: Install Cosign
uses: sigstore/cosign-installer@v3.6.0
- name: Import GPG key
id: gpg
run: |
echo "${GPG_PRIVATE_KEY}" | gpg --import --passphrase "${GPG_PASSPHRASE}" --batch --allow-secret-key-import
GPG_KEY_FILE=/tmp/signing-key.gpg
echo "${GPG_PRIVATE_KEY}" > "${GPG_KEY_FILE}"
echo "GPG_KEY_FILE=${GPG_KEY_FILE}" >> "${GITHUB_ENV}"
env:
GPG_TTY: /dev/ttys000 # Set the GPG_TTY to avoid issues with pinentry
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
- name: Setup snapcraft
run: |
sudo snap install snapcraft --classic --channel=7.x/stable
# See https://github.com/goreleaser/goreleaser/issues/1715
mkdir -p "$HOME/.cache/snapcraft/download"
mkdir -p "$HOME/.cache/snapcraft/stage-packages"
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_TOKEN }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean -f ${{ vars.GORELEASER_CONFIG_PATH }}
env:
AUR_KEY: ${{ secrets.AUR_KEY }}
GITHUB_TOKEN: ${{ secrets.TENV_GITHUB_TOKEN }}
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_TOKEN }}
GPG_KEY_FILE: ${{ steps.gpg.outputs.GPG_KEY_FILE }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push docker image to GitHub Container Registry
env:
docker_registry: "ghcr.io"
run: |
version=${GITHUB_REF#refs/*/v}
IFS='.' read -ra version_arr <<< "${version}"
architectures=("amd64" "arm64" "arm" "386")
versions=("latest" "${version_arr[0]}.${version_arr[1]}" "${version}")
for version in "${versions[@]}"; do
manifest="${docker_registry}/tofuutils/tenv:${version}"
images=""
for arch in "${architectures[@]}"; do
image="${docker_registry}/tofuutils/tenv:${version}-${arch}"
echo "Pushing image ${image} ..."
docker push ${image}
if [ ${?} -ne 0 ]; then
echo "Failed to push image ${image}"
exit 1
fi
images="${image} ${images}"
done
docker manifest create "${manifest}" ${images}
docker manifest push "${manifest}"
done
echo "All images and manifests pushed successfully to ${docker_registry}!"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: registry.hub.docker.com
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Push docker image to DockerHub
env:
docker_registry: "registry.hub.docker.com"
run: |
version=${GITHUB_REF#refs/*/v}
IFS='.' read -ra version_arr <<< "${version}"
architectures=("amd64" "arm64" "arm" "386")
versions=("latest" "${version_arr[0]}.${version_arr[1]}" "${version}")
for version in "${versions[@]}"; do
manifest="${docker_registry}/tofuutils/tenv:${version}"
images=""
for arch in "${architectures[@]}"; do
image="${docker_registry}/tofuutils/tenv:${version}-${arch}"
echo "Pushing image ${image} ..."
docker push ${image}
if [ ${?} -ne 0 ]; then
echo "Failed to push image ${image}"
exit 1
fi
images="${image} ${images}"
done
docker manifest create "${manifest}" ${images}
docker manifest push "${manifest}"
done
echo "All images and manifests pushed successfully to ${docker_registry}!"