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

feat: Add support for native modules #4

Merged
merged 1 commit into from
Sep 28, 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
21 changes: 21 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
- 'main'
paths:
- '.github/workflows/build-release.yml'
- 'cmd/**'
- 'pkg/**'
- 'internal/**'
- 'go.mod'
- 'go.sum'
- 'templates/**'
- 'tests/**'
- 'manifest.yaml'
Expand Down Expand Up @@ -56,6 +61,9 @@ jobs:
with:
persist-credentials: false
token: ${{ steps.generate_token.outputs.token }}
# These two required for builds to successfully amend commits
ref: ${{ github.head_ref }}
fetch-depth: 2
- name: Install Tool Versions
uses: jdx/mise-action@052520c41a328779551db19a76697ffa34f3eabc
with:
Expand All @@ -74,6 +82,9 @@ jobs:
run: mise run buildtest
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
## <<Stencil::Block(buildTestEnvVars)>>

## <</Stencil::Block>>
- name: Run Tests
run: mise run runtest
env:
Expand All @@ -95,7 +106,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set git User
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Install Tool Versions
uses: jdx/mise-action@052520c41a328779551db19a76697ffa34f3eabc
with:
Expand All @@ -108,3 +125,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release

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

## <</Stencil::Block>>
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
__debug_bin*

# Editor files
*.swp
Expand Down Expand Up @@ -36,6 +37,9 @@ vendor
# macOS
.DS_Store

# Currently a build artifact for native modules
CHANGELOG.md

