From 7c40565b918db5e9731108f561a6994129d7275a Mon Sep 17 00:00:00 2001 From: Michael Fridman Date: Mon, 3 Jul 2023 22:39:22 -0400 Subject: [PATCH] fix: pre-built binary versions (#551) --- .goreleaser.yaml | 7 ++++--- CHANGELOG.md | 14 +++++++++++--- cmd/goose/main.go | 5 +---- scripts/release-notes.sh | 40 ++++++++++++++++++++++++++-------------- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 09e3b94..9c08e22 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,7 +5,6 @@ project_name: goose before: hooks: - # You may remove this if you don't use go modules. - go mod tidy builds: - env: @@ -20,14 +19,16 @@ builds: - amd64 - arm64 ldflags: - - -s -w + # The v prefix is stripped by goreleaser, so we need to add it back. + # https://goreleaser.com/customization/templates/#fnref:version-prefix + - "-s -w -X main.version=v{{ .Version }}" archives: - format: binary name_template: >- {{ .ProjectName }}_{{- tolower .Os }}_{{- if eq .Arch "amd64" }}x86_64{{- else }}{{ .Arch }}{{ end }} checksum: - name_template: 'checksums.txt' + name_template: "checksums.txt" snapshot: name_template: "{{ incpatch .Version }}-next" changelog: diff --git a/CHANGELOG.md b/CHANGELOG.md index bb1f2e6..9387181 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,23 @@ # Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project +adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + ## [Unreleased] +- Fix pre-built binary versioning and make small improvements to the build process. + ## [v3.13.1] - 2023-07-03 - Add pre-built binaries with GoReleaser and update the build process. ## [v3.13.0] - 2023-06-29 -- Update go.mod and retract all v3.12.X tags. They were accidentally pushed and contain a reference - to the wrong Go module. +- Add a changelog to the project, based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +- Update go.mod and retract all `v3.12.X` tags. They were accidentally pushed and contain a + reference to the wrong Go module. - Fix `up` and `up -allowing-missing` behavior. - Fix empty version in log output. - Add new `context.Context`-aware functions and methods, for both sql and go migrations. @@ -17,4 +25,4 @@ [Unreleased]: https://github.com/pressly/goose/compare/v3.13.1...HEAD [v3.13.1]: https://github.com/pressly/goose/compare/v3.13.0...v3.13.1 -[v3.13.0]: https://github.com/pressly/goose/compare/v3.11.2...v3.13.0 +[v3.13.0]: https://github.com/pressly/goose/releases/tag/v3.13.0 diff --git a/cmd/goose/main.go b/cmd/goose/main.go index af29bca..f3a58fd 100644 --- a/cmd/goose/main.go +++ b/cmd/goose/main.go @@ -35,12 +35,9 @@ var ( noVersioning = flags.Bool("no-versioning", false, "apply migration commands with no versioning, in file order, from directory pointed to") noColor = flags.Bool("no-color", false, "disable color output (NO_COLOR env variable supported)") ) + var ( - // These variables are populated via GoReleaser ldflags. - // See https://goreleaser.com/cookbooks/using-main.version/ version = "(devel)" - // commit = "none" - // date = "unknown" ) func main() { diff --git a/scripts/release-notes.sh b/scripts/release-notes.sh index ec7fed6..bbcb90b 100755 --- a/scripts/release-notes.sh +++ b/scripts/release-notes.sh @@ -11,7 +11,7 @@ fi version="$1" changelog_file="${2:-CHANGELOG.md}" -# Check if the CHANGELOG.md file exists +# Check if the changelog file exists if [ ! -f "$changelog_file" ]; then echo "Error: $changelog_file does not exist" exit 1 @@ -19,25 +19,37 @@ fi CAPTURE=0 items="" +# Read the changelog file line by line while IFS= read -r LINE; do - if [[ "${LINE}" == "##"* ]] && [[ "${CAPTURE}" -eq 1 ]]; then - break + # Stop capturing when we reach the next version sections + if [[ "${LINE}" == "##"* ]] && [[ "${CAPTURE}" -eq 1 ]]; then + break + fi + # Stop capturing when we reach the Unreleased section + if [[ "${LINE}" == "[Unreleased]"* ]]; then + break + fi + # Start capturing when we reach the specified version section + if [[ "${LINE}" == "## [${version}]"* ]] && [[ "${CAPTURE}" -eq 0 ]]; then + CAPTURE=1 + continue + fi + # Capture the lines between the specified version and the next version + if [[ "${CAPTURE}" -eq 1 ]]; then + # Ignore empty lines + if [[ -z "${LINE}" ]]; then + continue fi - if [[ "${LINE}" == "## [${version}]"* ]] && [[ "${CAPTURE}" -eq 0 ]]; then - CAPTURE=1 - continue - fi - if [[ "${CAPTURE}" -eq 1 ]]; then - items+="$(echo "${LINE}" | xargs)" - # if items is not empty, add a newline - if [[ -n "$items" ]]; then - items+=$'\n' - fi + items+="$(echo "${LINE}" | xargs)" + # Add a newline between each item + if [[ -n "$items" ]]; then + items+=$'\n' fi + fi done <"${changelog_file}" if [[ -n "$items" ]]; then - echo "${items%$'\n'}" + echo "${items%$'\n'}" else echo "No changelog items found for version $version" fi