Skip to content

Commit 2264757

Browse files
committed
feat: Add support for native modules
Tested with stencil-sentry
1 parent 5f2cf14 commit 2264757

20 files changed

+511
-3
lines changed

.github/workflows/build-release.yml

+21
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ on:
1111
- 'main'
1212
paths:
1313
- '.github/workflows/build-release.yml'
14+
- 'cmd/**'
15+
- 'pkg/**'
16+
- 'internal/**'
17+
- 'go.mod'
18+
- 'go.sum'
1419
- 'templates/**'
1520
- 'tests/**'
1621
- 'manifest.yaml'
@@ -56,6 +61,9 @@ jobs:
5661
with:
5762
persist-credentials: false
5863
token: ${{ steps.generate_token.outputs.token }}
64+
# These two required for builds to successfully amend commits
65+
ref: ${{ github.head_ref }}
66+
fetch-depth: 2
5967
- name: Install Tool Versions
6068
uses: jdx/mise-action@052520c41a328779551db19a76697ffa34f3eabc
6169
with:
@@ -74,6 +82,9 @@ jobs:
7482
run: mise run buildtest
7583
env:
7684
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
85+
## <<Stencil::Block(buildTestEnvVars)>>
86+
87+
## <</Stencil::Block>>
7788
- name: Run Tests
7889
run: mise run runtest
7990
env:
@@ -95,7 +106,13 @@ jobs:
95106
- name: Checkout
96107
uses: actions/checkout@v4
97108
with:
109+
fetch-depth: 0
110+
fetch-tags: true
98111
token: ${{ secrets.GITHUB_TOKEN }}
112+
- name: Set git User
113+
run: |
114+
git config user.name github-actions
115+
git config user.email github-actions@github.com
99116
- name: Install Tool Versions
100117
uses: jdx/mise-action@052520c41a328779551db19a76697ffa34f3eabc
101118
with:
@@ -108,3 +125,7 @@ jobs:
108125
env:
109126
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110127
run: npx semantic-release
128+
129+
## <<Stencil::Block(extraActions)>>
130+
131+
## <</Stencil::Block>>

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.dll
55
*.so
66
*.dylib
7+
__debug_bin*
78

89
# Editor files
910
*.swp
@@ -36,6 +37,9 @@ vendor
3637
# macOS
3738
.DS_Store
3839

40+
# Currently a build artifact for native modules
41+
CHANGELOG.md
42+
3943
# Ignore literally everything under the tests directory (except the README) -- specifically include the dir and stencil.yaml file
4044
# for each test case in the ignores block below
4145
tests/*

.mise.toml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
nodejs = "22"
33
yarn = "1.22.22"
44

5+
6+
57
[tasks.cleantest]
68
description = "Helper to clean the test directory"
79
dir = "tests"

.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
2+
"go.lintTool": "golangci-lint",
3+
"go.lintFlags": [
4+
"--fast"
5+
],
6+
"go.formatTool": "goimports",
7+
"go.useLanguageServer": true,
28
"files.trimTrailingWhitespace": true,
39
"files.exclude": {
410
"**/bin": true,

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ In the `arguments` section of the `manifest.yaml` file, you can specify the foll
1010
| -------------------- | --------------- | -------------------------------------------------------------- |
1111
| `description` | Required | Friendly-but-short description string for the frontend app |
1212
| `owner` | Required | Pod or Portfolio ID for the owner of the frontend app |
13+
| `nativeModule` | `false` | Does this template module include native module golang code |
1314
| `buildAndTestRunner` | `ubuntu-latest` | The github actions runner to use for the build and test CI job |

manifest.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ arguments:
2020
schema:
2121
type: string
2222
## <<Stencil::Block(arguments)>>
23+
nativeModule:
24+
required: false
25+
description: Does this template module include native module golang code
26+
schema:
27+
type: boolean
2328
buildAndTestRunner:
2429
required: false
2530
description: The github actions runner to use for the build and test CI job
2631
schema:
2732
type: string
33+
packageJsonDeps:
34+
required: false
35+
description: The package.json dependencies to add to the generated package.json
2836
## <</Stencil::Block>>
2937
modules:
3038
- name: github.com/udemy/eng-team-management

stencil.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
version: 0.10.0
1+
version: 0.10.2
22
modules:
33
- name: github.com/udemy/eng-team-management
44
url: https://github.com/udemy/eng-team-management
55
version:
6-
commit: 4d5cf0c23526a24ccc553310dba01b1fbddc0911
7-
tag: v0.1.8
6+
commit: 8eacc46158f50de1a13f754b4e5634749de3252c
7+
tag: v0.2.5
88
- name: github.com/udemy/stencil-templatemodule
99
url: ./
1010
version:

templates/.github/workflows/build-release.yml.tpl

+97
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ on:
1111
- 'main'
1212
paths:
1313
- '.github/workflows/build-release.yml'
14+
- 'cmd/**'
15+
- 'pkg/**'
16+
- 'internal/**'
17+
- 'go.mod'
18+
- 'go.sum'
1419
- 'templates/**'
1520
- 'tests/**'
1621
- 'manifest.yaml'
1722
- 'stencil.yaml'
23+
- '.goreleaser.yaml'
24+
- '.mise.toml'
1825

