Repository navigation
140 lines (125 loc) · 5.82 KB
/
Copy pathrelease.yml
File metadata and controls
140 lines (125 loc) · 5.82 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
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- name: Test
run: |
go vet ./...
go test ./...
- name: Build all platforms
run: |
mkdir -p build
VERSION="${GITHUB_REF_NAME#v}"
# Stamp the build SHA into the Exposure Receipt so a receipt names the
# exact binary that produced it (agent_build_sha).
LDFLAGS="-s -w -X main.Version=${VERSION} -X github.com/Quality-Max/qmax-receipt.BuildSHA=${GITHUB_SHA}"
GOOS=darwin GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o build/qmax-code-darwin-amd64 .
GOOS=darwin GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o build/qmax-code-darwin-arm64 .
GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o build/qmax-code-linux-amd64 .
GOOS=linux GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o build/qmax-code-linux-arm64 .
GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o build/qmax-code-windows-amd64.exe .
GOOS=windows GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o build/qmax-code-windows-arm64.exe .
- name: Collect third-party notices
run: |
# Include modules used on every shipped OS, including Windows-only imports.
for platform in darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64 windows/arm64; do
GOOS="${platform%/*}" GOARCH="${platform#*/}" go list -deps \
-f '{{with .Module}}{{if not .Main}}{{.Path}} {{.Version}} {{.Dir}}{{end}}{{end}}' .
done | sort -u > build/modules.txt
printf 'Third-party licenses for qmax-code\n' > build/THIRD_PARTY_NOTICES.txt
while read -r module version dir; do
[ -n "$module" ] || continue
found=false
for notice in "$dir"/LICENSE* "$dir"/LICENCE* "$dir"/COPYING* "$dir"/NOTICE*; do
[ -f "$notice" ] || continue
printf '\n===== %s %s: %s =====\n\n' "$module" "$version" "${notice##*/}" >> build/THIRD_PARTY_NOTICES.txt
cat "$notice" >> build/THIRD_PARTY_NOTICES.txt
found=true
done
# This pinned Windows dependency declares MIT in its README only.
if [ "$found" = false ] && [ "$module" = github.com/mattn/go-localereader ]; then
printf '\n===== %s %s: README.md =====\n\n' "$module" "$version" >> build/THIRD_PARTY_NOTICES.txt
cat "$dir/README.md" >> build/THIRD_PARTY_NOTICES.txt
found=true
fi
if [ "$found" = false ]; then
echo "Missing third-party license: $module" >&2
exit 1
fi
done < build/modules.txt
- name: Create archives
run: |
cp LICENSE NOTICE build/
cd build
tar czf qmax-code-darwin-amd64.tar.gz qmax-code-darwin-amd64 LICENSE NOTICE THIRD_PARTY_NOTICES.txt
tar czf qmax-code-darwin-arm64.tar.gz qmax-code-darwin-arm64 LICENSE NOTICE THIRD_PARTY_NOTICES.txt
tar czf qmax-code-linux-amd64.tar.gz qmax-code-linux-amd64 LICENSE NOTICE THIRD_PARTY_NOTICES.txt
tar czf qmax-code-linux-arm64.tar.gz qmax-code-linux-arm64 LICENSE NOTICE THIRD_PARTY_NOTICES.txt
zip -q qmax-code-windows-amd64.zip qmax-code-windows-amd64.exe LICENSE NOTICE THIRD_PARTY_NOTICES.txt
zip -q qmax-code-windows-arm64.zip qmax-code-windows-arm64.exe LICENSE NOTICE THIRD_PARTY_NOTICES.txt
- name: Prepare release announcement
run: |
NOTES="docs/releases/${GITHUB_REF_NAME}.md"
if [ -f "$NOTES" ]; then
cp "$NOTES" build/release-notes.md
else
touch build/release-notes.md
fi
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body_path: build/release-notes.md
generate_release_notes: true
files: |
build/qmax-code-darwin-amd64.tar.gz
build/qmax-code-darwin-arm64.tar.gz
build/qmax-code-linux-amd64.tar.gz
build/qmax-code-linux-arm64.tar.gz
build/qmax-code-windows-amd64.zip
build/qmax-code-windows-arm64.zip
- name: Publish to public releases repo
env:
RELEASES_TOKEN: ${{ secrets.RELEASES_REPO_TOKEN }}
GH_TOKEN: ${{ secrets.RELEASES_REPO_TOKEN }}
run: |
TAG="${GITHUB_REF_NAME}"
if [ -z "$RELEASES_TOKEN" ]; then
echo "RELEASES_REPO_TOKEN not set — skipping public repo publish"
exit 0
fi
# Clone public releases repo
gh auth setup-git --hostname github.com
gh repo clone Quality-Max/qmax-code-releases /tmp/releases
cd /tmp/releases
# Copy archives
cp $GITHUB_WORKSPACE/build/*.tar.gz .
cp $GITHUB_WORKSPACE/build/*.zip .
cp "$GITHUB_WORKSPACE/LICENSE" "$GITHUB_WORKSPACE/NOTICE" .
cp "$GITHUB_WORKSPACE/build/THIRD_PARTY_NOTICES.txt" .
# Commit and push
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add *.tar.gz *.zip LICENSE NOTICE THIRD_PARTY_NOTICES.txt
git commit -m "release: ${TAG}" || true
git push
# Create release on public repo
gh release view "$TAG" --repo Quality-Max/qmax-code \
--json body --jq .body > /tmp/release-notes.md
gh release create "${TAG}" \
*.tar.gz *.zip \
--repo Quality-Max/qmax-code-releases \
--title "${TAG}" \
--notes-file /tmp/release-notes.md