Skip to content

Commit

Permalink
refactor(goreleaser): add post hook to codesign
Browse files Browse the repository at this point in the history
  • Loading branch information
cage1016 committed Jun 26, 2024
1 parent 51ed51e commit 2c09259
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ builds:
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}-{{ .Arm }}{{ end }}
no_unique_dist_dir: true
hooks:
post:
- cmd: ./script/sign '{{ .Path }}'
output: true

archives:
- format: binary
Expand Down
42 changes: 42 additions & 0 deletions script/sign
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# usage: script/sign <file>
#
# Signs macOS binaries using codesign, notarizes macOS zip archives using notarytool, and signs
# Windows EXE and MSI files using osslsigncode.
#
set -e

sign_macos() {
if [ -z "$APPLE_DEVELOPER_ID" ]; then
echo "skipping macOS code-signing; APPLE_DEVELOPER_ID not set" >&2
return 0
fi

if [[ $1 == *.zip ]]; then
xcrun notarytool submit "$1" --apple-id "${APPLE_ID?}" --team-id "${APPLE_DEVELOPER_ID?}" --password "${APPLE_ID_PASSWORD?}"
else
codesign --timestamp --options=runtime -s "${APPLE_DEVELOPER_ID?}" -v "$1"
fi
}

if [ $# -eq 0 ]; then
echo "usage: script/sign <file>" >&2
exit 1
fi

platform="$(uname -s)"

for input_file; do
case "$input_file" in
*.exe | *.msi)
sign_windows "$input_file"
;;
*)
if [ "$platform" = "Darwin" ]; then
sign_macos "$input_file"
else
printf "warning: don't know how to sign %s on %s\n" "$1", "$platform" >&2
fi
;;
esac
done

0 comments on commit 2c09259

Please sign in to comment.