diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0458b3a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,23 @@ +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +; YAML ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +[{*.yaml,*.yml}] +indent_style = space +indent_size = 2 + +; Misc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +[{Makefile,*.mk}] +; Makefiles require tabs to work properly and do not work with spaces +indent_style = tab + +[*.md] +indent_style = space + diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml new file mode 100644 index 0000000..d436cc8 --- /dev/null +++ b/.github/workflows/push.yaml @@ -0,0 +1,37 @@ +name: Generators + +on: + push: + branches: + - "**" + +jobs: + generate: + name: Generate + runs-on: ubuntu-latest + env: + GH_API_KEY: ${{ secrets.GH_API_KEY }} + steps: + - name: Checkout local + uses: actions/checkout@v3 + + - name: Setup Git Config + shell: bash + run: | + set -x + git config --global user.email '${{ secrets.GH_AUTO_EMAIL }}' + git config --global user.name '${{ secrets.GH_AUTO_USER }}' + git config --global url.https://${GH_API_KEY}@github.com/.insteadOf https://github.com/ + + # Generate and then make sure no changes have occurred + - name: Generate + run: | + make generate-metadata + + - name: Check porcelain + run: | + git add . + if [[ -n "$(git status --porcelain)" ]]; then + PAGER= git diff --cached + exit 1 + fi diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3b0d464 --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +GENERATORS_DIR := generators +GENERATOR_METADATA_FILE := generator-config.yaml +JSON_OUTPUT := generators.json + +REPO := generators +REPO_ORG := datawire +REPO_BRANCH := main +REPO_BASE_URL := https://github.com/$(REPO_ORG)/$(REPO)/raw/$(REPO_BRANCH) + + +# Setting SHELL to bash allows bash commands to be executed by recipes. +# Options are set to exit when a recipe line exits non-zero or a piped command fails. +SHELL = /usr/bin/env bash -o pipefail +.SHELLFLAGS = -ec + +# Default `make` to run `make generate-metadata` +.PHONY: all +all: generate-metadata + +.PHONY: generate-metadata +generate-metadata: + @echo "{" > $(JSON_OUTPUT) + @echo ' "generators": [' >> $(JSON_OUTPUT) + @find $(GENERATORS_DIR) -type f -name $(GENERATOR_METADATA_FILE) | while read -r generator_config_file; do \ + gen_dir="$$(basename "$$(dirname "$$generator_config_file")")"; \ + gen_name="$$(yq eval '.metadata.name' "$$generator_config_file")"; \ + gen_description="$$(yq eval '.metadata.description' "$$generator_config_file")"; \ + gen_version="$$(yq eval '.metadata.version' "$$generator_config_file")"; \ + gen_languages="$$(yq eval '.metadata.languages' "$$generator_config_file")"; \ + echo ' {' >> $(JSON_OUTPUT); \ + echo ' "name": "'$$gen_name'",' >> $(JSON_OUTPUT); \ + echo ' "description": "'$$gen_description'",' >> $(JSON_OUTPUT); \ + echo ' "version": "'$$gen_version'",' >> $(JSON_OUTPUT); \ + echo ' "languages": '$$gen_languages',' >> $(JSON_OUTPUT); \ + echo ' "dir_name": "'$$gen_dir'"' >> $(JSON_OUTPUT); \ + echo ' },' >> $(JSON_OUTPUT); \ + done + @sed -i '$$s/,$$/]/' $(JSON_OUTPUT) + @echo "}" >> $(JSON_OUTPUT) diff --git a/generators.json b/generators.json new file mode 100644 index 0000000..c9a1146 --- /dev/null +++ b/generators.json @@ -0,0 +1,10 @@ +{ + "generators": [ + { + "name": "Ambassador Labs Go Generator", + "description": "Generates a new project for an API server writen in go", + "version": "1.0.0", + "languages": ["go"], + "dir_name": "go" + }] +} diff --git a/go/base/cmd/binary/main.go.template b/generators/go/base/cmd/binary/main.go.template similarity index 100% rename from go/base/cmd/binary/main.go.template rename to generators/go/base/cmd/binary/main.go.template diff --git a/go/base/go.mod.template b/generators/go/base/go.mod.template similarity index 100% rename from go/base/go.mod.template rename to generators/go/base/go.mod.template diff --git a/go/base/internal/binary/handlers.go.template b/generators/go/base/internal/binary/handlers.go.template similarity index 100% rename from go/base/internal/binary/handlers.go.template rename to generators/go/base/internal/binary/handlers.go.template diff --git a/go/base/internal/binary/server.go.template b/generators/go/base/internal/binary/server.go.template similarity index 100% rename from go/base/internal/binary/server.go.template rename to generators/go/base/internal/binary/server.go.template diff --git a/go/generator-config.yaml b/generators/go/generator-config.yaml similarity index 90% rename from go/generator-config.yaml rename to generators/go/generator-config.yaml index b2ffcf0..7cd71a2 100644 --- a/go/generator-config.yaml +++ b/generators/go/generator-config.yaml @@ -1,10 +1,11 @@ metadata: name: "Ambassador Labs Go Generator" + description: "Generates a new project for an API server writen in go" version: "1.0.0" languages: ["go"] # Defines the base directory within the template folder. -# The entire contents of the base directory will be copied +# The entire contents of the base directory will be copied # and used to create the root of the new project. It may contain # directories, static files that will not be edited, and template files # that will be built later. @@ -22,23 +23,23 @@ templateExtension: ".template" # TODO: not implemented yet # denylist: any template file listed below (ex: "base/example.template") will not be built # allowlist: -ignoredTemplateFiles: +ignoredTemplateFiles: mode: denylist paths: [] # TODO: not implemented yet # By default template files will be removed after being built, but any template files listed below will # not be deleted after being built -persistedTemplateFiles: [] +persistedTemplateFiles: [] # Example in-line -# Log: +# Log: # source: in-line # value: fmt.Printf("foo bar\n") # Example in-line template -# Log: +# Log: # source: in-line # value: fmt.Printf("{{ MyMessage }}\n") @@ -64,7 +65,7 @@ variables: - name: GoModule sourceType: prompt - name: GoVersion - sourceType: prompt + sourceType: prompt renames: - path: "base/cmd/binary" diff --git a/go/modules/gha-test/build.yaml.template b/generators/go/modules/gha-test/build.yaml.template similarity index 100% rename from go/modules/gha-test/build.yaml.template rename to generators/go/modules/gha-test/build.yaml.template diff --git a/go/modules/readme/README.md.template b/generators/go/modules/readme/README.md.template similarity index 100% rename from go/modules/readme/README.md.template rename to generators/go/modules/readme/README.md.template