Skip to content

Commit

Permalink
feat: use Sage to release
Browse files Browse the repository at this point in the history
  • Loading branch information
odsod committed Jul 26, 2023
1 parent b45570a commit 8e386c7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
19 changes: 6 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,12 @@ jobs:
- name: Make
run: make

- name: Fetch tags
run: git fetch --force --tags

- name: Release
uses: go-semantic-release/[email protected]
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/[email protected]
with:
version: latest
args: release --rm-dist
- name: Run GoReleaser
run: make go-releaser snapshot=false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 0 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
36 changes: 36 additions & 0 deletions .sage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
}
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)"

0 comments on commit 8e386c7

Please sign in to comment.