From 8e386c7b3a8a1ecc854449cfe3e1bdc0fda38c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20S=C3=B6derlund?= Date: Wed, 26 Jul 2023 13:30:53 +0200 Subject: [PATCH] feat: use Sage to release --- .github/workflows/release.yml | 19 ++++++------------ .goreleaser.yml | 8 -------- .sage/main.go | 36 +++++++++++++++++++++++++++++++++++ Makefile | 17 +++++++++++++++++ 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c7742e1..3d9905f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,19 +16,12 @@ jobs: - name: Make run: make - - name: Fetch tags - run: git fetch --force --tags - - - name: Release - uses: go-semantic-release/action@v1.18 - 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 - uses: goreleaser/goreleaser-action@v3.1.0 - with: - version: latest - args: release --rm-dist + - name: Run GoReleaser + run: make go-releaser snapshot=false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml index fd0a8d6..edabfdd 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -13,14 +13,6 @@ builds: - windows - darwin -archives: - - replacements: - darwin: Darwin - linux: Linux - windows: Windows - 386: i386 - amd64: x86_64 - checksum: name_template: "checksums.txt" diff --git a/.sage/main.go b/.sage/main.go index 3eab470..49cde56 100644 --- a/.sage/main.go +++ b/.sage/main.go @@ -8,7 +8,9 @@ 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/sggoreview" + "go.einride.tech/sage/tools/sggosemanticrelease" "go.einride.tech/sage/tools/sggovulncheck" "go.einride.tech/sage/tools/sgmarkdownfmt" "go.einride.tech/sage/tools/sgyamlfmt" @@ -75,3 +77,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", + "--rm-dist", + } + 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 d842b49..52f9ba6 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,13 @@ 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-review go-review: $(sagefile) @$(sagefile) GoReview @@ -82,3 +89,13 @@ go-test: $(sagefile) .PHONY: go-vuln-check go-vuln-check: $(sagefile) @$(sagefile) GoVulnCheck + +.PHONY: semantic-release +semantic-release: $(sagefile) +ifndef repo + $(error missing argument repo="...") +endif +ifndef dry + $(error missing argument dry="...") +endif + @$(sagefile) SemanticRelease "$(repo)" "$(dry)"