Skip to content

Commit

Permalink
feat: Support native AND/OR template modules
Browse files Browse the repository at this point in the history
  • Loading branch information
deregtd committed Sep 30, 2024
1 parent 4fea206 commit 6799fcb
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ on:
- 'tests/**'
- 'manifest.yaml'
- 'stencil.yaml'
- '.goreleaser.yaml'
- '.mise.toml'

env:
GH_ROLE_ARN: arn:aws:iam::602046956384:role/GithubActions-github-actions-services-repos-Role
Expand Down
11 changes: 7 additions & 4 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
nodejs = "22"
yarn = "1.22.22"



# Template module tasks
[tasks.cleantest]
description = "Helper to clean the test directory"
dir = "tests"
Expand All @@ -15,7 +14,7 @@ done
"""

[tasks.buildtest]
description = 'Build the Test templates'
description = 'Build the Test projects'
dir = "tests"
run = """
#!/usr/bin/env bash
Expand All @@ -28,9 +27,13 @@ done
description = 'Run the tests'
dir = "tests"
## <<Stencil::Block(runTests)>>
env = {ENV_VAR_NAME = 'hooray'} # env vars for the script
env = { ENV_VAR_NAME = 'hooray' } # env vars for the script
run = """
#!/usr/bin/env bash
echo "Tests are running"
"""
## <</Stencil::Block>>

## <<Stencil::Block(tasks)>>

## <</Stencil::Block>>
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# stencil-templatemodule

This is a stencil template module for making it easy to make stencil template modules. Much meta, wow.
This is a stencil module for making it easy to make stencil modules. Much meta, wow.

Stencil modules can be a native and/or template module. A native module is one that contains native golang code. A template module is one that contains templated code. If you are looking for a guide on how to make your own stencil modules, check out the [stencil documentation](https://stencil.rgst.io/).

## Manifest Arguments

Expand All @@ -10,5 +12,6 @@ In the `arguments` section of the `manifest.yaml` file, you can specify the foll
| -------------------- | --------------- | -------------------------------------------------------------- |
| `description` | Required | Friendly-but-short description string for the frontend app |
| `owner` | Required | Pod or Portfolio ID for the owner of the frontend app |
| `nativeModule` | `false` | Does this template module include native module golang code |
| `nativeModule` | `false` | Does this module include native module golang code |
| `templateModule` | `false` | Does this module include templated code |
| `buildAndTestRunner` | `ubuntu-latest` | The github actions runner to use for the build and test CI job |
8 changes: 7 additions & 1 deletion manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: github.com/udemy/stencil-templatemodule
type: templates
dirReplacements:
## <<Stencil::Block(dirReplacements)>>

Expand All @@ -22,7 +23,12 @@ arguments:
## <<Stencil::Block(arguments)>>
nativeModule:
required: false
description: Does this template module include native module golang code
description: Does this module include native module golang code?
schema:
type: boolean
templateModule:
required: false
description: Does this module include templated code
schema:
type: boolean
buildAndTestRunner:
Expand Down
1 change: 1 addition & 0 deletions stencil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: stencil-templatemodule
arguments:
description: Stencil module forming the base for stencil template modules
owner: platform
templateModule: true
modules:
- name: github.com/udemy/stencil-templatemodule
replacements:
Expand Down
2 changes: 2 additions & 0 deletions templates/.github/workflows/build-release.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ jobs:
{{ file.Block "gotestvars" }}
## <</Stencil::Block>>
{{- end }}
{{- if stencil.Arg "templateModule" }}
## <<Stencil::Block(buildtestauth)>>
{{ file.Block "buildtestauth" }}
## <</Stencil::Block>>
Expand All @@ -127,6 +128,7 @@ jobs:
## <<Stencil::Block(buildteststeps)>>
{{ file.Block "arguments" }}
## <</Stencil::Block>>
{{- end }}

build-release:
name: Build and Release
Expand Down
8 changes: 6 additions & 2 deletions templates/.mise.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ goreleaser = "latest"
"go:golang.org/x/tools/cmd/goimports" = "latest"
"go:github.com/thenativeweb/get-next-version" = "latest"
{{- end }}
{{- if stencil.Arg "nativeModule" }}

{{ if stencil.Arg "nativeModule" -}}
# Native module tasks
[tasks.build]
description = "Build a binary for the current platform/architecture"
run = "go build -trimpath -o ./bin/ -v ./cmd/..."
Expand Down Expand Up @@ -40,7 +41,9 @@ run = ["./.github/scripts/get-next-version.sh"]
description = "Run tests"
run = "gotestsum"
{{- end }}
{{- if stencil.Arg "templateModule" }}

# Template module tasks
[tasks.cleantest]
description = "Helper to clean the test directory"
dir = "tests"
Expand All @@ -52,7 +55,7 @@ done
"""

[tasks.buildtest]
description = 'Build the Test templates'
description = 'Build the Test projects'
dir = "tests"
run = """
#!/usr/bin/env bash
Expand All @@ -75,6 +78,7 @@ echo "Tests are running"
{{ file.Block "runTests" }}
{{- end }}
## <</Stencil::Block>>
{{- end }}

## <<Stencil::Block(tasks)>>
{{ file.Block "tasks" }}
Expand Down
8 changes: 6 additions & 2 deletions templates/manifest.yaml.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: github.com/udemy/{{ .Config.Name }}
{{- if stencil.Arg "nativeModule" }}
{{- if and (stencil.Arg "nativeModule") (stencil.Arg "templateModule") }}
type: templates,extension
{{- else }}
{{- else if stencil.Arg "nativeModule" }}
type: extension
{{- else if stencil.Arg "templateModule" }}
type: templates
{{- else }}
{{- fail "Either templateModule or nativeModule must be true" }}
{{- end }}
dirReplacements:
## <<Stencil::Block(dirReplacements)>>
Expand Down
9 changes: 7 additions & 2 deletions templates/tests/README.md.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{{- if not (stencil.Arg "templateModule") -}}
{{- file.Delete -}}
{{- else -}}
{{ file.Static -}}
{{- end -}}
For every test case that you have, regarding your stencil templates, you should have a corresponding directory which contains its own stencil.yaml in the tests directory.

For every test case that you have, regarding your stencil templates, you should have a corresponding directory which contains its own stencil.yaml in the tests directory.
Make sure to also add each of these tests to the .gitignore file so that you don't commit the test results to the repository.

This is a good practice to ensure that your templates are working as expected.
This is a good practice to ensure that your templates are working as expected.

The CI pipeline will execute all the tests in the tests directory and will fail if any of them fail.
4 changes: 4 additions & 0 deletions templates/tests/basic/stencil.yaml.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{- if not (stencil.Arg "templateModule") -}}
{{- file.Delete -}}
{{- else -}}
{{- file.Once -}}
{{- end -}}
# yaml-language-server: $schema=https://stencil.rgst.io/static/stencil.jsonschema.json
name: {{ .Config.Name }}-test
arguments:
Expand Down

0 comments on commit 6799fcb

Please sign in to comment.