Skip to content

Commit

Permalink
Merge pull request #21 from cli/script-refresh
Browse files Browse the repository at this point in the history
💅 Script refresh
  • Loading branch information
mislav authored Jun 8, 2022
2 parents 19c3117 + 8dc9751 commit fcb2907
Showing 1 changed file with 43 additions and 26 deletions.
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[@]}"

0 comments on commit fcb2907

Please sign in to comment.