Skip to content

Commit

Permalink
Switch to GoReleaser
Browse files Browse the repository at this point in the history
GitHub releaser stopped working.
  • Loading branch information
jschaf committed Jul 17, 2022
1 parent c97b1bd commit 2762115
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 64 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*.iml
/.idea/
/dist/
/dist/
.DS_Store
21 changes: 1 addition & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,10 @@ update-acceptance-test:
lint:
golangci-lint run

.PHONY: binary-all
binary-all: binary-darwin-amd64 binary-darwin-arm64 binary-linux-amd64 binary-windows-amd64

.PHONY: dist-dir
dist-dir:
mkdir -p dist

.PHONY: binary-darwin-amd64
binary-darwin-amd64: dist-dir
GOOS=darwin GOARCH=amd64 go build ${ldflags} -o dist/pggen-darwin-amd64 ./cmd/pggen

.PHONY: binary-darwin-arm64
binary-darwin-arm64: dist-dir
GOOS=darwin GOARCH=arm64 go build ${ldflags} -o dist/pggen-darwin-arm64 ./cmd/pggen

.PHONY: binary-linux-amd64
binary-linux-amd64: dist-dir
GOOS=linux GOARCH=amd64 go build ${ldflags} -o dist/pggen-linux-amd64 ./cmd/pggen

.PHONY: binary-windows-amd64
binary-windows-amd64: dist-dir
GOOS=windows GOARCH=amd64 go build ${ldflags} -o dist/pggen-windows-amd64.exe ./cmd/pggen

.PHONY: release
release: binary-all
release:
./script/release.sh
25 changes: 25 additions & 0 deletions script/.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
main: ./cmd/pggen
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}}
archives:
- files:
- none*
format: tar.xz
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
checksum:
disable: true
changelog:
sort: asc
use: github-native
63 changes: 20 additions & 43 deletions script/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,31 @@ if [[ -z "${GITHUB_TOKEN:-}" ]]; then
exit 1
fi

day="$(date '+%Y-%m-%d')"
echo "preparing assets for release $day"

targets=(
darwin-amd64
darwin-arm64
linux-amd64
windows-amd64
)

# Create zipped binaries.
# chdir into dist so zip files sit at root of zip instead of in 'dist/pggen'.
pushd dist >/dev/null
for target in "${targets[@]}"; do
binary="pggen-${target}"
if [[ "$binary" == *windows* ]]; then
binary+='.exe'
fi
echo -n "zipping ${binary} ... "
zip --quiet -9 "pggen-${target}.zip" "${binary}"
echo "done"
done
popd >/dev/null

# Download github-release if necessary.
GH_REL_BIN='github-release'
if ! command -v "$GH_REL_BIN"; then
# Download github-release if necessary. Only used to delete existing releases.
# We use GoReleaser to create new releases.
githubRelease='github-release'
if ! command -v "$githubRelease"; then
echo 'downloading github-release'
GH_REL_BIN="$(mktemp)"
githubRelease="$(mktemp)"
url=https://github.com/github-release/github-release/releases/download/v0.10.0/linux-amd64-github-release.bz2
curl -L --fail --silent "${url}" | bzip2 -dc >"$GH_REL_BIN"
chmod +x "$GH_REL_BIN"
curl -L --fail --silent "${url}" | bzip2 -dc >"$githubRelease"
chmod +x "$githubRelease"
else
echo 'github-release already downloaded'
fi

goReleaser='goreleaser'
if ! command -v "$goReleaser"; then
goReleaserUrl='https://github.com/goreleaser/goreleaser/releases/download/v1.10.2/goreleaser_Linux_x86_64.tar.gz'
curl -L --fail --silent "${goReleaserUrl}" | tar xvz >"$goReleaser"
chmod +x "$goReleaser"
else
echo 'goreleaser already downloaded'
fi

day="$(date '+%Y-%m-%d')"

# Delete the remote tag since we're creating a new release tagged today.
echo 'deleting existing release tag'
git push origin ":refs/tags/$day" 2>/dev/null
Expand All @@ -53,20 +42,8 @@ git push origin "$day"
# Delete any existing releases. We only support 1 release per day.
# Ignore errors if we try to delete a release that doesn't exist.
echo 'deleting existing releases'
"${GH_REL_BIN}" delete --user jschaf --repo pggen --tag "$day" || true
"$githubRelease" delete --user jschaf --repo pggen --tag "$day" || true

echo
echo "creating release $day"
"${GH_REL_BIN}" release --user jschaf --repo pggen --tag "$day" --name "$day"

# Upload each of the zipped binaries.
for target in "${targets[@]}"; do
echo -n "uploading pggen-${target}.zip ... "
"${GH_REL_BIN}" upload \
--user jschaf \
--repo pggen \
--tag "$day" \
--name "pggen-${target}.zip" \
--file "dist/pggen-${target}.zip"
echo "done"
done
goreleaser release --config ./script/.goreleaser.yaml --rm-dist

0 comments on commit 2762115

Please sign in to comment.