Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: migrate to Sage-based release tooling #676

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
14 changes: 9 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ jobs:
- name: Make
run: make

- 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
run: make go-releaser snapshot=false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode
.DS_Store
.semrel/
25 changes: 25 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions .sage/sagefile.go → .sage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
}
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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