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 7, 2022
1 parent 762bfd8 commit 5b5fae3
Show file tree
Hide file tree
Showing 44 changed files with 264 additions and 383 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ updates:
directory: /
schedule:
interval: daily

- package-ecosystem: gomod
directory: .mage
schedule:
interval: daily
57 changes: 9 additions & 48 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,27 @@
name: CI
name: ci

on:
push:
branches:
- master
pull_request:
branches:
- "*"
types: [opened, reopened, synchronize]

jobs:
make:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.4.0

- name: Setup Go
uses: actions/setup-go@v2
- uses: actions/checkout@v2.4.0
with:
go-version: ~1.16
fetch-depth: 0

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

- name: Make
run: make

- name: Report Code Coverage
uses: codecov/codecov-action@v2.1.0
with:
file: ./build/coverage/go-test.txt
file: .mage/tools/go/coverage/go-test.txt
fail_ci_if_error: true

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

steps:
- name: Checkout
uses: actions/checkout@v2.4.0

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ~1.16

- name: Setup Node
uses: actions/setup-node@v2.5.1
with:
node-version: 12

- name: Run semantic-release
run: make semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run goreleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: release

on:
push:
branches: [master]

permissions: write-all

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.4.0
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2.1.5
with:
go-version: ^1.17

- name: Make
run: make

- name: Release
uses: go-semantic-release/action@v1.15.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
allow-initial-development-versions: true

- name: Run goreleaser
uses: goreleaser/goreleaser-action@v2.8.0
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
.idea
tools/*/*/
node_modules/
build/
.mage/tools/
23 changes: 0 additions & 23 deletions .golangci.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .mage/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module mage-tools

go 1.17

require (
github.com/magefile/mage v1.12.1
go.einride.tech/mage-tools v0.11.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
)
10 changes: 10 additions & 0 deletions .mage/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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.11.0 h1:rLl9vam1K4wEGy+lp8Ry9Zdm2s2+q0q3h73yW7JvcL4=
go.einride.tech/mage-tools v0.11.0/go.mod h1:Z6r1+t7AAzM8G59LtsD8nM4anNGDHyo2lioYRXL8Ggs=
42 changes: 42 additions & 0 deletions .mage/magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//go:build mage
// +build mage

package main

import (
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"

// 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/mggolangcilint"

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

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

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

func SpannerGenerate() error {
return sh.RunV("go", "run", ".", "generate")
}
12 changes: 12 additions & 0 deletions .mage/mgmain_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .mage/mgmake_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions .mage/tools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
mage_folder := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
mage_generated_path := $(mage_folder)/tools/mgmake
mage_tools_path := $(mage_folder)/tools
mage_targets_file := $(mage_generated_path)/targets.mk
mage := $(mage_generated_path)/local-mage
mgmake := $(mage_folder)/mgmake_gen.go
mgmain := $(mage_folder)/mgmain_gen.go

define mgmake_content
// Code generated by Mage-tools. DO NOT EDIT.
//go:build mage
// +build mage

package main

// mage:import
import _ "go.einride.tech/mage-tools/mgmake"
endef

define mgmain_content
// Code generated by Mage-tools. DO NOT EDIT.
//go:build ignore
// +build ignore

package main

import (
"os"
"github.com/magefile/mage/mage"
)

func main() { os.Exit(mage.Main()) }
endef

include $(mage_targets_file)

$(mage_targets_file): $(mage_folder)/go.mod $(shell find $(mage_folder)/.. -type f -name '*.go')
@git clean -fdx $(mage_generated_path)
@mkdir -p $(mage_generated_path)
$(file > $(mgmake),$(mgmake_content))
$(file > $(mgmain),$(mgmain_content))
@cd $(mage_folder) && \
go mod tidy && \
go run $(notdir $(mgmain)) -compile $(mage) && \
$(mage) generateMakefile $(@)

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

0 comments on commit 5b5fae3

Please sign in to comment.