Skip to content

Commit

Permalink
init (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
xh3b4sd committed Sep 28, 2023
1 parent 594984f commit ef0a24e
Show file tree
Hide file tree
Showing 136 changed files with 7,789 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Do not edit. This file was generated via the "workflow" command line tool.
# More information about the tool can be found at github.com/xh3b4sd/workflow.
#
# workflow create dependabot -b master -r xh3b4sd
#

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-patch"]
open-pull-requests-limit: 10
reviewers:
- "xh3b4sd"
schedule:
interval: "daily"
time: "04:00"
target-branch: "master"

- package-ecosystem: "gomod"
directory: "/"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-patch"]
open-pull-requests-limit: 10
reviewers:
- "xh3b4sd"
schedule:
interval: "daily"
time: "04:00"
target-branch: "master"
43 changes: 43 additions & 0 deletions .github/workflows/go-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Do not edit. This file was generated via the "workflow" command line tool.
# More information about the tool can be found at github.com/xh3b4sd/workflow.
#
# workflow create golang
#

name: "go-build"

on: "push"

jobs:
go-build:
runs-on: "ubuntu-latest"
steps:

- name: "Setup Git Project"
uses: "actions/checkout@v4"

- name: "Setup Go Env"
uses: "actions/setup-go@v4"
with:
cache: true
go-version: "1.21.1"

- name: "Check Go Dependencies"
run: |
go mod tidy
git diff --exit-code
- name: "Check Go Tests"
run: |
go test ./... -race
- name: "Check Go Formatting"
run: |
test -z $(gofmt -l -s .)
- name: "Check Go Linters"
run: |
curl -LOs https://github.com/golangci/golangci-lint/releases/download/v1.54.2/golangci-lint-1.54.2-linux-amd64.tar.gz
tar -xzf golangci-lint-1.54.2-linux-amd64.tar.gz
./golangci-lint-1.54.2-linux-amd64/golangci-lint run
38 changes: 38 additions & 0 deletions .github/workflows/go-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Do not edit. This file was generated via the "workflow" command line tool.
# More information about the tool can be found at github.com/xh3b4sd/workflow.
#
# workflow create releasego -n workflow -s gitSHA -t version
#

name: "go-release"

on:
push:
tags:
- "v*.*.*"

jobs:
release:
runs-on: "ubuntu-latest"
steps:
- name: "Setup Git Project"
uses: "actions/checkout@v4"

- name: "Setup Go Env"
uses: "actions/setup-go@v4"
with:
cache: true
go-version: "1.21.1"

- name: "Cross Compile Binaries"
run: |
GOOS=darwin GOARCH=amd64 go build -o workflow-darwin-amd64 -ldflags="-X 'github.com/${{ github.repository_owner }}/workflow/pkg/project.gitSHA=${{ github.sha }}' -X 'github.com/${{ github.repository_owner }}/workflow/pkg/project.version=${{ github.ref_name }}'"
GOOS=linux GOARCH=amd64 go build -o workflow-linux-amd64 -ldflags="-X 'github.com/${{ github.repository_owner }}/workflow/pkg/project.gitSHA=${{ github.sha }}' -X 'github.com/${{ github.repository_owner }}/workflow/pkg/project.version=${{ github.ref_name }}'"
- name: "Upload To Github"
uses: "softprops/action-gh-release@v1"
with:
files: |
workflow-darwin-amd64
workflow-linux-amd64
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.vscode/
/.DS_Store
/workflow
!pkg/**
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# workflow

Command line tool for generating github workflows. Certain optinionated design
decisions have been made which limits the workflow generation and other tooling
to the github ecosystem. All commands generating workflows must be executed
within the root directory of the repository the desired workflows should be
generated for.



### Create Workflows

```
$ workflow create -h
Create github workflows and config files.
Usage:
workflow create [flags]
workflow create [command]
Available Commands:
cfmtest Create a conformance workflow for e.g. running tests.
dependabot Create a dependabot workflow for e.g. golang and docker.
dockergo Create a docker workflow for building and pushing docker images of golang apps.
dockerts Create a docker workflow for building and pushing docker images of typescript apps.
dsmupdate Create a mutating workflow for e.g. app versions.
dsmverify Create a validation workflow for e.g. checking consistency.
golang Create a golang workflow for e.g. running tests and checking formatting.
npm Create a npm workflow for e.g. building and publishing npm packages.
pbfgo Create a protocol buffer workflow for golang code generation.
pbflint Create a protocol buffer workflow for schema validation.
pbfts Create a protocol buffer workflow for typescript code generation.
redigo Create a golang workflow for e.g. running redis conformance tests.
releasego Create a golang workflow for e.g. uploading cross compiled release assets.
releases3 Create a golang workflow for e.g. uploading cross compiled release assets.
typescript Create a typescript workflow for e.g. building and formatting typescript code.
Flags:
-h, --help help for create
Use "workflow create [command] --help" for more information about a command.
```

```
$ workflow create dependabot -h
Create a dependabot workflow for e.g. golang and docker.
Usage:
workflow create dependabot [flags]
Flags:
-b, --branch string Dependabort target branch to merge pull requests into. (default "main")
-h, --help help for dependabot
-r, --reviewers strings Reviewers assigned to dependabot PRs, e.g. xh3b4sd. Works with github usernames and teams.
-g, --version-golang string Golang version to use in, e.g. workflow files. (default "1.15.2")
```



### Update Workflows


```
$ workflow update all -h
Update all github workflows to the latest version. When creating a new
workflow file the original command instruction in form of os.Args is written
to the header of the workflow file. A typical workflow file header looks like
the following.
#
# Do not edit. This file was generated via the "workflow" command line tool.
# More information about the tool can be found at github.com/xh3b4sd/workflow.
#
# workflow create dependabot -r xh3b4sd
#
This information of the executable command is used to make workflow updates
reproducible. All workflow files within the github specific workflow
directory are inspected when collecting command instructions. Once all
commands are known they are executed dynamically while new behaviour is
applied.
.github/workflows/
Usage:
workflow update all [flags]
Flags:
-h, --help help for all
```
106 changes: 106 additions & 0 deletions cmd/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package cmd

import (
"github.com/spf13/cobra"
"github.com/xh3b4sd/logger"
"github.com/xh3b4sd/tracer"

"github.com/xh3b4sd/workflow/cmd/completion"
"github.com/xh3b4sd/workflow/cmd/create"
"github.com/xh3b4sd/workflow/cmd/update"
"github.com/xh3b4sd/workflow/cmd/version"
"github.com/xh3b4sd/workflow/pkg/project"
)

var (
name = project.Name()
short = project.Description()
long = project.Description()
)

type Config struct {
Logger logger.Interface
}

func New(config Config) (*cobra.Command, error) {
if config.Logger == nil {
return nil, tracer.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}

var err error

var completionCmd *cobra.Command
{
c := completion.Config{
Logger: config.Logger,
}

completionCmd, err = completion.New(c)
if err != nil {
return nil, tracer.Mask(err)
}
}

var createCmd *cobra.Command
{
c := create.Config{
Logger: config.Logger,
}

createCmd, err = create.New(c)
if err != nil {
return nil, tracer.Mask(err)
}
}

var versionCmd *cobra.Command
{
c := version.Config{
Logger: config.Logger,
}

versionCmd, err = version.New(c)
if err != nil {
return nil, tracer.Mask(err)
}
}

var updateCmd *cobra.Command
{
c := update.Config{
Logger: config.Logger,
}

updateCmd, err = update.New(c)
if err != nil {
return nil, tracer.Mask(err)
}
}

var c *cobra.Command
{
r := &runner{
logger: config.Logger,
}

c = &cobra.Command{
Use: name,
Short: short,
Long: long,
RunE: r.Run,
// We slience errors because we do not want to see spf13/cobra printing.
// The errors returned by the commands will be propagated to the main.go
// anyway, where we have custom error printing for the command line
// tool.
SilenceErrors: true,
SilenceUsage: true,
}

c.AddCommand(completionCmd)
c.AddCommand(createCmd)
c.AddCommand(updateCmd)
c.AddCommand(versionCmd)
}

return c, nil
}
55 changes: 55 additions & 0 deletions cmd/completion/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package completion

import (
"github.com/spf13/cobra"
"github.com/xh3b4sd/logger"
"github.com/xh3b4sd/tracer"
)

const (
name = "completion"
short = "Generate shell completions."
long = `Supported positional arguments and respective shell completions are
as follows.
bash
fish
powershell
zsh
Generating zsh completion for Oh My Zsh can be done by writing the
generated completion to the custom plugin folder.
mkdir -p ~/.oh-my-zsh/custom/plugins/workflow && workflow completion zsh > ~/.oh-my-zsh/custom/plugins/workflow/_workflow
`
)

type Config struct {
Logger logger.Interface
}

func New(config Config) (*cobra.Command, error) {
if config.Logger == nil {
return nil, tracer.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}

var c *cobra.Command
{
r := &runner{
logger: config.Logger,
}

c = &cobra.Command{
Use: name,
Short: short,
Long: long,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "fish", "powershell", "zsh"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
RunE: r.Run,
}
}

return c, nil
}
15 changes: 15 additions & 0 deletions cmd/completion/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package completion

import (
"errors"

"github.com/xh3b4sd/tracer"
)

var invalidConfigError = &tracer.Error{
Kind: "invalidConfigError",
}

func IsInvalidConfig(err error) bool {
return errors.Is(err, invalidConfigError)
}
Loading

0 comments on commit ef0a24e

Please sign in to comment.