-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (153 loc) · 5.46 KB
/
build-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
name: Build and release
on:
push:
branches: [trunk]
paths-ignore:
- 'docs/**'
- 'README.md'
pull_request:
branches: [trunk]
paths-ignore:
- 'docs/**'
- 'README.md'
jobs:
build:
name: Build
runs-on: ${{ matrix.os == 'windows' && 'windows-latest' || 'elvia-runner' }}
strategy:
matrix:
os: [linux, macos, windows]
arch: [amd64]
include:
- os: macos
arch: arm64
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Add MSBuild to PATH
if: ${{ matrix.os == 'windows' }}
uses: microsoft/setup-msbuild@v2
- name: Install WiX
if: ${{ matrix.os == 'windows' }}
run: dotnet tool install --global wix
- name: Package binaries
shell: bash
run: make 'package-${{ matrix.os }}-${{ matrix.arch }}'
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: '3lv-${{ matrix.os }}-${{ matrix.arch }}'
path: 'dist/package/*'
pre-release:
name: Pre-release
needs: [build]
runs-on: elvia-runner
if: ${{ github.event_name == 'push' }}
outputs:
version-tag: ${{ steps.get-version.outputs.version_tag }}
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Resolve version
id: get-version
run: |
version=$(cat VERSION)
echo "VERSION_TAG=v$version" | tee -a "$GITHUB_ENV" "$GITHUB_OUTPUT"
echo "MAJOR_VERSION_TAG=v$(echo $version | cut -d. -f1)" >> "$GITHUB_ENV"
- name: Create pre-release if new version
id: create-pre-release
run: |
latest_version=$(gh release list --json name,isLatest -q '.[] | select(.isLatest == true) | .name')
if [[ "$latest_version" == "$VERSION_TAG" ]]; then
echo "Version already released."
exit 0
fi
latest_prelrease_version=$(gh release list --json name,isPrerelease -q 'first(.[] | select(.isPrerelease == true) | .name)')
if [[ "$latest_prelrease_version" == "$VERSION_TAG" ]]; then
echo "Pre-release already created."
exit 0
fi
gh release create "$VERSION_TAG" --generate-notes --prerelease
env:
GH_TOKEN: ${{ github.token }}
- name: Override old major tag
run: |
git config user.name github-actions
git config user.email [email protected]
git fetch --tags
git tag "$MAJOR_VERSION_TAG" "$VERSION_TAG" -f
git push --tags -f
upload-binaries:
name: Upload binaries
needs: [pre-release]
runs-on: elvia-runner
if: ${{ github.event_name == 'push' }}
strategy:
matrix:
os: [linux, macos, windows]
arch: [amd64]
include:
- os: macos
arch: arm64
fail-fast: false
env:
VERSION_TAG: ${{ needs.pre-release.outputs.version-tag }}
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: '3lv-${{ matrix.os }}-${{ matrix.arch }}'
- name: Upload binaries if not already uploaded
run: |
version=$(echo "$VERSION_TAG" | cut -c 2-)
package_name="3lv-$version-${{ matrix.os }}-${{ matrix.arch }}"
number_of_binaries=$(gh release view "$VERSION_TAG" \
--json assets \
| jq -r --arg package_name "$package_name" '.[] | map(select(.name | contains($package_name))) | length')
# One binary and one checksum file per arch/os combo
if [[ "$number_of_binaries" -gt 1 ]]; then
echo "Binaries already uploaded."
exit 0
fi
# Special case for macOS binaries being named differently from their architecture (darwin)
if [[ '${{ matrix.os }}' == 'macos' ]]; then
mv "3lv-$version-darwin-${{ matrix.arch }}.tar.gz" "$package_name.tar.gz"
mv "3lv-$version-darwin-${{ matrix.arch }}.tar.gz.md5" "$package_name.tar.gz.md5"
fi
# Special case for Windows being packaged as MSI
if [[ '${{ matrix.os }}' == 'windows' ]]; then
gh release upload "$VERSION_TAG" "$package_name.msi"
gh release upload "$VERSION_TAG" "$package_name.msi.md5"
else
gh release upload "$VERSION_TAG" "$package_name.tar.gz"
gh release upload "$VERSION_TAG" "$package_name.tar.gz.md5"
fi
env:
GH_TOKEN: ${{ github.token }}
release:
name: Release
runs-on: elvia-runner
needs: [pre-release, upload-binaries]
if: ${{ github.event_name == 'push' }}
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Release if new version and not alpha or beta
if: ${{ !contains(needs.build.outputs.version-tag, '-alpha') && !contains(needs.build.outputs.version-tag, '-beta') }}
run: gh release edit "$VERSION_TAG" --prerelease=false --latest=true
env:
GH_TOKEN: ${{ github.token }}
VERSION_TAG: ${{ needs.pre-release.outputs.version-tag }}