-
Notifications
You must be signed in to change notification settings - Fork 363
224 lines (192 loc) · 6.52 KB
/
Copy pathrelease.yml
File metadata and controls
224 lines (192 loc) · 6.52 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
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
222
223
224
name: Release
on:
push:
tags:
- 'v*' # Trigger on tags starting with v, e.g., v1.0.0, v1.0.0-rc.1
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
build-binaries:
name: Build Binaries
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Build WebUI
working-directory: ./webui
run: |
npm ci
npm run build
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.25.x'
- name: Build Go Binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
VERSION=${GITHUB_REF_NAME}
GIT_COMMIT=${GITHUB_SHA::8}
BUILD_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
OUTPUT_NAME=resin-${GOOS}-${GOARCH}
if [ "$GOOS" = "windows" ]; then
OUTPUT_NAME="${OUTPUT_NAME}.exe"
fi
echo "OUTPUT_NAME=${OUTPUT_NAME}" >> $GITHUB_ENV
mkdir -p build
go build -trimpath -tags "with_quic with_wireguard with_grpc with_utls with_embedded_tor with_naive_outbound" \
-ldflags="-s -w \
-X github.com/Resinat/Resin/internal/buildinfo.Version=${VERSION} \
-X github.com/Resinat/Resin/internal/buildinfo.GitCommit=${GIT_COMMIT} \
-X github.com/Resinat/Resin/internal/buildinfo.BuildTime=${BUILD_TIME}" \
-o build/${OUTPUT_NAME} ./cmd/resin
cd build
# Create a copy with the simple name for the archive
SIMPLE_NAME="resin"
if [ "$GOOS" = "windows" ]; then
SIMPLE_NAME="resin.exe"
fi
cp ${OUTPUT_NAME} ${SIMPLE_NAME}
if [ "$GOOS" = "windows" ]; then
zip resin-${GOOS}-${GOARCH}.zip ${SIMPLE_NAME}
PACKAGE_NAME="resin-${GOOS}-${GOARCH}.zip"
else
tar -czvf resin-${GOOS}-${GOARCH}.tar.gz ${SIMPLE_NAME}
PACKAGE_NAME="resin-${GOOS}-${GOARCH}.tar.gz"
fi
# Remove simple name copy to avoid confusion
rm ${SIMPLE_NAME}
echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV
- name: Upload Release Package Artifact
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.goos }}-${{ matrix.goarch }}
path: build/${{ env.PACKAGE_NAME }}
retention-days: 1
- name: Upload Linux bin for Docker
if: matrix.goos == 'linux'
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.goos }}-${{ matrix.goarch }}
path: build/${{ env.OUTPUT_NAME }}
retention-days: 1
publish-release:
name: Publish Release
runs-on: ubuntu-latest
needs: build-binaries
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Find Release Note
id: release_note
env:
RELEASE_NOTE_PATH: doc/release-notes/${{ github.ref_name }}.md
run: |
if [[ -f "$RELEASE_NOTE_PATH" ]]; then
echo "path=$RELEASE_NOTE_PATH" >> "$GITHUB_OUTPUT"
fi
- name: Download Release Package Artifacts
uses: actions/download-artifact@v4
with:
pattern: release-*
path: build
merge-multiple: true
- name: Check if Pre-release
id: check_prerelease
run: |
if [[ "${GITHUB_REF_NAME}" == *"-"* ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Publish Release Assets
uses: softprops/action-gh-release@v2
with:
files: build/*
fail_on_unmatched_files: true
overwrite_files: true
body_path: ${{ steps.release_note.outputs.path }}
generate_release_notes: true
prerelease: ${{ steps.check_prerelease.outputs.is_prerelease == 'true' }}
docker:
name: Build & Push Docker Image
runs-on: ubuntu-latest
needs: build-binaries
permissions:
contents: read
packages: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Download Linux amd64 binary
uses: actions/download-artifact@v4
with:
name: binary-linux-amd64
path: release-bin/linux/amd64/
- name: Download Linux arm64 binary
uses: actions/download-artifact@v4
with:
name: binary-linux-arm64
path: release-bin/linux/arm64/
- name: Give binaries execute permission
run: chmod +x release-bin/linux/amd64/resin-linux-amd64 release-bin/linux/arm64/resin-linux-arm64
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Check if Pre-release
id: check_prerelease
run: |
if [[ "${GITHUB_REF_NAME}" == *"-"* ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ steps.check_prerelease.outputs.is_prerelease == 'false' }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./.github/Dockerfile.release
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}