Skip to content

Commit f04dcdf

Browse files
danielkovclaude
andauthored
feat: produce CLI build artifacts on PR builds (#1932)
## Summary - Adds `.goreleaser.pr.yaml` — a stripped-down GoReleaser config (builds + archives + checksum only, no brews/chocolateys/winget/changelog) with snapshot version `0.0.0-<short-sha>` so it never sorts above real releases - Adds `build-artifacts` job to `validate.yml` that cross-compiles for linux/windows/darwin on every non-draft PR push, then creates a GitHub Release tagged `v0.0.0-<short-sha>` (prerelease) with the zips + checksums — no auth needed to download since release assets on public repos are public - Adds `cleanup-pr-releases.yml` scheduled workflow that deletes `v0.0.0-*` releases older than 14 days ### Usage Test it out: [v0.0.0-7b76d461](https://github.com/speakeasy-api/speakeasy/releases/tag/v0.0.0-7b76d461) ```bash VERSION=0.0.0-7b76d461 curl -fsSL https://raw.githubusercontent.com/speakeasy-api/speakeasy/main/install.sh | sh ``` ✻ Clauded... --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
1 parent c51dfcc commit f04dcdf

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Cleanup PR Build Releases
2+
3+
on:
4+
schedule:
5+
- cron: "0 3 * * *" # Daily at 3 AM UTC
6+
7+
jobs:
8+
cleanup:
9+
name: Delete old PR build releases
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- name: Delete PR build releases older than 14 days
15+
env:
16+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
run: |
18+
cutoff=$(date -u -d '14 days ago' +%Y-%m-%dT%H:%M:%SZ)
19+
20+
gh release list --repo speakeasy-api/speakeasy --limit 100 --json tagName,createdAt \
21+
| jq -r --arg cutoff "$cutoff" \
22+
'.[] | select(.tagName | startswith("v0.0.0-")) | select(.createdAt < $cutoff) | .tagName' \
23+
| while read -r tag; do
24+
echo "Deleting release ${tag}"
25+
gh release delete "${tag}" --repo speakeasy-api/speakeasy --yes --cleanup-tag
26+
done

.github/workflows/validate.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,37 @@ jobs:
116116
- run: go test -json -v -timeout=20m ./... | gotestfmt
117117
env:
118118
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
119+
build-artifacts:
120+
name: Build PR Artifacts
121+
if: ${{ github.event.pull_request.draft == false }}
122+
permissions:
123+
contents: write
124+
runs-on:
125+
group: ubuntu-latest-large
126+
steps:
127+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
128+
with:
129+
fetch-depth: 0
130+
ref: ${{ github.event.pull_request.head.sha }}
131+
- name: Set short SHA
132+
run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_ENV"
133+
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
134+
with:
135+
go-version-file: "go.mod"
136+
- name: Configure git for private modules
137+
env:
138+
GIT_AUTH_TOKEN: ${{ secrets.BOT_REPO_TOKEN }}
139+
run: git config --global url."https://speakeasybot:${GIT_AUTH_TOKEN}@github.com".insteadOf "https://github.com"
140+
- uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0
141+
with:
142+
version: '~> v2'
143+
args: release --snapshot --clean --config .goreleaser.pr.yaml
144+
- name: Create release
145+
env:
146+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147+
run: |
148+
gh release create "v0.0.0-${SHORT_SHA}" \
149+
--title "PR Build (${SHORT_SHA})" \
150+
--notes "Built from commit ${{ github.event.pull_request.head.sha }} on PR #${{ github.event.pull_request.number }}" \
151+
--prerelease \
152+
dist/*.zip dist/checksums.txt

.goreleaser.pr.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
# Stripped-down GoReleaser config for PR snapshot builds.
3+
# Produces cross-compiled archives named like releases but versioned with the commit SHA.
4+
version: 2
5+
6+
before:
7+
hooks:
8+
- go mod tidy
9+
- go generate ./...
10+
- go run scripts/completions.go
11+
builds:
12+
- env:
13+
- CGO_ENABLED=0
14+
goos:
15+
- linux
16+
- windows
17+
- darwin
18+
ldflags:
19+
- "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser -X main.artifactArch={{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
20+
archives:
21+
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
22+
formats: [zip]
23+
files:
24+
- completions/*
25+
checksum:
26+
name_template: "checksums.txt"
27+
snapshot:
28+
version_template: "0.0.0-{{ .ShortCommit }}"

0 commit comments

Comments
 (0)