Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💅 Script refresh #21

Merged
merged 1 commit into from
Jun 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 43 additions & 26 deletions build_and_release.sh
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[@]}"