Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ project_name: pscale
version: 2
release:
prerelease: auto # don't publish release with -rc1,-pre, etc suffixes
replace_existing_artifacts: true
before:
hooks:
- go mod tidy
Expand Down
65 changes: 64 additions & 1 deletion script/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -eu

DRY_RUN="${DRY_RUN:-false}"
WORKDIR=$(pwd)

if [ -z "${GORELEASER_CURRENT_TAG:-}" ]; then
Expand All @@ -10,6 +11,67 @@ if [ -z "${GORELEASER_CURRENT_TAG:-}" ]; then
fi
export GORELEASER_CURRENT_TAG

VERSION="${GORELEASER_CURRENT_TAG#v}"

all_targets=(docker homebrew scoop aur)
skip=()

if docker manifest inspect "planetscale/pscale:${GORELEASER_CURRENT_TAG}" >/dev/null 2>&1; then
echo "==> Docker image already exists, skipping docker"
skip+=(docker)
fi

if gh api "repos/planetscale/homebrew-tap/contents/Formula/pscale.rb" --jq '.content' 2>/dev/null \
| base64 --decode 2>/dev/null | grep -q "version \"${VERSION}\""; then
echo "==> Homebrew formula already up to date, skipping homebrew"
skip+=(homebrew)
fi

if gh api "repos/planetscale/scoop-bucket/contents/pscale.json" --jq '.content' 2>/dev/null \
| base64 --decode 2>/dev/null | grep -q "\"version\": \"${VERSION}\""; then
echo "==> Scoop manifest already up to date, skipping scoop"
skip+=(scoop)
fi

if curl -fsSL --connect-timeout 5 "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=pscale-cli-bin" 2>/dev/null \
| grep -q "pkgver=${VERSION}"; then
echo "==> AUR package already up to date, skipping aur"
skip+=(aur)
fi

should_skip() {
local target=$1
for s in "${skip[@]+"${skip[@]}"}"; do
[ "$target" = "$s" ] && return 0
done
return 1
}

run=()
echo ""
echo "==> Release plan for ${GORELEASER_CURRENT_TAG}:"
for target in "${all_targets[@]}"; do
if should_skip "$target"; then
echo " skip ${target}"
else
echo " run ${target}"
run+=("$target")
fi
done
echo ""

if [ ${#run[@]} -eq 0 ]; then
echo "==> All targets already published, nothing to do."
exit 0
fi

if [ "$DRY_RUN" = "true" ]; then
echo "==> Dry run, exiting."
exit 0
fi

GORELEASER_SKIP=$(IFS=,; echo ${skip[*]+"${skip[*]}"})

tmpdir=$(mktemp -d)
cat >"$tmpdir/docker.json" <<EOF
{
Expand All @@ -25,4 +87,5 @@ EOF
trap 'rm -rf -- "$tmpdir"' EXIT

cd "$WORKDIR"
make release DOCKER_CREDS_FILE="$tmpdir/docker.json"
make release DOCKER_CREDS_FILE="$tmpdir/docker.json" \
GORELEASER_EXTRA_ARGS="${GORELEASER_SKIP:+--skip=${GORELEASER_SKIP}}"