# Ignore literally everything under the tests directory (except the README) -- specifically include the dir and stencil.yaml file
# for each test case in the ignores block below
tests/*
Expand Down
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
nodejs = "22"
yarn = "1.22.22"



[tasks.cleantest]
description = "Helper to clean the test directory"
dir = "tests"
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
],
"go.formatTool": "goimports",
"go.useLanguageServer": true,
"files.trimTrailingWhitespace": true,
"files.exclude": {
"**/bin": true,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ 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 |
| `buildAndTestRunner` | `ubuntu-latest` | The github actions runner to use for the build and test CI job |
8 changes: 8 additions & 0 deletions manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ arguments:
schema:
type: string
## <<Stencil::Block(arguments)>>
nativeModule:
required: false
description: Does this template module include native module golang code
schema:
type: boolean
buildAndTestRunner:
required: false
description: The github actions runner to use for the build and test CI job
schema:
type: string
packageJsonDeps:
required: false
description: The package.json dependencies to add to the generated package.json
## <</Stencil::Block>>
modules:
- name: github.com/udemy/eng-team-management
Expand Down
6 changes: 3 additions & 3 deletions stencil.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: 0.10.0
version: 0.10.2
modules:
- name: github.com/udemy/eng-team-management
url: https://github.com/udemy/eng-team-management
version:
commit: 4d5cf0c23526a24ccc553310dba01b1fbddc0911
tag: v0.1.8
commit: 8eacc46158f50de1a13f754b4e5634749de3252c
tag: v0.2.5
- name: github.com/udemy/stencil-templatemodule
url: ./
version:
Expand Down
97 changes: 97 additions & 0 deletions templates/.github/workflows/build-release.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ on:
- 'main'
paths:
- '.github/workflows/build-release.yml'
- 'cmd/**'
- 'pkg/**'
- 'internal/**'
- 'go.mod'
- 'go.sum'
- 'templates/**'
- '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 Expand Up @@ -56,6 +63,9 @@ jobs:
with:
persist-credentials: false
token: {{ "${{ steps.generate_token.outputs.token }}" }}
# These two required for builds to successfully amend commits
ref: {{ "${{ github.head_ref }}" }}
fetch-depth: 2
- name: Install Tool Versions
uses: jdx/mise-action@052520c41a328779551db19a76697ffa34f3eabc
with:
Expand All @@ -67,13 +77,46 @@ jobs:
with:
github-token: {{ "${{ github.token }}" }}
version: 'latest'
{{- if stencil.Arg "nativeModule" }}
- name: Get Go directories
id: go
run: |
echo "cache_dir=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
echo "mod_cache_dir=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v4
with:
path: {{ "${{ steps.go.outputs.cache_dir }}" }}
key: {{ "${{ github.workflow }}-${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}" }}
- uses: actions/cache@v4
with:
path: {{ "${{ steps.go.outputs.mod_cache_dir }}" }}
key: {{ "${{ github.workflow }}-${{ runner.os }}-go-mod-cache-${{ hashFiles('go.sum') }}" }}
- name: Lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
# We already use setup-go's pkg cache and actions/cache's build cache, so don't double-up
skip-pkg-cache: true
skip-build-cache: true
args: --timeout=6m
- name: Build Go binary
run: mise run build
- name: Run Go Tests
run: go run gotest.tools/[email protected]
## <<Stencil::Block(gotestvars)>>
{{ file.Block "gotestvars" }}
## <</Stencil::Block>>
{{- end }}
## <<Stencil::Block(buildtestauth)>>
{{ file.Block "buildtestauth" }}
## <</Stencil::Block>>
- name: Build Test repo
run: mise run buildtest
env:
GITHUB_TOKEN: {{ "${{ steps.generate_token.outputs.token }}" }}
## <<Stencil::Block(buildTestEnvVars)>>
{{ file.Block "buildTestEnvVars" }}
## <</Stencil::Block>>
- name: Run Tests
run: mise run runtest
env:
Expand All @@ -95,16 +138,70 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
token: {{ "${{ secrets.GITHUB_TOKEN }}" }}
- name: Set git User
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Install Tool Versions
uses: jdx/mise-action@052520c41a328779551db19a76697ffa34f3eabc
with:
experimental: true
env:
GH_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}
{{- if stencil.Arg "nativeModule" }}
- name: Get Go directories
id: go
run: |
echo "cache_dir=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
echo "mod_cache_dir=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v4
with:
path: {{ "${{ steps.go.outputs.cache_dir }}" }}
key: {{ "${{ github.workflow }}-${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}" }}
- uses: actions/cache@v4
with:
path: {{ "${{ steps.go.outputs.mod_cache_dir }}" }}
key: {{ "${{ github.workflow }}-${{ runner.os }}-go-mod-cache-${{ hashFiles('go.sum') }}" }}
- name: Retrieve goreleaser version
run: |-
echo "version=$(mise current goreleaser)" >> "$GITHUB_OUTPUT"
id: goreleaser
- name: Get next version
id: next_version
run: |-
get-next-version --target github-action
- name: Create Tag
if: {{ "${{ steps.next_version.outputs.hasNextVersion == 'true' }}" }}
run: |-
git tag -a {{ "\"v${{ steps.next_version.outputs.version }}\" -m \"Release v${{ steps.next_version.outputs.version }}\"" }}
- name: Generate CHANGELOG
if: {{ "${{ steps.next_version.outputs.hasNextVersion == 'true' }}" }}
run: |-
mise run changelog
- name: Create release artifacts and Github Release
if: {{ "${{ steps.next_version.outputs.hasNextVersion == 'true' }}" }}
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: {{ "v${{ steps.goreleaser.outputs.version }}" }}
args: release --release-notes CHANGELOG.md --clean
env:
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}
## <<Stencil::Block(goreleaserEnvVars)>>
{{ file.Block "goreleaserEnvVars" }}
## <</Stencil::Block>>
{{- else }}
- name: Install Semantic-Release
run: yarn install
- name: Release
env:
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}
run: npx semantic-release
{{- end }}

## <<Stencil::Block(extraActions)>>
{{ file.Block "extraActions" }}
## <</Stencil::Block>>
4 changes: 4 additions & 0 deletions templates/.gitignore.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
__debug_bin*

# Editor files
*.swp
Expand Down Expand Up @@ -36,6 +37,9 @@ vendor
# macOS
.DS_Store

# Currently a build artifact for native modules
CHANGELOG.md

# Ignore literally everything under the tests directory (except the README) -- specifically include the dir and stencil.yaml file
# for each test case in the ignores block below
tests/*
Expand Down
Loading