diff --git a/docs/plugins/repo-scaffolding.md b/docs/plugins/repo-scaffolding.md index 573525d71..aab2e21e6 100644 --- a/docs/plugins/repo-scaffolding.md +++ b/docs/plugins/repo-scaffolding.md @@ -76,16 +76,26 @@ This configuration is used for template render, It has default variables listed } ``` +## Outputs + +This plugin has three outputs: + +- `owner` +- `repo` +- `repoURL` + + ## Examples ### official scaffolding repo config These repos are official scaffolding repo to use for `sourceRepo` config, You can use these repo directly or just create one for yourself. -| language | org | repo | -| ---- | ---- |---- | -| Golang | devstream-io | dtm-scaffolding-golang | -| Java Spring | spring-guides | gs-spring-boot | +| language | org | repo | +|-------------|---------------|----------------------------| +| Golang | devstream-io | dtm-scaffolding-golang | +| Golang | devstream-io | dtm-scaffolding-golang-cli | +| Java Spring | spring-guides | gs-spring-boot | ### Golang @@ -111,6 +121,27 @@ tools: This config will create `dtm-test-golang` repo for user test_owner in GitHub, and the variable ImageRepo will be used for template render. +### Golang CLI + +```yaml +tools: + - name: repo-scaffolding + instanceID: golang-cli-scaffolding + options: + destinationRepo: + owner: test_owner + org: "" + repo: dtm-test-golang-cli + branch: main + repoType: github + sourceRepo: + org: devstream-io + repo: dtm-scaffolding-golang-cli + repoType: github +``` + +This config will create `dtm-test-golang-cli` repo for user test_owner in GitHub. + ### Java Spring ```yaml @@ -133,11 +164,3 @@ tools: ``` this config will create `dtm-test-java` repo for user test_owner in GitHub. - -## Outputs - -This plugin has three outputs: - -- `owner` -- `repo` -- `repoURL` diff --git a/docs/plugins/repo-scaffolding.zh.md b/docs/plugins/repo-scaffolding.zh.md index dff0afd85..fc0716c6d 100644 --- a/docs/plugins/repo-scaffolding.zh.md +++ b/docs/plugins/repo-scaffolding.zh.md @@ -74,16 +74,25 @@ } ``` +## Outputs + +这个插件有以下三个输出: + +- `owner` +- `repo` +- `repoURL` + ## 示例 ### 官方支持脚手架项目 以下仓库是用于在 `sourceRepo` 设置的官方脚手架仓库,你可以使用这些仓库或者创建自己的脚手架仓库。 -| language | org | repo | -| ---- | ---- |---- | -| Golang | devstream-io | dtm-scaffolding-golang | -| Java Spring | spring-guides | gs-spring-boot | +| language | org | repo | +|-------------|---------------|----------------------------| +| Golang | devstream-io | dtm-scaffolding-golang | +| Golang | devstream-io | dtm-scaffolding-golang-cli | +| Java Spring | spring-guides | gs-spring-boot | ### Golang @@ -109,6 +118,27 @@ tools: 这个配置在 GitHub 为用于 test_owner 创建 `dtm-test-golang` 仓库,它的生成是基于 `devstream-io/dtm-scaffolding-golang` 官方 Golang 脚手架仓库和传入的变量 `ImageRepo`。 +### Golang CLI + +```yaml +tools: + - name: repo-scaffolding + instanceID: golang-cli-scaffolding + options: + destinationRepo: + owner: test_owner + org: "" + repo: dtm-test-golang-cli + branch: main + repoType: github + sourceRepo: + org: devstream-io + repo: dtm-scaffolding-golang-cli + repoType: github +``` + +这个配置在 GitHub 为用于 test_owner 创建 `dtm-test-golang-cli` 仓库,它的生成是基于 `devstream-io/dtm-scaffolding-golang-cli` 官方 Golang CLI 脚手架仓库。 + ### Java Spring ```yaml @@ -131,11 +161,3 @@ tools: ``` 这个配置会在 GitLab 为用户 test_owner 创建 `dtm-test-java` 仓库,使用的是 Spring 官方的 `spring-guides/gs-spring-boot` 仓库。 - -## Outputs - -这个插件有以下三个输出: - -- `owner` -- `repo` -- `repoURL` diff --git a/staging/dtm-repo-scaffolding-golang-cli/.github/workflows/release.yml b/staging/dtm-repo-scaffolding-golang-cli/.github/workflows/release.yml new file mode 100644 index 000000000..2c3678469 --- /dev/null +++ b/staging/dtm-repo-scaffolding-golang-cli/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: goreleaser + +on: + push: + tags: + - '*' + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v3 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/staging/dtm-repo-scaffolding-golang-cli/.gitignore b/staging/dtm-repo-scaffolding-golang-cli/.gitignore new file mode 100644 index 000000000..4e86ee083 --- /dev/null +++ b/staging/dtm-repo-scaffolding-golang-cli/.gitignore @@ -0,0 +1,27 @@ +### Go template +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +### VisualStudioCode template +.vscode/* + +### JetBrains template +.idea/ + +### macOS template +.DS_Store + +dist/ diff --git a/staging/dtm-repo-scaffolding-golang-cli/LICENSE b/staging/dtm-repo-scaffolding-golang-cli/LICENSE new file mode 100644 index 000000000..e69de29bb diff --git a/staging/dtm-repo-scaffolding-golang-cli/Makefile.tpl b/staging/dtm-repo-scaffolding-golang-cli/Makefile.tpl new file mode 100644 index 000000000..8514c7ac7 --- /dev/null +++ b/staging/dtm-repo-scaffolding-golang-cli/Makefile.tpl @@ -0,0 +1,22 @@ +SHELL := /bin/bash +BASEDIR = $(shell pwd) + +.PHONY: help +help: + @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: install +install: ## Install dependencies + @go mod download + @go mod vendor + +.PHONY: dev +dev: ## Run with Dev + @go run cmd/root.go + +.PHONY: build +build: ## Build todomvc + @go build -o build/[[.AppName]] cmd/main.go + +clean: ### Remove build dir + @rm -rf build diff --git a/staging/dtm-repo-scaffolding-golang-cli/README.md b/staging/dtm-repo-scaffolding-golang-cli/README.md new file mode 100644 index 000000000..0783d4650 --- /dev/null +++ b/staging/dtm-repo-scaffolding-golang-cli/README.md @@ -0,0 +1,28 @@ +# dtm-scaffolding-golang + +This repo contains templates used by DevStream plugin "repo-scaffolding" (thereafter: the plugin). + +This repo isn't intended to be used directly without DevStream. It should only be consumed by the plugin automatically. + +The plugin (together with this repo of templates) can create a repo in GitHub and set up the project layout and initialize the reop with necessary files that are typical for a Go cli app. The followings can be created automatically: + +- a Go cli app example (generated by [`cobra-cli init`](https://github.com/spf13/cobra-cli/blob/main/README.md)) +- [GoReleaser-Actions workflow](https://github.com/goreleaser/goreleaser-action)(Once you push a tag, it will build and release your app automatically) +- `.gitignore`, generated by [Toptal | gitignore.io](https://www.toptal.com/developers/gitignore/api/go,vim,macos,visualstudiocode) with minimum changes +- Makefile, with install/dev/build/clean + +## Usage + +- Render all files using go template whose name end with `.tpl` suffix. +- Files whose name don't end with `.tpl` extension don't need to be rendered. +- subdirectory "helm/**_app_name_**" (the **_app_name_** part) should be rendered with `AppName` +- subdicrectory "cmd/**_app_name_**" (the **_app_name_** part) should be rendered with `AppName` + +Example of required parameters to render these templates: + +```yaml +AppName: my-hello-world +Repo: + Owner: ironcore864 + Name: my-hello-world +``` diff --git a/staging/dtm-repo-scaffolding-golang-cli/README.md.tpl b/staging/dtm-repo-scaffolding-golang-cli/README.md.tpl new file mode 100644 index 000000000..c063ec13a --- /dev/null +++ b/staging/dtm-repo-scaffolding-golang-cli/README.md.tpl @@ -0,0 +1,21 @@ +# [[.AppName]] + +This is a repo for app [[.AppName]]; bootstrapped by DevStream. + +By default, the automatically generated scaffolding contains: + +- a piece of sample go cli app code using the [Cobra Commander Framework](https://github.com/spf13/cobra) +- [GoReleaser](https://goreleaser.com/) for building and releasing the app +- .gitignore +- Makefile + +## Automatic Releases + +Just push a tag to the repo and [GoReleaser](https://goreleaser.com/) will build and release the app. + +For example, to release version 0.1.0, run: + +```git +git tag -a v0.1.0 -m "First release" +git push origin v0.1.0 +``` diff --git a/staging/dtm-repo-scaffolding-golang-cli/cmd/root.go.tpl b/staging/dtm-repo-scaffolding-golang-cli/cmd/root.go.tpl new file mode 100644 index 000000000..dde66104d --- /dev/null +++ b/staging/dtm-repo-scaffolding-golang-cli/cmd/root.go.tpl @@ -0,0 +1,51 @@ +/* +Copyright © 2022 NAME HERE + +*/ +package cmd + +import ( + "os" + + "github.com/spf13/cobra" +) + + + +// rootCmd represents the base command when called without any subcommands +var rootCmd = &cobra.Command{ + Use: "[[.AppName]]", + Short: "A brief description of your application", + Long: `A longer description that spans multiple lines and likely contains +examples and usage of using your application. For example: + +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application.`, + // Uncomment the following line if your bare application + // has an action associated with it: + // Run: func(cmd *cobra.Command, args []string) { }, +} + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute() { + err := rootCmd.Execute() + if err != nil { + os.Exit(1) + } +} + +func init() { + // Here you will define your flags and configuration settings. + // Cobra supports persistent flags, which, if defined here, + // will be global for your application. + + // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.myapp.yaml)") + + // Cobra also supports local flags, which will only run + // when this action is called directly. + rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + + diff --git a/staging/dtm-repo-scaffolding-golang-cli/go.mod.tpl b/staging/dtm-repo-scaffolding-golang-cli/go.mod.tpl new file mode 100644 index 000000000..a72adf9fc --- /dev/null +++ b/staging/dtm-repo-scaffolding-golang-cli/go.mod.tpl @@ -0,0 +1,9 @@ +module github.com/[[.Repo.Owner]]/[[.Repo.Name]] + +go 1.19 + +require ( + github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/spf13/cobra v1.6.1 // indirect + github.com/spf13/pflag v1.0.5 // indirect +) diff --git a/staging/dtm-repo-scaffolding-golang-cli/go.sum.tpl b/staging/dtm-repo-scaffolding-golang-cli/go.sum.tpl new file mode 100644 index 000000000..442875a4e --- /dev/null +++ b/staging/dtm-repo-scaffolding-golang-cli/go.sum.tpl @@ -0,0 +1,10 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= +github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= +github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/staging/dtm-repo-scaffolding-golang-cli/main.go.tpl b/staging/dtm-repo-scaffolding-golang-cli/main.go.tpl new file mode 100644 index 000000000..4170e82db --- /dev/null +++ b/staging/dtm-repo-scaffolding-golang-cli/main.go.tpl @@ -0,0 +1,11 @@ +/* +Copyright © 2022 NAME HERE + +*/ +package main + +import "github.com/[[.Repo.Owner]]/[[.Repo.Name]]/cmd" + +func main() { + cmd.Execute() +}