Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add generators metadata file #1

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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

37 changes: 37 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions generators.json
Original file line number Diff line number Diff line change
@@ -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"
}]
}
File renamed without changes.
13 changes: 7 additions & 6 deletions go/generator-config.yaml → generators/go/generator-config.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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")

Expand All @@ -64,7 +65,7 @@ variables:
- name: GoModule
sourceType: prompt
- name: GoVersion
sourceType: prompt
sourceType: prompt

renames:
- path: "base/cmd/binary"
Expand Down
Loading