-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (113 loc) · 3.2 KB
/
Copy pathrelease.yml
File metadata and controls
132 lines (113 loc) · 3.2 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run tests
run: go test ./...
build:
needs: test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
- goos: windows
goarch: arm64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
version="dev-${GITHUB_SHA::7}"
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
version="${GITHUB_REF#refs/tags/}"
fi
mkdir -p dist
ext=""
if [ "${GOOS}" = "windows" ]; then
ext=".exe"
fi
out="dist/ra2fnt-${GOOS}-${GOARCH}${ext}"
go build -trimpath -ldflags="-s -w -X main.version=${version}" -o "${out}" ./src/cmd/ra2fnt
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ra2fnt-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/*
if-no-files-found: error
publish:
if: startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Flatten artifacts
run: |
mkdir -p release
find dist -maxdepth 3 -type f -print -exec cp {} release/ \;
- name: Package release archives
run: |
set -euo pipefail
version="${GITHUB_REF_NAME}"
mkdir -p packaged
for file in release/*; do
base="$(basename "${file}")"
stem="${base%.exe}"
stage_dir="$(mktemp -d)"
cp "${file}" "${stage_dir}/"
cp README.md LICENSE THIRD_PARTY_NOTICES.md "${stage_dir}/"
if [[ "${base}" == *.exe ]]; then
asset="packaged/${stem}-${version}.zip"
(
cd "${stage_dir}"
zip -q -r "${GITHUB_WORKSPACE}/${asset}" .
)
else
asset="packaged/${stem}-${version}.tar.gz"
tar -C "${stage_dir}" -czf "${asset}" .
fi
rm -rf "${stage_dir}"
done
- name: Publish GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
generate_release_notes: true
fail_on_unmatched_files: true
files: packaged/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}