-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (88 loc) · 2.61 KB
/
Copy pathrelease.yml
File metadata and controls
100 lines (88 loc) · 2.61 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Release version, for example v0.1.0"
required: true
type: string
draft:
description: "Create release as draft"
required: true
default: true
type: boolean
prerelease:
description: "Mark release as prerelease"
required: true
default: false
type: boolean
notes:
description: "Release notes"
required: false
type: string
permissions:
contents: write
jobs:
release:
name: Build and publish binaries
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-file: go.mod
cache: true
- name: Validate version
run: |
version="${{ inputs.version }}"
if ! printf '%s' "$version" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$'; then
echo "Version must look like v0.1.0 or v0.1.0-rc.1"
exit 1
fi
- name: Test
run: go test ./...
- name: Build release assets
run: |
set -euo pipefail
version="${{ inputs.version }}"
mkdir -p dist
build() {
os="$1"
arch="$2"
ext="$3"
name="mmdbforge_${version}_${os}_${arch}"
bin="dist/${name}/mmdbforge${ext}"
mkdir -p "dist/${name}"
GOOS="$os" GOARCH="$arch" CGO_ENABLED=0 go build \
-trimpath \
-ldflags="-s -w -X main.version=${version}" \
-o "$bin" \
./cmd/mmdbforge
cp README.md LICENSE "dist/${name}/"
if [ "$os" = "windows" ]; then
(cd dist && zip -qr "${name}.zip" "${name}")
rm -rf "dist/${name}"
else
tar -C dist -czf "dist/${name}.tar.gz" "${name}"
rm -rf "dist/${name}"
fi
}
build linux amd64 ""
build linux arm64 ""
build darwin amd64 ""
build darwin arm64 ""
build windows amd64 ".exe"
build windows arm64 ".exe"
(cd dist && shasum -a 256 * > checksums.txt)
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_VERSION: ${{ inputs.version }}
RELEASE_DRAFT: ${{ inputs.draft }}
RELEASE_PRERELEASE: ${{ inputs.prerelease }}
RELEASE_NOTES: ${{ inputs.notes }}
run: |