Skip to content

Commit

Permalink
ci: add GitHub Actions workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
odsod committed Mar 27, 2023
1 parent 90ae891 commit 264ef4f
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 5 deletions.
12 changes: 11 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@ updates:
- package-ecosystem: gomod
directory: .sage
schedule:
interval: weekly
interval: monthly

- package-ecosystem: gomod
directory: /
schedule:
interval: monthly

- package-ecosystem: gomod
directory: cmd/backstage
schedule:
interval: monthly
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: ci

on:
pull_request:
branches:
- "*"

jobs:
make:
runs-on: ubuntu-latest
steps:
- name: Setup Sage
uses: einride/sage/actions/setup@master
with:
go-version: "1.20"

- 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 }}
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: release

on:
push:
branches: [master]

permissions: write-all

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Setup Sage
uses: einride/sage/actions/setup@master
with:
go-version: "1.20"

- name: Make
run: make

- 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 }}
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: backstage
binary: backstage
dir: ./cmd/backstage
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
21 changes: 21 additions & 0 deletions .sage/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"context"

"go.einride.tech/sage/sg"
)

type CmdBackstage sg.Namespace

func (CmdBackstage) Default(ctx context.Context) error {
sg.Deps(ctx, CmdBackstage.GoModTidy)
return nil
}

func (CmdBackstage) GoModTidy(ctx context.Context) error {
sg.Logger(ctx).Println("tidying Go module files...")
cmd := sg.Command(ctx, "go", "mod", "tidy", "-v")
cmd.Dir = sg.FromGitRoot("cmd", "backstage")
return cmd.Run()
}
2 changes: 1 addition & 1 deletion .sage/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module go.einride.tech/backstage/.sage

go 1.20

require go.einride.tech/sage v0.212.0
require go.einride.tech/sage v0.212.1
4 changes: 2 additions & 2 deletions .sage/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
go.einride.tech/sage v0.212.0 h1:0v5rBRBA/v1lX4hxf0EDSOhPDi366VXAybxh4Rhqu7w=
go.einride.tech/sage v0.212.0/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ=
go.einride.tech/sage v0.212.1 h1:RMJ61K2nQZyNjljhE5/cREpRjwuM5rLD3BbhOLheqbM=
go.einride.tech/sage v0.212.1/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ=
45 changes: 44 additions & 1 deletion .sage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"go.einride.tech/sage/tools/sggo"
"go.einride.tech/sage/tools/sggolangcilint"
"go.einride.tech/sage/tools/sggolicenses"
"go.einride.tech/sage/tools/sggoreleaser"
"go.einride.tech/sage/tools/sggoreview"
"go.einride.tech/sage/tools/sggosemanticrelease"
"go.einride.tech/sage/tools/sgmarkdownfmt"
"go.einride.tech/sage/tools/sgyamlfmt"
)
Expand All @@ -20,11 +22,18 @@ func main() {
Path: sg.FromGitRoot("Makefile"),
DefaultTarget: Default,
},

sg.Makefile{
Path: sg.FromGitRoot("cmd", "backstage", "Makefile"),
Namespace: CmdBackstage{},
DefaultTarget: CmdBackstage.Default,
},
)
}

func Default(ctx context.Context) error {
sg.Deps(ctx, ConvcoCheck, FormatMarkdown, FormatYaml)
sg.Deps(ctx, CmdBackstage.Default)
sg.Deps(ctx, GoLint, GoReview)
sg.Deps(ctx, GoTest)
sg.Deps(ctx, GoModTidy)
Expand Down Expand Up @@ -63,7 +72,7 @@ func FormatMarkdown(ctx context.Context) error {
}

func FormatYaml(ctx context.Context) error {
sg.Logger(ctx).Println("formatting Yaml files...")
sg.Logger(ctx).Println("formatting YAML files...")
return sgyamlfmt.Run(ctx)
}

Expand All @@ -76,3 +85,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()
}
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,31 @@ 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

.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: cmd-backstage
cmd-backstage:
$(MAKE) -C cmd/backstage -f Makefile
52 changes: 52 additions & 0 deletions cmd/backstage/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Code generated by go.einride.tech/sage. DO NOT EDIT.
# To learn more, see ../../.sage/main.go and https://github.com/einride/sage.

.DEFAULT_GOAL := default

cwd := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
sagefile := $(abspath $(cwd)/../../.sage/bin/sagefile)

# Setup Go.
go := $(shell command -v go 2>/dev/null)
export GOWORK ?= off
ifndef go
SAGE_GO_VERSION ?= 1.18.4
export GOROOT := $(abspath $(cwd)/../../.sage/tools/go/$(SAGE_GO_VERSION)/go)
export PATH := $(PATH):$(GOROOT)/bin
go := $(GOROOT)/bin/go
os := $(shell uname | tr '[:upper:]' '[:lower:]')
arch := $(shell uname -m)
ifeq ($(arch),x86_64)
arch := amd64
endif
$(go):
$(info installing Go $(SAGE_GO_VERSION)...)
@mkdir -p $(dir $(GOROOT))
@curl -sSL https://go.dev/dl/go$(SAGE_GO_VERSION).$(os)-$(arch).tar.gz | tar xz -C $(dir $(GOROOT))
@touch $(GOROOT)/go.mod
@chmod +x $(go)
endif

.PHONY: $(sagefile)
$(sagefile): $(go)
@cd ../../.sage && $(go) mod tidy && $(go) run .

.PHONY: sage
sage:
@$(MAKE) $(sagefile)

.PHONY: update-sage
update-sage: $(go)
@cd ../../.sage && $(go) get -d go.einride.tech/sage@latest && $(go) mod tidy && $(go) run .

.PHONY: clean-sage
clean-sage:
@git clean -fdx ../../.sage/tools ../../.sage/bin ../../.sage/build

.PHONY: default
default: $(sagefile)
@$(sagefile) CmdBackstage:Default

.PHONY: go-mod-tidy
go-mod-tidy: $(sagefile)
@$(sagefile) CmdBackstage:GoModTidy

0 comments on commit 264ef4f

Please sign in to comment.