-
Notifications
You must be signed in to change notification settings - Fork 9
146 lines (125 loc) · 4.44 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
name: Release
on:
- push
- pull_request
env:
DOCKERHUB_USERNAME: druggeri
jobs:
test:
name: Test
strategy:
matrix:
go-version:
- '1.23.x'
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Checkout code
uses: actions/checkout@v4
- name: Test
run: go test ./...
release:
needs: test
name: Build and release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: build --clean --parallelism=2 --timeout=1h --skip=validate
- name: Publish release
uses: goreleaser/goreleaser-action@v4
if: startsWith(github.ref, 'refs/tags/v')
with:
distribution: goreleaser
version: latest
args: release --clean --parallelism=2 --timeout=1h --release-notes=.release_info.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
containers:
if: startsWith(github.ref, 'refs/tags/v')
needs: release
name: Push containers
runs-on: ubuntu-latest
steps:
- name: Prep variables
run: |
set -u
export PROJECT_NAME=${GITHUB_REPOSITORY##*/}
export TAG=${GITHUB_REF##*/}
echo "PROJECT_NAME=$PROJECT_NAME" >> $GITHUB_ENV
echo "TAG=$TAG" >> $GITHUB_ENV
echo "URL_LINUX_AMD64=https://github.com/${GITHUB_REPOSITORY}/releases/download/$TAG/${PROJECT_NAME}-${TAG}-linux-amd64" >> $GITHUB_ENV
echo "URL_LINUX_ARM64=https://github.com/${GITHUB_REPOSITORY}/releases/download/$TAG/${PROJECT_NAME}-${TAG}-linux-arm64" >> $GITHUB_ENV
echo "URL_LINUX_ARM=https://github.com/${GITHUB_REPOSITORY}/releases/download/$TAG/${PROJECT_NAME}-${TAG}-linux-arm" >> $GITHUB_ENV
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout code
uses: actions/checkout@v2
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.DOCKERHUB_USERNAME }}/${{ env.PROJECT_NAME }}
ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Create scratch docker image
run: |
echo "
FROM alpine AS builder
RUN apk --no-cache add wget ca-certificates \
&& if uname -m | grep 'x86_64' >/dev/null 2>&1; then wget -O /downloaded_file $URL_LINUX_AMD64;fi \
&& if uname -m | grep 'aarch64' >/dev/null 2>&1; then wget -O /downloaded_file $URL_LINUX_ARM64;fi \
&& if uname -m | grep 'arm' >/dev/null 2>&1; then wget -O /downloaded_file $URL_LINUX_ARM;fi \
&& if [ ! -f /downloaded_file ];then echo "===Failed to download for:";uname -m;echo "===";exit 1;fi \
&& chmod 755 /downloaded_file
FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /downloaded_file /$PROJECT_NAME
ENTRYPOINT [\"/$PROJECT_NAME\"]
" > Dockerfile
echo "Rendered Dockerfile in $PWD:"
cat Dockerfile
- name: Build and push Docker images
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}