Skip to content

Commit 3f68860

Browse files
committed
Add CI and tagged release workflows
1 parent cd4a80a commit 3f68860

4 files changed

Lines changed: 175 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
go:
18+
name: Go checks
19+
runs-on: macos-latest
20+
steps:
21+
- name: Check out source
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version-file: go.mod
28+
cache: true
29+
30+
- name: Check formatting
31+
shell: bash
32+
run: |
33+
go fmt ./...
34+
if ! git diff --quiet -- '*.go'; then
35+
echo 'Go formatting changed tracked files:'
36+
git diff -- '*.go'
37+
exit 1
38+
fi
39+
40+
- name: Vet
41+
run: go vet ./...
42+
43+
- name: Test
44+
run: go test ./...
45+
46+
- name: Test with race detector
47+
run: go test -race ./...
48+
49+
- name: Build CLI
50+
run: go build -trimpath ./cmd/things-cli
51+
52+
- name: Build release architectures
53+
shell: bash
54+
run: |
55+
mkdir -p "$RUNNER_TEMP/things-cli-build"
56+
GOOS=darwin GOARCH=amd64 go build -trimpath \
57+
-o "$RUNNER_TEMP/things-cli-build/things-cli-darwin-amd64" \
58+
./cmd/things-cli
59+
GOOS=darwin GOARCH=arm64 go build -trimpath \
60+
-o "$RUNNER_TEMP/things-cli-build/things-cli-darwin-arm64" \
61+
./cmd/things-cli
62+
63+
docs:
64+
name: Documentation build
65+
runs-on: ubuntu-latest
66+
steps:
67+
- name: Check out source
68+
uses: actions/checkout@v4
69+
70+
- name: Set up Node.js
71+
uses: actions/setup-node@v4
72+
with:
73+
node-version: 22
74+
cache: npm
75+
cache-dependency-path: docs/package-lock.json
76+
77+
- name: Install documentation dependencies
78+
run: npm --prefix docs ci
79+
80+
- name: Build documentation
81+
run: npm --prefix docs run build
82+
83+
- name: Upload documentation artifact
84+
if: ${{ !cancelled() }}
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: things-cli-docs-${{ github.run_id }}
88+
path: docs/dist
89+
if-no-files-found: error
90+
retention-days: 3

.github/workflows/release.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: release-${{ github.ref }}
13+
cancel-in-progress: false
14+
15+
jobs:
16+
release:
17+
name: Publish release
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
id-token: write
22+
attestations: write
23+
steps:
24+
- name: Check out source and tag history
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Set up Go
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version-file: go.mod
33+
cache: true
34+
35+
- name: Validate release tag
36+
shell: bash
37+
run: |
38+
tag_commit="$(git rev-list -n 1 "$GITHUB_REF")"
39+
if [[ -z "$tag_commit" || "$tag_commit" != "$GITHUB_SHA" ]]; then
40+
echo "::error::${GITHUB_REF} does not resolve to the workflow commit ($GITHUB_SHA)."
41+
exit 1
42+
fi
43+
44+
git fetch origin main --no-tags
45+
if ! git merge-base --is-ancestor "$tag_commit" origin/main; then
46+
echo "::error::Release tags must point at a commit reachable from main."
47+
exit 1
48+
fi
49+
50+
- name: Vet
51+
run: go vet ./...
52+
53+
- name: Test
54+
run: go test ./...
55+
56+
- name: Verify Homebrew token
57+
env:
58+
HAS_TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN != '' }}
59+
run: |
60+
if [[ "$HAS_TAP_GITHUB_TOKEN" != "true" ]]; then
61+
echo '::error::TAP_GITHUB_TOKEN is required to publish the Homebrew formula.'
62+
exit 1
63+
fi
64+
65+
- name: Install Syft for SBOM generation
66+
uses: anchore/sbom-action/download-syft@v0.24.0
67+
68+
- name: Release with GoReleaser
69+
uses: goreleaser/goreleaser-action@v6
70+
with:
71+
distribution: goreleaser
72+
version: v2.17.1
73+
args: release --clean
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
77+
78+
- name: Attest release artifacts
79+
uses: actions/attest-build-provenance@v2
80+
with:
81+
subject-path: 'dist/*'

.goreleaser.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ archives:
2929
checksum:
3030
name_template: "checksums.txt"
3131

32+
sboms:
33+
- artifacts: archive
34+
3235
changelog:
3336
use: github
3437
sort: asc

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ vet: ## Run go vet
3232
tidy: ## Tidy Go modules
3333
go mod tidy
3434

35-
check: fmt tidy vet test ## Format, tidy, vet, and test
35+
check: fmt tidy vet test build ## Format, tidy, vet, test, and build
3636

3737
docs-install: ## Install documentation site dependencies
3838
npm --prefix docs ci

0 commit comments

Comments
 (0)