-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (176 loc) · 5.26 KB
/
Copy pathrelease.yml
File metadata and controls
196 lines (176 loc) · 5.26 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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Release version, for example v1.2.3'
required: true
env:
APP_NAME: cloud-vm-manager
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/cloud-vm-manager
jobs:
build-binaries:
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
include:
- goos: linux
goarch: amd64
goarm: ''
archive: tar.gz
suffix: linux_amd64
- goos: linux
goarch: arm64
goarm: ''
archive: tar.gz
suffix: linux_arm64
- goos: linux
goarch: arm
goarm: '7'
archive: tar.gz
suffix: linux_armv7
- goos: windows
goarch: amd64
goarm: ''
archive: zip
suffix: windows_amd64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: true
- name: Resolve version
id: version
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${GITHUB_REF_NAME}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Test
run: go test ./...
- name: Build
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
CGO_ENABLED: '0'
VERSION: ${{ steps.version.outputs.version }}
run: |
mkdir -p dist/package
EXT=""
if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi
go build -trimpath -ldflags "-s -w -X main.version=${VERSION}" -o "dist/package/${APP_NAME}${EXT}" .
cp -r public dist/package/public
cat > dist/package/README-update.txt <<'TXT'
This archive contains a cloud-vm-manager binary built by GitHub Actions.
The in-app updater downloads the matching archive for the current OS/architecture.
TXT
- name: Package
shell: bash
run: |
cd dist/package
if [ "${{ matrix.archive }}" = "zip" ]; then
zip -9 "../${APP_NAME}_${{ matrix.suffix }}.zip" *
else
tar -czf "../${APP_NAME}_${{ matrix.suffix }}.tar.gz" *
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.APP_NAME }}_${{ matrix.suffix }}
path: dist/${{ env.APP_NAME }}_${{ matrix.suffix }}.*
if-no-files-found: error
publish-release:
needs: build-binaries
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Resolve version
id: version
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${GITHUB_REF_NAME}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Generate checksums
run: |
cd dist
sha256sum * > checksums.txt
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.version }}
files: |
dist/*.tar.gz
dist/*.zip
dist/checksums.txt
generate_release_notes: true
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve version
id: version
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${GITHUB_REF_NAME}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=raw,value=${{ steps.version.outputs.version }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ steps.version.outputs.version }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max