diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81726d2..14a2a3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,3 +15,13 @@ jobs: - name: Make run: make + + - name: Dry-run semantic-release + run: make semantic-release repo=${{ github.repository }} dry=true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Dry-run GoReleaser + run: make go-releaser snapshot=true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4048bd5..0cb67a8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,8 +18,12 @@ jobs: - name: Make run: make - - name: Release - uses: go-semantic-release/action@v1.21 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - allow-initial-development-versions: true + - name: Run semantic-release + run: make semantic-release repo=${{ github.repository }} dry=false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Run GoReleaser + run: make go-releaser snapshot=false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index d4d9525..713d047 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea .vscode .DS_Store +.semrel/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..c8db945 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,25 @@ +before: + hooks: + - go mod download + +builds: + - id: protoc-gen-go-iam + binary: protoc-gen-go-iam + dir: ./cmd/protoc-gen-go-iam + main: main.go + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + +checksum: + name_template: "checksums.txt" + +snapshot: + name_template: "{{ .Tag }}-next" + +release: + github: + prerelease: auto diff --git a/.sage/sagefile.go b/.sage/main.go similarity index 65% rename from .sage/sagefile.go rename to .sage/main.go index 8893f0b..6bec43b 100644 --- a/.sage/sagefile.go +++ b/.sage/main.go @@ -9,6 +9,8 @@ import ( "go.einride.tech/sage/tools/sggit" "go.einride.tech/sage/tools/sggo" "go.einride.tech/sage/tools/sggolangcilint" + "go.einride.tech/sage/tools/sggoreleaser" + "go.einride.tech/sage/tools/sggosemanticrelease" "go.einride.tech/sage/tools/sgmdformat" "go.einride.tech/sage/tools/sgyamlfmt" ) @@ -73,3 +75,37 @@ func GitVerifyNoDiff(ctx context.Context) error { sg.Logger(ctx).Println("verifying that git has no diff...") return sggit.VerifyNoDiff(ctx) } + +func SemanticRelease(ctx context.Context, repo string, dry bool) error { + sg.Logger(ctx).Println("triggering release...") + args := []string{ + "--allow-initial-development-versions", + "--allow-no-changes", + "--ci-condition=default", + "--provider=github", + "--provider-opt=slug=" + repo, + } + if dry { + args = append(args, "--dry") + } + return sggosemanticrelease.Command(ctx, args...).Run() +} + +func GoReleaser(ctx context.Context, snapshot bool) error { + sg.Logger(ctx).Println("building Go binary releases...") + if err := sggit.Command(ctx, "fetch", "--force", "--tags").Run(); err != nil { + return err + } + args := []string{ + "release", + "--clean", + } + if len(sggit.Tags(ctx)) == 0 && !snapshot { + sg.Logger(ctx).Printf("no git tag found for %s, forcing snapshot mode", sggit.ShortSHA(ctx)) + snapshot = true + } + if snapshot { + args = append(args, "--snapshot") + } + return sggoreleaser.Command(ctx, args...).Run() +} diff --git a/Makefile b/Makefile index 8cb1938..2bcfee0 100644 --- a/Makefile +++ b/Makefile @@ -71,10 +71,27 @@ go-lint: $(sagefile) go-mod-tidy: $(sagefile) @$(sagefile) GoModTidy +.PHONY: go-releaser +go-releaser: $(sagefile) +ifndef snapshot + $(error missing argument snapshot="...") +endif + @$(sagefile) GoReleaser "$(snapshot)" + .PHONY: go-test go-test: $(sagefile) @$(sagefile) GoTest +.PHONY: semantic-release +semantic-release: $(sagefile) +ifndef repo + $(error missing argument repo="...") +endif +ifndef dry + $(error missing argument dry="...") +endif + @$(sagefile) SemanticRelease "$(repo)" "$(dry)" + .PHONY: proto proto: $(MAKE) -C proto -f Makefile