Skip to content

Commit 8815846

Browse files
committed
chore(ci): macos notarization.
1 parent 0199ccd commit 8815846

File tree

4 files changed

+138
-39
lines changed

4 files changed

+138
-39
lines changed

.github/workflows/go.yml

+8-12
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ jobs:
5252
git --no-pager diff --quiet go.mod go.sum
5353
5454
# Try compiple all binaries first
55-
goreleaser-dryrun:
56-
name: "GoReleaser (dry-run)"
55+
compile-dryrun:
56+
name: "Compile"
5757
runs-on: ubuntu-latest
5858
needs: [golangci-lint, go-mod]
5959
steps:
@@ -82,13 +82,9 @@ jobs:
8282
name: Fetch dependencies
8383
run: go mod download
8484
-
85-
name: Run GoReleaser (Dry Run)
86-
uses: goreleaser/goreleaser-action@v2
87-
with:
88-
version: latest
89-
args: release --rm-dist --snapshot --skip-publish
90-
env:
91-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
name: Build Harp
86+
run: |
87+
go mod vendor && go build -mod=vendor -o bin/harp github.com/elastic/harp/cmd/harp
9288
9389
# Run golangci-lint
9490
golangci-lint:
@@ -116,7 +112,7 @@ jobs:
116112

117113
tests-on-linux:
118114
name: "Tests (linux)"
119-
needs: [go-mod, goreleaser-dryrun, golangci-lint] # run after golangci-lint action to not produce duplicated errors
115+
needs: [go-mod, compile-dryrun, golangci-lint] # run after golangci-lint action to not produce duplicated errors
120116
runs-on: ubuntu-latest
121117
steps:
122118
-
@@ -154,7 +150,7 @@ jobs:
154150

155151
tests-on-windows:
156152
name: "Tests (windows)"
157-
needs: [go-mod, goreleaser-dryrun, golangci-lint] # run after golangci-lint action to not produce duplicated errors
153+
needs: [go-mod, compile-dryrun, golangci-lint] # run after golangci-lint action to not produce duplicated errors
158154
runs-on: windows-latest
159155
steps:
160156
-
@@ -192,7 +188,7 @@ jobs:
192188

193189
tests-on-macos:
194190
name: "Tests (darwin)"
195-
needs: [go-mod, goreleaser-dryrun, golangci-lint] # run after golangci-lint action to not produce duplicated errors
191+
needs: [go-mod, compile-dryrun, golangci-lint] # run after golangci-lint action to not produce duplicated errors
196192
runs-on: macos-latest
197193
steps:
198194
-

.github/workflows/releaser.yml

+112-8
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ permissions:
1212
actions: write
1313

