-
Notifications
You must be signed in to change notification settings - Fork 0
216 lines (187 loc) · 6.86 KB
/
release.yml
File metadata and controls
216 lines (187 loc) · 6.86 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Existing tag to release (manual runs), e.g. v1.2.3 or v1.2.4-nightly-2026-04-18"
required: true
type: string
permissions:
contents: write
jobs:
build:
if: github.event_name == 'workflow_dispatch' || !contains(github.ref_name, '-nightly-')
name: Build ${{ matrix.goos }}-${{ matrix.goarch }}
runs-on: ${{ matrix.runner }}
env:
TARGET_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
goos: linux
goarch: amd64
archive: tar.gz
- runner: ubuntu-latest
goos: linux
goarch: arm64
archive: tar.gz
- runner: macos-latest
goos: darwin
goarch: amd64
archive: tar.gz
- runner: macos-latest
goos: darwin
goarch: arm64
archive: tar.gz
- runner: windows-latest
goos: windows
goarch: amd64
archive: zip
- runner: windows-latest
goos: windows
goarch: arm64
archive: zip
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref }}
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build and package (Unix)
if: matrix.archive == 'tar.gz'
shell: bash
run: |
set -euo pipefail
mkdir -p dist
export CGO_ENABLED=0
export GOOS="${{ matrix.goos }}"
export GOARCH="${{ matrix.goarch }}"
VERSION="${TARGET_TAG:-dev}"
go build -trimpath -ldflags "-s -w -X luumen/internal/cli.version=${VERSION}" -o dist/luu ./cmd/luu
asset_name="luu-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz"
tar -C dist -czf "$asset_name" luu
echo "ASSET_NAME=$asset_name" >> "$GITHUB_ENV"
- name: Build and package (Windows)
if: matrix.archive == 'zip'
shell: pwsh
run: |
New-Item -ItemType Directory -Path dist -Force | Out-Null
$env:CGO_ENABLED = "0"
$env:GOOS = "windows"
$env:GOARCH = "${{ matrix.goarch }}"
$version = if ($env:TARGET_TAG) { $env:TARGET_TAG } else { "dev" }
$ldflags = "-s -w -X luumen/internal/cli.version=$version"
go build -trimpath -ldflags $ldflags -o dist/luu.exe ./cmd/luu
$assetName = "luu-windows-${{ matrix.goarch }}.zip"
Compress-Archive -Path dist/luu.exe -DestinationPath $assetName -Force
"ASSET_NAME=$assetName" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Upload packaged artifact
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ env.ASSET_NAME }}
if-no-files-found: error
release:
name: Publish Release
runs-on: ubuntu-latest
needs: build
env:
TARGET_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
steps:
- name: Download packaged artifacts
uses: actions/download-artifact@v4
with:
path: release-assets
pattern: release-*
merge-multiple: true
- name: Generate checksums.txt
shell: bash
run: |
set -euo pipefail
cd release-assets
sha256sum * > checksums.txt
- name: Generate commit summary
id: commit_notes
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const targetTag = process.env.TARGET_TAG;
if (!targetTag) {
return "### Commit Summary\n\n- Could not determine target tag.";
}
const tags = await github.paginate(github.rest.repos.listTags, {
owner,
repo,
per_page: 100,
});
const isNightly = targetTag.includes("-nightly-");
const nightlyPattern = /^v\d+\.\d+\.\d+-nightly-\d{4}-\d{2}-\d{2}$/;
const stablePattern = /^v\d+\.\d+\.\d+$/;
const matchingTags = tags.filter((tag) => {
if (isNightly) {
return nightlyPattern.test(tag.name);
}
return stablePattern.test(tag.name);
});
const targetIndex = matchingTags.findIndex((tag) => tag.name === targetTag);
const previousTag = targetIndex >= 0 && targetIndex + 1 < matchingTags.length
? matchingTags[targetIndex + 1].name
: null;
let commits = [];
if (previousTag) {
const compare = await github.rest.repos.compareCommitsWithBasehead({
owner,
repo,
basehead: `${previousTag}...${targetTag}`,
});
commits = compare.data.commits || [];
} else {
const list = await github.rest.repos.listCommits({
owner,
repo,
sha: targetTag,
per_page: 30,
});
commits = list.data || [];
}
const maxCommits = 50;
const shown = commits.slice(-maxCommits);
const header = previousTag
? `### Commit Summary (${previousTag}...${targetTag})`
: `### Commit Summary (${targetTag})`;
const lines = shown.map((commit) => {
const sha = commit.sha.slice(0, 7);
const subject = (commit.commit.message || "").split("\n")[0];
const author = commit.author && commit.author.login ? ` @${commit.author.login}` : "";
return `- \`${sha}\` ${subject}${author}`;
});
if (lines.length === 0) {
lines.push("- No commits found.");
}
if (commits.length > maxCommits) {
lines.push(`- ...and ${commits.length - maxCommits} more commit(s).`);
}
return `${header}\n\n${lines.join("\n")}`;
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TARGET_TAG }}
name: ${{ env.TARGET_TAG }}
prerelease: ${{ contains(env.TARGET_TAG, '-nightly-') }}
generate_release_notes: true
append_body: true
body: ${{ steps.commit_notes.outputs.result }}
files: |
release-assets/*