Skip to content

Commit 51a487e

Browse files
authored
Merge pull request #1235 from planetscale/idempotent-release
Ensure `script/release.sh` is idempotent
2 parents 936ce05 + ad43183 commit 51a487e

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ project_name: pscale
22
version: 2
33
release:
44
prerelease: auto # don't publish release with -rc1,-pre, etc suffixes
5+
replace_existing_artifacts: true
56
before:
67
hooks:
78
- go mod tidy

script/release.sh

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set -eu
44

5+
DRY_RUN="${DRY_RUN:-false}"
56
WORKDIR=$(pwd)
67

78
if [ -z "${GORELEASER_CURRENT_TAG:-}" ]; then
@@ -10,6 +11,67 @@ if [ -z "${GORELEASER_CURRENT_TAG:-}" ]; then
1011
fi
1112
export GORELEASER_CURRENT_TAG
1213

14+
VERSION="${GORELEASER_CURRENT_TAG#v}"
15+
16+
all_targets=(docker homebrew scoop aur)
17+
skip=()
18+
19+
if docker manifest inspect "planetscale/pscale:${GORELEASER_CURRENT_TAG}" >/dev/null 2>&1; then
20+
echo "==> Docker image already exists, skipping docker"
21+
skip+=(docker)
22+
fi
23+
24+
if gh api "repos/planetscale/homebrew-tap/contents/Formula/pscale.rb" --jq '.content' 2>/dev/null \
25+
| base64 --decode 2>/dev/null | grep -q "version \"${VERSION}\""; then
26+
echo "==> Homebrew formula already up to date, skipping homebrew"
27+
skip+=(homebrew)
28+
fi
29+
30+
if gh api "repos/planetscale/scoop-bucket/contents/pscale.json" --jq '.content' 2>/dev/null \
31+
| base64 --decode 2>/dev/null | grep -q "\"version\": \"${VERSION}\""; then
32+
echo "==> Scoop manifest already up to date, skipping scoop"
33+
skip+=(scoop)
34+
fi
35+
36+
if curl -fsSL --connect-timeout 5 "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=pscale-cli-bin" 2>/dev/null \
37+
| grep -q "pkgver=${VERSION}"; then
38+
echo "==> AUR package already up to date, skipping aur"
39+
skip+=(aur)
40+
fi
41+
42+
should_skip() {
43+
local target=$1
44+
for s in "${skip[@]+"${skip[@]}"}"; do
45+
[ "$target" = "$s" ] && return 0
46+
done
47+
return 1
48+
}
49+
50+
run=()
51+
echo ""
52+
echo "==> Release plan for ${GORELEASER_CURRENT_TAG}:"
53+
for target in "${all_targets[@]}"; do
54+
if should_skip "$target"; then
55+
echo " skip ${target}"
56+
else
57+
echo " run ${target}"
58+
run+=("$target")
59+
fi
60+
done
61+
echo ""
62+
63+
if [ ${#run[@]} -eq 0 ]; then
64+
echo "==> All targets already published, nothing to do."
65+
exit 0
66+
fi
67+
68+
if [ "$DRY_RUN" = "true" ]; then
69+
echo "==> Dry run, exiting."
70+
exit 0
71+
fi
72+
73+
GORELEASER_SKIP=$(IFS=,; echo ${skip[*]+"${skip[*]}"})
74+
1375
tmpdir=$(mktemp -d)
1476
cat >"$tmpdir/docker.json" <<EOF
1577
{
@@ -25,4 +87,5 @@ EOF
2587
trap 'rm -rf -- "$tmpdir"' EXIT
2688

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

0 commit comments

Comments
 (0)