Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 866205c

Browse files
authored
feat: Sign MacOS binaries (coder#1060)
This fixes virus warnings when launching Coder on darwin.
1 parent a5f36ad commit 866205c

File tree

4 files changed

+91
-15
lines changed

4 files changed

+91
-15
lines changed

.github/workflows/release.yaml

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- "v*"
66
jobs:
77
goreleaser:
8-
runs-on: ubuntu-latest
8+
runs-on: macos-latest
99
steps:
1010
- uses: actions/checkout@v3
1111
with:
@@ -14,6 +14,17 @@ jobs:
1414
with:
1515
go-version: "~1.18"
1616

17+
- name: Install Gon
18+
run: |
19+
brew tap mitchellh/gon
20+
brew install mitchellh/gon/gon
21+
22+
- name: Import Signing Certificates
23+
uses: Apple-Actions/import-codesign-certs@v1
24+
with:
25+
p12-file-base64: ${{ secrets.AC_CERTIFICATE_P12_BASE64 }}
26+
p12-password: ${{ secrets.AC_CERTIFICATE_PASSWORD }}
27+
1728
- name: Echo Go Cache Paths
1829
id: go-cache-paths
1930
run: |
@@ -53,3 +64,5 @@ jobs:
5364
args: release --rm-dist
5465
env:
5566
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
AC_USERNAME: ${{ secrets.AC_USERNAME }}
68+
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}

.goreleaser.yaml

+58-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
archives:
2-
- id: coder
3-
builds:
4-
- coder
2+
- id: coder-linux
3+
builds: [coder-linux]
4+
format: tar
5+
files:
6+
- src: docs/README.md
7+
dst: README.md
8+
9+
- id: coder-darwin
10+
builds: [coder-darwin]
11+
format: zip
12+
files:
13+
- src: docs/README.md
14+
dst: README.md
15+
16+
- id: coder-windows
17+
builds: [coder-windows]
18+
format: zip
519
files:
620
- src: docs/README.md
721
dst: README.md
8-
format_overrides:
9-
- goos: windows
10-
format: zip
1122

1223
before:
1324
hooks:
@@ -27,15 +38,44 @@ builds:
2738
post: |
2839
cp {{.Path}} site/out/bin/coder-{{ .Os }}-{{ .Arch }}{{ trimprefix .Name "coder" }}
2940
30-
- id: coder
41+
- id: coder-linux
3142
dir: cmd/coder
32-
flags: ["-tags=embed"]
43+
flags: [-tags=embed]
3344
ldflags:
3445
["-s -w -X github.com/coder/coder/cli/buildinfo.tag={{ .Version }}"]
3546
env: [CGO_ENABLED=0]
36-
goos: [darwin, linux, windows]
47+
goos: [linux]
48+
goarch: [amd64, arm64]
49+
50+
- id: coder-windows
51+
dir: cmd/coder
52+
flags: [-tags=embed]
53+
ldflags:
54+
["-s -w -X github.com/coder/coder/cli/buildinfo.tag={{ .Version }}"]
55+
env: [CGO_ENABLED=0]
56+
goos: [windows]
3757
goarch: [amd64, arm64]
3858

59+
- id: coder-darwin
60+
dir: cmd/coder
61+
flags: [-tags=embed]
62+
ldflags:
63+
["-s -w -X github.com/coder/coder/cli/buildinfo.tag={{ .Version }}"]
64+
env: [CGO_ENABLED=0]
65+
goos: [darwin]
66+
goarch: [amd64, arm64]
67+
hooks:
68+
# This signs the binary that will be located inside the zip.
69+
# MacOS requires the binary to be signed for notarization.
70+
#
71+
# If it doesn't successfully sign, the zip sign step will error.
72+
post: |
73+
sh -c 'codesign -s {{.Env.AC_APPLICATION_IDENTITY}} -f -v --timestamp --options runtime {{.Path}} || true'
74+
75+
env:
76+
# Apple identity for signing!
77+
- AC_APPLICATION_IDENTITY=BDB050EB749EDD6A80C6F119BF1382ECA119CCCC
78+
3979
nfpms:
4080
- id: packages
4181
vendor: Coder
@@ -50,7 +90,7 @@ nfpms:
5090
suggests:
5191
- postgresql
5292
builds:
53-
- coder
93+
- coder-linux
5494
bindir: /usr/bin
5595
contents:
5696
- src: coder.env
@@ -60,7 +100,14 @@ nfpms:
60100
dst: /usr/lib/systemd/system/coder.service
61101

62102
release:
63-
ids: [coder, packages]
103+
ids: [coder-linux, coder-darwin, coder-windows, packages]
104+
105+
signs:
106+
- ids: [coder-darwin]
107+
artifacts: archive
108+
cmd: ./scripts/sign_macos.sh
109+
args: ["${artifact}"]
110+
output: true
64111

65112
snapshot:
66113
name_template: "{{ .Version }}-devel+{{ .ShortCommit }}"

Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ provisionersdk/proto: provisionersdk/proto/provisioner.proto
8888
./provisionersdk/proto/provisioner.proto
8989
.PHONY: provisionersdk/proto
9090

91-
release: site/out
92-
goreleaser release --snapshot --rm-dist
91+
release:
92+
goreleaser release --snapshot --rm-dist --skip-sign
9393
.PHONY: release
9494

9595
site/out:
@@ -102,4 +102,3 @@ site/out:
102102

103103
test:
104104
gotestsum -- -v -short ./...
105-

scripts/sign_macos.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
cd "$(git rev-parse --show-toplevel)"
5+
6+
codesign -s $AC_APPLICATION_IDENTITY -f -v --timestamp --options runtime $1
7+
8+
config="$(mktemp -d)/gon.json"
9+
jq -r --null-input --arg path "$(pwd)/$1" '{
10+
"notarize": [
11+
{
12+
"path": $path,
13+
"bundle_id": "com.coder.cli"
14+
}
15+
]
16+
}' > $config
17+
gon $config

0 commit comments

Comments
 (0)