Skip to content

Commit

Permalink
ci: migrate to Sage-based semantic release
Browse files Browse the repository at this point in the history
  • Loading branch information
odsod committed Jul 15, 2024
1 parent 4cd2b8f commit 29fda15
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 24 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: Release
uses: go-semantic-release/action@v1.23
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
allow-initial-development-versions: true

- name: Fetch tags
run: git fetch --force --tags
- 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@v6.0.0
with:
version: latest
args: release --rm-dist
- name: Run GoReleaser
run: make go-releaser snapshot=false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 10 additions & 0 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,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 }}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea
tools/*/*/
bin
.vscode
.semrel
.generated-go-semantic-release-changelog.md
14 changes: 5 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ before:
- go mod download

builds:
- env:
- id: protoc-gen-typescript-http
binary: protoc-gen-typescript-http
dir: .
main: main.go
env:
- CGO_ENABLED=0
goos:
- linux
- 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,6 +8,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 @@ -83,3 +85,37 @@ func TypescriptLint(ctx context.Context) error {
"examples/proto/gen/typescript/**/*.ts",
).Run()
}

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 @@ -75,10 +75,27 @@ go-lint-fix: $(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: typescript-lint
typescript-lint: $(sagefile)
@$(sagefile) TypescriptLint
Expand Down

0 comments on commit 29fda15

Please sign in to comment.