-
Notifications
You must be signed in to change notification settings - Fork 1
221 lines (192 loc) · 7.23 KB
/
testing-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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
name: Release
run-name: "Testing release workflow"
env:
APPLICATION: "test-app"
GOLANG_BUILDER_VERSION: "1.22-bookworm"
TARGET_BASE_VERSION: "bookworm-20240722"
PACKAGE_NAME: "github.com/erigontech/erigon"
DOCKERHUB_REPOSITORY: "erigontech/dev-erigon"
BUILD_TAGS: "nosqlite,noboltdb,nosilkworm"
VERSION: "2.65.4"
VERSION_TMP: ".."
on:
push:
#branches-ignore:
# - '**'
#branches:
# - 'master'
#tags:
## only trigger on release tags:
#- 'v*.*.*'
#- 'v*.*.*-*'
workflow_dispatch:
inputs:
checkout_ref:
required: true
type: string
default: 'main'
description: 'The branch, tag or SHA to checkout and build artifacts from'
release_version:
required: false
type: string
description: 'Release version number (v#.#.#)'
perform_release:
required: true
type: boolean
default: false
description: 'perform_release: when set then all artifacts will be published and the release
notes will be created. Otherwise build will be done and draft of the release notes will be created.'
jobs:
build:
runs-on: ubuntu-latest
name: Build ${{ matrix.arch }}
strategy:
matrix:
include:
- arch: linux/amd64/v2
id: linux-amd64-v2
goos: linux
goarch: amd64
flags_cc: x86_64-linux-gnu-gcc
flags_cxx: x86_64-linux-gnu-g++
build_dst: src
- arch: linux/arm64
id: linux-arm64
goos: linux
goarch: arm64
flags_cc: aarch64-linux-gnu-gcc
flags_cxx: aarch64-linux-gnu-g++
build_dst: src
steps:
- name: Checkout github repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ inputs.checkout_ref }}
- name: Check if tag ${{ inputs.release_version }} already exists. Exit pipeline if tag already exist.
run: |
if [ $( git ls-remote --exit-code --tags origin '${{ inputs.release_version }}' ) ]; then
echo "FAILURE: Tag ${{ inputs.release_version}} already exists!" ; exit 1
fi
- name: Debug content of current dir
run: |
pwd
ls -lao
set
- name: Get short commit id
id: GetShortCommitId
run: echo "short_commit_id=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_USERNAME }}
password: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build binary for the platform ${{ matrix.arch }}
run: |
docker run --rm --platform ${{ matrix.arch }} \
-e GOOS=${{ matrix.goos }} -e GOARCH=${{ matrix.goarch }} \
-w /app1/src \
-v $(pwd):/app1 \
golang:${{ env.GOLANG_BUILDER_VERSION }} \
/bin/bash -c "git config --global --add safe.directory . ; go build main.go; ls -lao"
- name: Build ${{ inputs.perform_release && 'and push' || 'without pushing' }} a docker image for ${{ matrix.arch }} platform
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: ${{ matrix.arch }}
build-args: |
BUILD_DST=${{ matrix.build_dst }}
GOLANG_BUILDER_VERSION=${{ env.GOLANG_BUILDER_VERSION }}
TARGET_BASE_VERSION=${{ env.TARGET_BASE_VERSION }}
BUILD_TAGS=${{ env.BUILD_TAGS }}
BUILD_TIMESTAMP=${{ steps.current_ts.outputs.date }}
VCS_REF_SHORT=${{ steps.GetShortCommitId.outputs.short_commit_id }}
VCS_REF_LONG=${{ github.sha }}
VERSION=${{ steps.GetVersion.outputs.ver }}
## push when perform_release==true only:
outputs: type=image,name=${{ env.DOCKERHUB_REPOSITORY }},push-by-digest=true,name-canonical=true,${{ inputs.perform_release && 'push=true' || 'push=false' }}
- name: Compress Artifact for the platform ${{ matrix.arch }}
run: |
tar czvf ./${{ env.APPLICATION}}-${{ matrix.id }}.tar.gz src/main
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.sha }}_${{ env.APPLICATION}}-${{ matrix.id }}.tar.gz
path: ./${{ env.APPLICATION}}-${{ matrix.id }}.tar.gz
retention-days: 1
compression-level: 0
if-no-files-found: error
- name: Debug 2
run: |
pwd
find . -ls
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.docker_build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.id }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
publish-artifacts:
needs: [ build ]
runs-on: ubuntu-latest
name: Publish artifacts
steps:
- name: Get short commit id
id: GetShortCommitId
run: echo "short_commit_id=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
- name: Download tar.gz artifacts
uses: actions/download-artifact@v4
with:
path: .
pattern: "${{ github.sha }}_*"
merge-multiple: true
- name: Download docker digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get version from Github tag
id: GetVersion
run: echo ver=$( echo ${{ github.ref_name }} | sed -e 's,.*\/,,g' ) >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKERHUB_REPOSITORY }}
tags: |
type=sha,enable=true,priority=100,prefix=sha-,suffix=,format=short
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_USERNAME }}
password: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_TOKEN }}
- name: Create manifest list and push ${{ inputs.perform_release && 'when perform_release is true' || '' }}
working-directory: /tmp/digests
if: ${{ inputs.perform_release }}
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.DOCKERHUB_REPOSITORY }}@sha256:%s ' *)
- name: Publish Release ${{ inputs.perform_release || 'draft' }}
if: ${{ inputs.release_version }}
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: gh release edit "${{ inputs.release_version }}" --draft=false --title "Release ${{ inputs.release_version }}"
- name: Debug output
run: |
find . -ls