Skip to content

Commit

Permalink
ci: migrate to mage-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
odsod committed Jan 16, 2022
1 parent dae05c5 commit 1324d62
Show file tree
Hide file tree
Showing 36 changed files with 325 additions and 392 deletions.
16 changes: 13 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
version: 2

updates:
- package-ecosystem: "gomod"
directory: "/"
- package-ecosystem: github-actions
directory: /
schedule:
interval: "daily"
interval: daily

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

- package-ecosystem: gomod
directory: .mage
schedule:
interval: daily
51 changes: 8 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,21 @@
name: CI
name: ci

on:
push:
branches:
- master
pull_request:
branches:
- "*"

# Allow dependabot to make releases
permissions:
contents: write
types: [opened, reopened, synchronize]

jobs:
make:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

- name: Setup Go
uses: actions/setup-go@v2
- uses: actions/[email protected]
with:
go-version: ^1.17
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v2.3.0
- name: Set up Go
uses: actions/setup-go@v2.1.5
with:
node-version: 12
go-version: ^1.17

- name: Make
run: make

release:
needs: [make]
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/[email protected]

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ^1.17

- name: Setup Node
uses: actions/[email protected]
with:
node-version: 12

- name: Run semantic-release
run: make semantic-release
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:
- uses: actions/[email protected]
with:
fetch-depth: 0

- name: Set up Go
uses: actions/[email protected]
with:
go-version: ^1.17

- name: Make
run: make

- name: Release
uses: go-semantic-release/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
allow-initial-development-versions: true
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.vscode
.idea
tools/*/*/
node_modules/
.mage/tools
15 changes: 15 additions & 0 deletions .mage/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module mage-tools

go 1.17

require (
github.com/magefile/mage v1.12.1
go.einride.tech/mage-tools v0.20.0
)

require (
github.com/go-logr/logr v1.2.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
14 changes: 14 additions & 0 deletions .mage/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/magefile/mage v1.12.1 h1:oGdAbhIUd6iKamKlDGVtU6XGdy5SgNuCWn7gCTgHDtU=
github.com/magefile/mage v1.12.1/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
go.einride.tech/mage-tools v0.20.0 h1:KBFsi2zxsHe+fF/syg68vRZA6JcoKgpk0LkRijuM7kU=
go.einride.tech/mage-tools v0.20.0/go.mod h1:pFpCBZ0U7a6862mks4y6v5xBkT4IhdrcJdEeTEjweMI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
85 changes: 85 additions & 0 deletions .mage/magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//go:build mage
// +build mage

package main

import (
"fmt"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"go.einride.tech/mage-tools/mgmake"
"go.einride.tech/mage-tools/mgpath"
"os"
"regexp"
"strings"

// mage:import
"go.einride.tech/mage-tools/targets/mgyamlfmt"

// mage:import
"go.einride.tech/mage-tools/targets/mgconvco"

// mage:import
"go.einride.tech/mage-tools/targets/mggo"

// mage:import
"go.einride.tech/mage-tools/targets/mggoreview"

// mage:import
"go.einride.tech/mage-tools/targets/mggolangcilint"

// mage:import
"go.einride.tech/mage-tools/targets/mgmarkdownfmt"

// mage:import
"go.einride.tech/mage-tools/targets/mggitverifynodiff"
)

func init() {
mgmake.GenerateMakefiles(
mgmake.Makefile{
Path: mgpath.FromGitRoot("Makefile"),
DefaultTarget: All,
},
)
}

func All() {
mg.Deps(
mg.F(mgconvco.ConvcoCheck, "origin/master..HEAD"),
mggolangcilint.GolangciLint,
mggoreview.Goreview,
mggo.GoTest,
mgmarkdownfmt.FormatMarkdown,
mgyamlfmt.FormatYaml,
)
mg.Deps(
ReadmeSnippet,
mggo.GoModTidy,
)
mg.SerialDeps(
mggitverifynodiff.GitVerifyNoDiff,
)
}

func ReadmeSnippet() error {
usage, err := sh.Output("go", "run", "./examples/cmd/grpc-server", "-help")
if err != nil {
return err
}
usage = strings.TrimSpace(usage)
usage = "<!-- BEGIN usage -->\n\n```\n" + usage
usage = usage + "\n```\n\n<!-- END usage -->"
readme, err := os.ReadFile("README.md")
if err != nil {
return err
}
usageRegexp, err := regexp.Compile(`(?ms)<!-- BEGIN usage -->.*<!-- END usage -->`)
if err != nil {
return err
}
if !usageRegexp.Match(readme) {
return fmt.Errorf("found no match for 'usage' snippet in README.md")
}
return os.WriteFile("README.md", usageRegexp.ReplaceAll(readme, []byte(usage)), 0o600)
}
10 changes: 10 additions & 0 deletions .mage/tools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mage_dir := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
mage_tools_path := $(mage_dir)/tools
mage := $(mage_tools_path)/mgmake/magefile

$(mage): $(mage_dir)/go.mod $(mage_dir)/*.go
@cd $(mage_dir) && go run go.einride.tech/mage-tools gen

.PHONY: mage-clean
mage-clean:
@git clean -fdx $(mage_dir)
Loading

0 comments on commit 1324d62

Please sign in to comment.