-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Quote variables in case values contain spaces - Use bash arrays where applicable - Use new `gh release create --generate-notes` flag - Simplify generating checksums - Release only regular files within `dist/*` - Fix checking whether `dist/*` is empty
- Loading branch information
Showing
1 changed file
with
43 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,59 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
tag=$(git describe --tags --abbrev=0) | ||
platforms=$(echo "darwin-amd64,darwin-arm64,linux-386,linux-arm,linux-amd64,linux-arm64,windows-386,windows-amd64" | tr "," "\n") | ||
include="dist/*" | ||
platforms=( | ||
darwin-amd64 | ||
darwin-arm64 | ||
linux-386 | ||
linux-arm | ||
linux-amd64 | ||
linux-arm64 | ||
windows-386 | ||
windows-amd64 | ||
) | ||
|
||
if [[ $GITHUB_REF = refs/tags/* ]]; then | ||
tag="${GITHUB_REF#refs/tags/}" | ||
else | ||
tag="$(git describe --tags --abbrev=0)" | ||
fi | ||
|
||
prerelease="" | ||
if [[ $tag = *-* ]]; then | ||
prerelease="--prerelease" | ||
fi | ||
|
||
if [ -n "${GH_EXT_BUILD_SCRIPT}" ]; then | ||
echo "invoking build script override ${GH_EXT_BUILD_SCRIPT}" | ||
./${GH_EXT_BUILD_SCRIPT} $tag || exit $? | ||
if [ -n "$GH_EXT_BUILD_SCRIPT" ]; then | ||
echo "invoking build script override $GH_EXT_BUILD_SCRIPT" | ||
./"$GH_EXT_BUILD_SCRIPT" "$tag" | ||
else | ||
for p in $platforms; do | ||
goos=$(echo $p | sed 's/-.*//') | ||
goarch=$(echo $p | sed 's/.*-//') | ||
for p in "${platforms[@]}"; do | ||
goos="${p%-*}" | ||
goarch="${p#*-}" | ||
ext="" | ||
if [[ "${goos}" == "windows" ]]; then | ||
if [ "$goos" = "windows" ]; then | ||
ext=".exe" | ||
fi | ||
GOOS=${goos} GOARCH=${goarch} go build -trimpath -ldflags="-s -w" -o "dist/${goos}-${goarch}${ext}" | ||
GOOS="$goos" GOARCH="$goarch" go build -trimpath -ldflags="-s -w" -o "dist/${p}${ext}" | ||
done | ||
fi | ||
|
||
ls -A dist >/dev/null || (echo "no files found in dist/" && exit 1) | ||
assets=() | ||
for f in dist/*; do | ||
if [ -f "$f" ]; then | ||
assets+=("$f") | ||
fi | ||
done | ||
|
||
if [ -n "${GPG_FINGERPRINT}" ]; then | ||
for f in $(ls dist); do | ||
shasum -a 256 dist/$f >> checksums.txt | ||
done | ||
gpg --output checksums.txt.sig --detach-sign checksums.txt | ||
include="dist/* checksums*" | ||
if [ "${#assets[@]}" -eq 0 ]; then | ||
echo "error: no files found in dist/*" >&2 | ||
exit 1 | ||
fi | ||
|
||
prerelease="" | ||
|
||
if [[ "${tag}" =~ .*-.* ]]; then | ||
prerelease="-p" | ||
if [ -n "$GPG_FINGERPRINT" ]; then | ||
shasum -a 256 "${assets[@]}" > checksums.txt | ||
gpg --output checksums.txt.sig --detach-sign checksums.txt | ||
assets+=(checksums.txt checksums.txt.sig) | ||
fi | ||
|
||
gh api repos/$GITHUB_REPOSITORY/releases/generate-notes \ | ||
-f tag_name="${tag}" -q .body > CHANGELOG.md | ||
|
||
gh release create $tag $prerelease --notes-file CHANGELOG.md $include | ||
gh release create "$tag" $prerelease --generate-notes -- "${assets[@]}" |