-
Notifications
You must be signed in to change notification settings - Fork 1.3k
217 lines (191 loc) · 7.26 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
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
name: Release
on:
push:
tags:
- "v*"
branches:
- dev
jobs:
build:
strategy:
fail-fast: true
matrix:
goos: [linux, windows]
goarch: [amd64]
include:
- goos: linux
goarch: s390x
- goos: linux
goarch: arm64
name: Build artifacts
runs-on: ubuntu-latest
container:
image: goreleaser/goreleaser-cross:v1.23
steps:
- run: git config --global --add safe.directory /__w/nezha/nezha
- uses: actions/checkout@v4
- name: Fetch IPInfo GeoIP Database
env:
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
run: |
rm pkg/geoip/geoip.db
wget -qO pkg/geoip/geoip.db https://ipinfo.io/data/free/country.mmdb?token=${IPINFO_TOKEN}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23.x"
- name: generate swagger docs
run: |
go install github.com/swaggo/swag/cmd/swag@latest
swag init --pd -d . -g ./cmd/dashboard/main.go -o ./cmd/dashboard/docs --parseGoList=false
- name: Build with tag
if: contains(github.ref, 'refs/tags/')
uses: goreleaser/goreleaser-action@v6
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
with:
distribution: goreleaser
version: '~> v2'
args: build --single-target --clean --skip=validate
- name: Build snapshot
if: contains(github.ref, 'refs/tags/') == false
uses: goreleaser/goreleaser-action@v6
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
with:
distribution: goreleaser
version: '~> v2'
args: build --single-target --clean --skip=validate --snapshot
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dashboard-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
./dist/*/*
release:
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
needs: build
name: Release
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./assets
- name: Archive and compress binaries
run: |
for file in assets/*/*/*; do
if [ -f "$file" ]; then
chmod +x "$file"
export fileWithoutExt=${file%.*}
zip -jr "$fileWithoutExt.zip" "$file"
fi
done
- name: Release
uses: ncipollo/release-action@v1
with:
artifacts: "assets/*/*/*.zip"
generateReleaseNotes: true
- name: Purge jsdelivr cache
run: |
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/install.sh
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/nezha-agent.service
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/docker-compose.yaml
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/config.yaml
LOWER_USERNAME=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/install.sh
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/nezha-agent.service
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/docker-compose.yaml
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/config.yaml
- name: Trigger sync
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
GH_DEBUG: api
run: |
gh workflow run sync-release.yml
release-docker:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: build
name: Release Docker images
steps:
- uses: actions/checkout@v4
- name: prepare frontend dists
run: |
wget https://github.com/nezhahq/nezha-dashboard/releases/download/v0.0.3/dist.zip
unzip dist.zip
mv dist admin-dist
mkdir user-dist
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./assets
- name: Fix permissions
run: |
chmod -R +x ./assets/*
mkdir dist
mv ./assets/*/*/* ./dist
- name: Extract branch name in tag
run: |
if [[ $GITHUB_REF == refs/heads/* ]]; then
export TAG_NAME=$(echo ${GITHUB_REF#refs/heads/})
else
export TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})
fi
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
id: extract_branch
- name: Log into GHCR
uses: docker/login-action@master
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- name: Log in to the AliyunCS
uses: docker/login-action@master
with:
registry: registry.cn-shanghai.aliyuncs.com
username: ${{ secrets.ALI_USER }}
password: ${{ secrets.ALI_PAT }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up image name
run: |
GHCR_IMAGE_NAME=$(echo "ghcr.io/${{ github.repository_owner }}/nezha-dashboard" | tr '[:upper:]' '[:lower:]')
if [ ${{ github.repository_owner }} = "naiba" ]
then ALI_IMAGE_NAME=$(echo "registry.cn-shanghai.aliyuncs.com/naibahq/nezha-dashboard")
else ALI_IMAGE_NAME=$(echo "registry.cn-shanghai.aliyuncs.com/${{ github.repository_owner }}/nezha-dashboard" | tr '[:upper:]' '[:lower:]')
fi
echo "GHCR_IMAGE_NAME=$GHCR_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "ALI_IMAGE_NAME=$ALI_IMAGE_NAME" >> $GITHUB_OUTPUT
id: image-name
- name: Build dasbboard image And Push with tag
if: contains(github.ref, 'refs/tags/')
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/s390x
push: true
tags: |
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
- name: Build dasbboard image And Push snapshot
if: contains(github.ref, 'refs/tags/') == false
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/s390x
push: true
tags: |
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}