Skip to content

Commit

Permalink
ci: init Sage
Browse files Browse the repository at this point in the history
  • Loading branch information
odsod committed Mar 27, 2023
1 parent 8ca2570 commit 8a1ed7a
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2

updates:
- package-ecosystem: gomod
directory: .sage
schedule:
interval: weekly
5 changes: 5 additions & 0 deletions .sage/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module go.einride.tech/backstage/.sage

go 1.20

require go.einride.tech/sage v0.212.0
2 changes: 2 additions & 0 deletions .sage/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +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=
78 changes: 78 additions & 0 deletions .sage/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package main

import (
"context"

"go.einride.tech/sage/sg"
"go.einride.tech/sage/tools/sgconvco"
"go.einride.tech/sage/tools/sggit"
"go.einride.tech/sage/tools/sggo"
"go.einride.tech/sage/tools/sggolangcilint"
"go.einride.tech/sage/tools/sggolicenses"
"go.einride.tech/sage/tools/sggoreview"
"go.einride.tech/sage/tools/sgmarkdownfmt"
"go.einride.tech/sage/tools/sgyamlfmt"
)

func main() {
sg.GenerateMakefiles(
sg.Makefile{
Path: sg.FromGitRoot("Makefile"),
DefaultTarget: Default,
},
)
}

func Default(ctx context.Context) error {
sg.Deps(ctx, ConvcoCheck, FormatMarkdown, FormatYaml)
sg.Deps(ctx, GoLint, GoReview)
sg.Deps(ctx, GoTest)
sg.Deps(ctx, GoModTidy)
sg.Deps(ctx, GoLicenses, GitVerifyNoDiff)
return nil
}

func GoModTidy(ctx context.Context) error {
sg.Logger(ctx).Println("tidying Go module files...")
return sg.Command(ctx, "go", "mod", "tidy", "-v").Run()
}

func GoTest(ctx context.Context) error {
sg.Logger(ctx).Println("running Go tests...")
return sggo.TestCommand(ctx).Run()
}

func GoReview(ctx context.Context) error {
sg.Logger(ctx).Println("reviewing Go files...")
return sggoreview.Run(ctx)
}

func GoLint(ctx context.Context) error {
sg.Logger(ctx).Println("linting Go files...")
return sggolangcilint.Run(ctx)
}

func GoLicenses(ctx context.Context) error {
sg.Logger(ctx).Println("checking Go licenses...")
return sggolicenses.Check(ctx)
}

func FormatMarkdown(ctx context.Context) error {
sg.Logger(ctx).Println("formatting Markdown files...")
return sgmarkdownfmt.Command(ctx, "-w", ".").Run()
}

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

func ConvcoCheck(ctx context.Context) error {
sg.Logger(ctx).Println("checking git commits...")
return sgconvco.Command(ctx, "check", "origin/master..HEAD").Run()
}

func GitVerifyNoDiff(ctx context.Context) error {
sg.Logger(ctx).Println("verifying that git has no diff...")
return sggit.VerifyNoDiff(ctx)
}
84 changes: 84 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 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: convco-check
convco-check: $(sagefile)
@$(sagefile) ConvcoCheck

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

.PHONY: format-markdown
format-markdown: $(sagefile)
@$(sagefile) FormatMarkdown

.PHONY: format-yaml
format-yaml: $(sagefile)
@$(sagefile) FormatYaml

.PHONY: git-verify-no-diff
git-verify-no-diff: $(sagefile)
@$(sagefile) GitVerifyNoDiff

.PHONY: go-licenses
go-licenses: $(sagefile)
@$(sagefile) GoLicenses

.PHONY: go-lint
go-lint: $(sagefile)
@$(sagefile) GoLint

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

.PHONY: go-review
go-review: $(sagefile)
@$(sagefile) GoReview

.PHONY: go-test
go-test: $(sagefile)
@$(sagefile) GoTest
7 changes: 5 additions & 2 deletions catalog/client_entities_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"net/http"
"net/url"
)

// ListEntitiesRequest is the request to the [Client.ListEntities] method.
Expand All @@ -25,10 +26,12 @@ type ListEntitiesResponse struct {
// ListEntities lists entities in the catalog.
//
// See: https://backstage.io/docs/features/software-catalog/software-catalog-api/#get-entities
func (c *Client) ListEntities(ctx context.Context, request *ListEntitiesRequest) (*ListEntitiesResponse, error) {
func (c *Client) ListEntities(ctx context.Context, _ *ListEntitiesRequest) (*ListEntitiesResponse, error) {
const path = "/api/catalog/entities"
// TODO: Set request query parameters.
query := make(url.Values)
var rawEntities []json.RawMessage
if err := c.get(ctx, path, nil, func(response *http.Response) error {
if err := c.get(ctx, path, query, func(response *http.Response) error {
return json.NewDecoder(response.Body).Decode(&rawEntities)
}); err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion cmd/backstage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bytes"
"encoding/json"
"fmt"
"os"

"github.com/adrg/xdg"
"github.com/spf13/cobra"
"go.einride.tech/backstage/catalog"
"os"
)

func main() {
Expand Down

0 comments on commit 8a1ed7a

Please sign in to comment.