From d61d3cbfd8e3454b5f4e5e4211f3447622e68372 Mon Sep 17 00:00:00 2001 From: Jose Luis Vazquez Gonzalez Date: Mon, 13 Dec 2021 11:50:16 +0100 Subject: [PATCH] Add goreleaser config and bump version support Releases are cut manually by calling bump-version.sh Signed-off-by: Jose Luis Vazquez Gonzalez --- .github/workflows/release.yml | 27 +++++++++++++++++++++++++++ .gitignore | 4 ++++ .goreleaser.yml | 35 +++++++++++++++++++++++++++++++++++ bump-version.sh | 13 +++++++++++++ next-semver/go.mod | 5 +++++ next-semver/go.sum | 2 ++ next-semver/main.go | 19 +++++++++++++++++++ 7 files changed, 105 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml create mode 100755 bump-version.sh create mode 100644 next-semver/go.mod create mode 100644 next-semver/go.sum create mode 100644 next-semver/main.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..660d0e03 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,27 @@ +name: release + +on: + push: + tags: + - "v*.*.*" + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Unshallow + run: git fetch --prune --unshallow + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: 1.17.x + - name: Release + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 77b12d4c..4e11a5f5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ build/* .idea *.iml + +dist/ + +next-semver/next-semver diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..1b37c74d --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,35 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +env: + - VERSION="{{ .Version }}" +before: + hooks: + - make build +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + binary: relok8s +archives: + - replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 + name_template: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}" + files: + - README.md +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/bump-version.sh b/bump-version.sh new file mode 100755 index 00000000..c390a6d8 --- /dev/null +++ b/bump-version.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -euo pipefail + +old_version=$(cat version) +(cd next-semver && go build .) +version=$(./next-semver/next-semver "${old_version}") +echo "${version}" > version +git add version +git commit -s -m "Bump version to ${version}" +git push +git tag "v${version}" && git push origin "v${version}" + diff --git a/next-semver/go.mod b/next-semver/go.mod new file mode 100644 index 00000000..cf77a39d --- /dev/null +++ b/next-semver/go.mod @@ -0,0 +1,5 @@ +module example.com/versions/next-semver + +go 1.17 + +require github.com/Masterminds/semver/v3 v3.1.1 // indirect diff --git a/next-semver/go.sum b/next-semver/go.sum new file mode 100644 index 00000000..471bde90 --- /dev/null +++ b/next-semver/go.sum @@ -0,0 +1,2 @@ +github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= +github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= diff --git a/next-semver/main.go b/next-semver/main.go new file mode 100644 index 00000000..f200da38 --- /dev/null +++ b/next-semver/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "os" + + semverv3 "github.com/Masterminds/semver/v3" +) + +func main() { + if len(os.Args) != 2 { + fmt.Printf("Usage: %s {semver-version}\n$ %s 1.2.3\n", os.Args[0], os.Args[0]) + os.Exit(-1) + } + v := os.Args[1] + version := semverv3.MustParse(v) + next := version.IncPatch() + fmt.Println(next) +}