1926
env:
2027
GH_ROLE_ARN: arn:aws:iam::602046956384:role/GithubActions-github-actions-services-repos-Role
@@ -56,6 +63,9 @@ jobs:
5663
with:
5764
persist-credentials: false
5865
token: {{ "${{ steps.generate_token.outputs.token }}" }}
66+
# These two required for builds to successfully amend commits
67+
ref: {{ "${{ github.head_ref }}" }}
68+
fetch-depth: 2
5969
- name: Install Tool Versions
6070
uses: jdx/mise-action@052520c41a328779551db19a76697ffa34f3eabc
6171
with:
@@ -67,13 +77,46 @@ jobs:
6777
with:
6878
github-token: {{ "${{ github.token }}" }}
6979
version: 'latest'
80+
{{- if stencil.Arg "nativeModule" }}
81+
- name: Get Go directories
82+
id: go
83+
run: |
84+
echo "cache_dir=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
85+
echo "mod_cache_dir=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
86+
- uses: actions/cache@v4
87+
with:
88+
path: {{ "${{ steps.go.outputs.cache_dir }}" }}
89+
key: {{ "${{ github.workflow }}-${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}" }}
90+
- uses: actions/cache@v4
91+
with:
92+
path: {{ "${{ steps.go.outputs.mod_cache_dir }}" }}
93+
key: {{ "${{ github.workflow }}-${{ runner.os }}-go-mod-cache-${{ hashFiles('go.sum') }}" }}
94+
- name: Lint
95+
uses: golangci/golangci-lint-action@v4
96+
with:
97+
version: latest
98+
# We already use setup-go's pkg cache and actions/cache's build cache, so don't double-up
99+
skip-pkg-cache: true
100+
skip-build-cache: true
101+
args: --timeout=6m
102+
- name: Build Go binary
103+
run: mise run build
104+
- name: Run Go Tests
105+
run: go run gotest.tools/gotestsum@v1.11.0
106+
## <<Stencil::Block(gotestvars)>>
107+
{{ file.Block "gotestvars" }}
108+
## <</Stencil::Block>>
109+
{{- end }}
70110
## <<Stencil::Block(buildtestauth)>>
71111
{{ file.Block "buildtestauth" }}
72112
## <</Stencil::Block>>
73113
- name: Build Test repo
74114
run: mise run buildtest
75115
env:
76116
GITHUB_TOKEN: {{ "${{ steps.generate_token.outputs.token }}" }}
117+
## <<Stencil::Block(buildTestEnvVars)>>
118+
{{ file.Block "buildTestEnvVars" }}
119+
## <</Stencil::Block>>
77120
- name: Run Tests
78121
run: mise run runtest
79122
env:
@@ -95,16 +138,70 @@ jobs:
95138
- name: Checkout
96139
uses: actions/checkout@v4
97140
with:
141+
fetch-depth: 0
142+
fetch-tags: true
98143
token: {{ "${{ secrets.GITHUB_TOKEN }}" }}
144+
- name: Set git User
145+
run: |
146+
git config user.name github-actions
147+
git config user.email github-actions@github.com
99148
- name: Install Tool Versions
100149
uses: jdx/mise-action@052520c41a328779551db19a76697ffa34f3eabc
101150
with:
102151
experimental: true
103152
env:
104153
GH_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}
154+
{{- if stencil.Arg "nativeModule" }}
155+
- name: Get Go directories
156+
id: go
157+
run: |
158+
echo "cache_dir=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
159+
echo "mod_cache_dir=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
160+
- uses: actions/cache@v4
161+
with:
162+
path: {{ "${{ steps.go.outputs.cache_dir }}" }}
163+
key: {{ "${{ github.workflow }}-${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}" }}
164+
- uses: actions/cache@v4
165+
with:
166+
path: {{ "${{ steps.go.outputs.mod_cache_dir }}" }}
167+
key: {{ "${{ github.workflow }}-${{ runner.os }}-go-mod-cache-${{ hashFiles('go.sum') }}" }}
168+
- name: Retrieve goreleaser version
169+
run: |-
170+
echo "version=$(mise current goreleaser)" >> "$GITHUB_OUTPUT"
171+
id: goreleaser
172+
- name: Get next version
173+
id: next_version
174+
run: |-
175+
get-next-version --target github-action
176+
- name: Create Tag
177+
if: {{ "${{ steps.next_version.outputs.hasNextVersion == 'true' }}" }}
178+
run: |-
179+
git tag -a {{ "\"v${{ steps.next_version.outputs.version }}\" -m \"Release v${{ steps.next_version.outputs.version }}\"" }}
180+
- name: Generate CHANGELOG
181+
if: {{ "${{ steps.next_version.outputs.hasNextVersion == 'true' }}" }}
182+
run: |-
183+
mise run changelog
184+
- name: Create release artifacts and Github Release
185+
if: {{ "${{ steps.next_version.outputs.hasNextVersion == 'true' }}" }}
186+
uses: goreleaser/goreleaser-action@v6
187+
with:
188+
distribution: goreleaser
189+
version: {{ "v${{ steps.goreleaser.outputs.version }}" }}
190+
args: release --release-notes CHANGELOG.md --clean
191+
env:
192+
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}
193+
## <<Stencil::Block(goreleaserEnvVars)>>
194+
{{ file.Block "goreleaserEnvVars" }}
195+
## <</Stencil::Block>>
196+
{{- else }}
105197
- name: Install Semantic-Release
106198
run: yarn install
107199
- name: Release
108200
env:
109201
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}
110202
run: npx semantic-release
203+
{{- end }}
204+
205+
## <<Stencil::Block(extraActions)>>
206+
{{ file.Block "extraActions" }}
207+
## <</Stencil::Block>>

templates/.gitignore.tpl

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.dll
55
*.so
66
*.dylib
7+
__debug_bin*
78

89
# Editor files
910
*.swp
@@ -36,6 +37,9 @@ vendor
3637
# macOS
3738
.DS_Store
3839

40+
# Currently a build artifact for native modules
41+
CHANGELOG.md
42+
3943
# Ignore literally everything under the tests directory (except the README) -- specifically include the dir and stencil.yaml file
4044
# for each test case in the ignores block below
4145
tests/*

0 commit comments

Comments
 (0)