1414
jobs:
15-
linux-build:
16-
runs-on: ubuntu-latest
15+
release:
16+
runs-on: macos-latest
1717
permissions:
18-
packages: write
19-
contents: read
20-
18+
packages: read
19+
contents: write
2120
steps:
2221
-
2322
name: Cancel previous workflows
@@ -36,9 +35,6 @@ jobs:
3635
with:
3736
go-version: '1.17'
3837
check-latest: true
39-
-
40-
name: Set up Cosign
41-
uses: sigstore/cosign-installer@v2.0.1
4238
-
4339
name: Cache Go modules
4440
uses: actions/cache@v1
@@ -47,6 +43,24 @@ jobs:
4743
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
4844
restore-keys: |
4945
${{ runner.os }}-go-
46+
-
47+
name: Download cyclonedx-gomod
48+
uses: CycloneDX/gh-gomod-generate-sbom@v1
49+
with:
50+
version: v1.2.0
51+
-
52+
uses: sigstore/cosign-installer@v2
53+
-
54+
name: Import Code-Signing Certificates
55+
uses: Apple-Actions/import-codesign-certs@v1
56+
with:
57+
p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }}
58+
p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }}
59+
-
60+
name: Install gon via HomeBrew for code signing and app notarization
61+
run: |
62+
brew tap mitchellh/gon
63+
brew install mitchellh/gon/gon
5064
-
5165
name: Run GoReleaser
5266
uses: goreleaser/goreleaser-action@v2
@@ -55,3 +69,93 @@ jobs:
5569
args: release --rm-dist --skip-publish
5670
env:
5771
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
-
73+
name: Prepare Github release packages
74+
run: |
75+
mkdir .dist
76+
cp "./dist/harp-*" .dist/
77+
-
78+
name: Sign and notarize AMD64 cli
79+
run: |
80+
echo '{
81+
"source": ["./dist/harp-darwin-amd64"]
82+
"bundle_id":"co.elastic.harp",
83+
"apple_id": {},
84+
"sign": { "application_identity": "9470D0A7B70090A8EF31C3B33AB3868B38B27A3D" },
85+
"zip": {
86+
"output_path": "./.dist/harp-darwin-amd64.zip"
87+
}
88+
}' | jq '' > gon.json
89+
gon -log-level=debug -log-json ./gon.json
90+
rm -f .dist/harp-darwin-amd64
91+
- name: Sign and notarize ARM64 cli
92+
run: |
93+
echo '{
94+
"source": ["./dist/harp-darwin-arm64"]
95+
"bundle_id":"co.elastic.harp",
96+
"apple_id": {},
97+
"sign": { "application_identity": "9470D0A7B70090A8EF31C3B33AB3868B38B27A3D" },
98+
"zip": {
99+
"output_path": "./.dist/harp-darwin-arm64.zip"
100+
}
101+
}' | jq '' > gon.json
102+
gon -log-level=debug -log-json ./gon.json
103+
rm -f .dist/harp-darwin-arm64
104+
-
105+
name: Generate provenance for Release
106+
uses: philips-labs/slsa-provenance-action@v0.7.2
107+
with:
108+
command: generate
109+
subcommand: files
110+
arguments: --artifact-path .dist --output-path '.dist/provenance.json'
111+
env:
112+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
113+
-
114+
name: Sign
115+
shell: bash
116+
run: |
117+
#!/bin/bash
118+
shopt -s expand_aliases
119+
cd .dist
120+
FILES="*"
121+
for f in $FILES;
122+
do
123+
case $f in
124+
*.sbom.json)
125+
continue
126+
;;
127+
provenance.json)
128+
cosign sign-blob --key <(echo -n "${COSIGN_KEY}") "$f" > "$f.sig"
129+
;;
130+
harp-*)
131+
sha256sum "$f" | cut -d " " -f 1 > "$f.sha256"
132+
cosign sign-blob --key <(echo -n "${COSIGN_KEY}") "$f" > "$f.sig"
133+
;;
134+
esac
135+
done
136+
env:
137+
COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
138+
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
139+
-
140+
name: Verify
141+
shell: bash
142+
run: |
143+
#!/bin/bash
144+
shopt -s expand_aliases
145+
curl -sLO https://raw.githubusercontent.com/elastic/harp/cmd/harp/v${{ github.event.inputs.release }}/build/artifact/cosign.pub
146+
cd .dist
147+
FILES="*"
148+
for f in $FILES;
149+
do
150+
if [[ -f "$f.sig" ]];
151+
then
152+
cosign verify-blob --key ../cosign.pub --signature "$f.sig" $f
153+
fi
154+
done
155+
-
156+
name: Upload to release
157+
uses: AButler/upload-release-assets@v2.0
158+
with:
159+
files: '.dist/*'
160+
repo-token: ${{ secrets.GITHUB_TOKEN }}
161+
release-tag: v${{ github.event.inputs.release }}

.goreleaser.yaml

+18-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ before:
55
- go mod tidy
66
- go mod vendor
77

8+
gomod:
9+
proxy: true
10+
811
builds:
9-
- main: './cmd/harp'
12+
- id: harp
13+
main: './cmd/harp'
1014
env:
1115
- CGO_ENABLED=0
1216
mod_timestamp: '{{ .CommitTimestamp }}'
@@ -31,13 +35,24 @@ builds:
3135
- windows_amd64
3236
- windows_arm
3337
- windows_arm64
34-
binary: '{{ .ProjectName }}'
38+
binary: 'harp-{{replace .Target "_" "-"}}'
39+
hooks:
40+
post:
41+
- cmd: cyclonedx-gomod app -main ./cmd/harp -licenses -packages -json -output "dist/harp-{{replace .Target "_" "-"}}.sbom.json"
42+
env:
43+
- GOARCH={{ .Arch }}
44+
- GOOS={{ .Os }}
45+
no_unique_dist_dir: true
3546

3647
archives:
3748
- format: binary
49+
name_template: '{{ .Binary }}'
50+
51+
snapshot:
52+
name_template: "{{.Tag}}-next"
3853

3954
checksum:
40-
disable: true
55+
name_template: 'checksums.txt'
4156

4257
release:
4358
disable: true

build/artifact/gon.hcl

-16
This file was deleted.

0 commit comments

Comments
 (0)