Skip to content

Commit

Permalink
add generators metadata file
Browse files Browse the repository at this point in the history
Signed-off-by: Alice Wasko <[email protected]>
  • Loading branch information
Alice Wasko committed Jan 29, 2024
1 parent d3c30eb commit 6802dfc
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 0 deletions.
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
- name: Check porcelain
run: |
git add .
if [[ -n "$(git status --porcelain)" ]]; then
PAGER= git diff --cached
exit 1
fi
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
GENERATORS_DIR := generators
GENERATOR_METADATA_FILE := generator-config.yaml
JSON_OUTPUT := generators.json

# 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`
.PHONY: all
all: generate

.PHONY: generate
generate:
@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="$$(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")"; \
gen_hash="$$(find "$$gen_dir" -type f -exec md5sum {} + | awk '{print $$1}' | sort | md5sum | awk '{print $$1}')"; \
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 ' "directory": "'$$gen_dir'",' >> $(JSON_OUTPUT); \
echo ' "hash": "'$$gen_hash'"' >> $(JSON_OUTPUT); \
echo ' },' >> $(JSON_OUTPUT); \
done
@sed -i '$$s/,$$/]/' $(JSON_OUTPUT)
@echo "}" >> $(JSON_OUTPUT)
11 changes: 11 additions & 0 deletions generators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"generators": [
{
"name": "Ambassador Labs Go Generator",
"description": "Generates a new project for an API server writen in go",
"version": "1.0.0",
"languages": ["go"],
"directory": "generators/go",
"hash": "6fdd0aeefb61bbb9a9d70c2f007f18fb"
}]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
metadata:
name: "Ambassador Labs Go Generator"
description: "Generates a new project for an API server writen in go"
version: "1.0.0"
languages: ["go"]

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 6802dfc

Please sign in to comment.