forked from pterodactyl/wings
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (119 loc) · 4.45 KB
/
Copy pathbinary.yaml
File metadata and controls
130 lines (119 loc) · 4.45 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
name: Build Binary
# Two ways in:
#
# 1. Called by release.yaml as a reusable workflow, right after the draft
# release was opened. This is the automatic path, and it runs in the SAME
# workflow run — which is what makes it work at all: a release published
# with GITHUB_TOKEN does NOT trigger new workflow runs, so an `on: release`
# listener would silently never fire.
#
# 2. A manual dispatch, to check that a build still works without touching any
# release. On that path `inputs` is empty, every `inputs.*` reference below
# evaluates to '' rather than erroring, and the binaries are kept as run
# artifacts instead of being attached anywhere.
on:
workflow_call:
inputs:
ref:
description: Commit SHA (or ref) to build. Defaults to the caller's ref.
type: string
required: false
default: ''
release-tag:
description: >-
Tag of an existing — possibly draft — GitHub Release to attach the
binaries and SHA256SUMS to. Empty means build and smoke-test only.
type: string
required: false
default: ''
version:
description: >-
Version to compile in, without a leading `v` (e.g. 1.13.2). Asserted
against what the built binary reports.
type: string
required: false
default: ''
workflow_dispatch:
permissions:
contents: write
jobs:
binary:
name: Build
runs-on: ubuntu-24.04
steps:
- name: Code checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
# Empty on dispatch, which makes actions/checkout fall back to its own
# default (the triggering ref and github.sha).
ref: ${{ inputs.ref }}
- name: Setup Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version: 1.24.11
- name: Resolve the version
id: resolve
env:
VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
# A dispatch build carries no version; label it by commit so a stray
# binary can never claim to be a release.
if [ -z "$VERSION" ]; then
VERSION="dev-$(git rev-parse --short HEAD)"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Build release binaries
env:
CGO_ENABLED: 0
VERSION: ${{ steps.resolve.outputs.version }}
run: |
set -euo pipefail
for arch in amd64 arm64; do
GOARCH="$arch" go build \
-o "dist/wings_linux_${arch}" \
-v -trimpath \
-ldflags="-s -w -X github.com/Rene-Roscher/wings/system.Version=${VERSION}" \
github.com/Rene-Roscher/wings
chmod 755 "dist/wings_linux_${arch}"
done
# Catches a broken ldflags path silently producing a binary that reports
# "develop" — which would otherwise only surface on a node, after release.
- name: Assert the binary reports the version it was built with
env:
VERSION: ${{ steps.resolve.outputs.version }}
run: |
set -euo pipefail
reported="$(./dist/wings_linux_amd64 version | head -n1)"
echo "$reported"
printf '%s' "$reported" | grep -qF "wings v${VERSION}" || {
echo "::error::binary reports '${reported}', expected 'wings v${VERSION}'"
exit 1
}
- name: Generate SHA256SUMS
run: |
set -euo pipefail
cd dist
sha256sum wings_linux_amd64 wings_linux_arm64 > SHA256SUMS
cat SHA256SUMS
- name: Attach the assets to the release
if: inputs.release-tag != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
TAG: ${{ inputs.release-tag }}
run: |
set -euo pipefail
# --clobber so that re-running a failed run replaces partial uploads
# instead of failing on "asset already exists".
gh release upload "$TAG" \
dist/wings_linux_amd64 \
dist/wings_linux_arm64 \
dist/SHA256SUMS \
--clobber
- name: Upload the binaries as run artifacts
if: inputs.release-tag == ''
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: wings-binaries
path: dist/