Skip to content

Commit 7967aa8

Browse files
authored
chore: Adding GitHub Actions Workflows (#245)
* feat: Adding GitHub Actions workflows * fix: Fixing spelling * fix: Toss markdownlint * fix: Upgrading to Golang 1.25 * fix: Pulling in updated linter * fix: Propagating context * fix: Don't make private functions backwards compatible * fix: Adding `go-junit-report` to dependencies * fix: Using build flags to isolate AWS tests * fix: Improving AWS test targeting * fix: Addressing lint finding * fix: Isolating tests that require SSH access * fix: Resolving more test issues * fix: Fixing build workflow
1 parent 231682d commit 7967aa8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+810
-290
lines changed

.codespellrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[codespell]
2+
skip = template_helpers_test.go

.github/workflows/base-test.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Base Tests
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
test:
8+
name: Test (${{ matrix.os }})
9+
runs-on: ${{ matrix.os }}-latest
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [ubuntu, macos]
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v5
18+
19+
- name: Use mise to install dependencies
20+
uses: jdx/mise-action@v2
21+
with:
22+
version: 2025.8.16
23+
experimental: true
24+
env:
25+
# Adding token here to reduce the likelihood of hitting rate limit issues.
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- id: go-cache-paths
29+
run: |
30+
echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
31+
echo "go-mod=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
32+
shell: bash
33+
34+
- name: Go Build Cache
35+
uses: actions/cache@v4
36+
with:
37+
path: ${{ steps.go-cache-paths.outputs.go-build }}
38+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}-${{ matrix.os }}-amd64
39+
40+
- name: Go Mod Cache
41+
uses: actions/cache@v4
42+
with:
43+
path: ${{ steps.go-cache-paths.outputs.go-mod }}
44+
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}-${{ matrix.os }}-amd64
45+
46+
- name: Install go-junit-report
47+
run: go install github.com/jstemmer/go-junit-report/v2@latest
48+
49+
- name: Run Tests
50+
id: run-tests
51+
run: |
52+
set -o pipefail
53+
go test -v ./... -timeout 45m | tee >(go-junit-report -set-exit-code > result.xml)
54+
shell: bash
55+
env:
56+
# Adding token here to reduce the likelihood of hitting rate limit issues.
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Upload Report (${{ matrix.os }})
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: test-report-${{ matrix.os }}
63+
path: result.xml
64+
65+
- name: Display Test Results (${{ matrix.os }})
66+
uses: mikepenz/action-junit-report@v5
67+
if: always()
68+
with:
69+
report_paths: result.xml
70+
detailed_summary: 'true'
71+
include_time_in_summary: 'true'
72+
group_suite: 'true'

.github/workflows/build.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Build
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build:
8+
name: Build (${{ matrix.os }}/${{ matrix.arch }})
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
include:
13+
- os: darwin
14+
arch: amd64
15+
- os: darwin
16+
arch: arm64
17+
- os: linux
18+
arch: "386"
19+
- os: linux
20+
arch: amd64
21+
- os: linux
22+
arch: arm64
23+
- os: windows
24+
arch: "386"
25+
- os: windows
26+
arch: amd64
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v5
31+
32+
- name: Use mise to install dependencies
33+
uses: jdx/mise-action@v2
34+
with:
35+
version: 2025.8.16
36+
experimental: true
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- id: go-cache-paths
41+
run: |
42+
echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
43+
44+
- name: Go Build Cache
45+
uses: actions/cache@v4
46+
with:
47+
path: ${{ steps.go-cache-paths.outputs.go-build }}
48+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}-${{ matrix.os }}-${{ matrix.arch }}
49+
50+
- name: Build Boilerplate
51+
env:
52+
GOOS: ${{ matrix.os }}
53+
GOARCH: ${{ matrix.arch }}
54+
run: |
55+
OUTPUT="bin/boilerplate_${GOOS}_${GOARCH}"
56+
if [[ "${GOOS}" == "windows" ]]; then
57+
OUTPUT="${OUTPUT}.exe"
58+
fi
59+
go build -o "${OUTPUT}" \
60+
-ldflags "-s -w -X github.com/gruntwork-io/go-commons/version.Version=${GITHUB_REF_NAME} -extldflags '-static'" \
61+
.
62+
63+
- name: Upload Build Artifact
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: boilerplate_${{ matrix.os }}_${{ matrix.arch }}
67+
path: bin/boilerplate_${{ matrix.os }}_${{ matrix.arch }}*

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
lint:
8+
uses: ./.github/workflows/lint.yml
9+
secrets: inherit
10+
11+
codespell:
12+
uses: ./.github/workflows/codespell.yml
13+
secrets: inherit
14+
15+
base_tests:
16+
needs: [lint, codespell]
17+
uses: ./.github/workflows/base-test.yml
18+
permissions:
19+
contents: read
20+
checks: write
21+
secrets: inherit
22+
23+
build:
24+
needs: [lint, codespell]
25+
uses: ./.github/workflows/build.yml
26+
secrets: inherit

.github/workflows/codespell.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Codespell
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
codespell:
8+
name: Check Spelling
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v5
14+
15+
- name: Create default packages file
16+
run: |
17+
cat <<EOF > .mise-python-default-packages
18+
codespell==2.4.0
19+
EOF
20+
21+
echo "MISE_PYTHON_DEFAULT_PACKAGES_FILE=.mise-python-default-packages" >> "$GITHUB_ENV"
22+
23+
- name: Use mise to install dependencies
24+
uses: jdx/mise-action@v2
25+
with:
26+
version: 2025.8.16
27+
experimental: true
28+
mise_toml: |
29+
[tools]
30+
python = "3.13.3"
31+
env:
32+
# Adding token here to reduce the likelihood of hitting rate limit issues.
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Run codespell
36+
run: codespell .

.github/workflows/lint.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Lint
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
lint:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v5
12+
13+
- id: go-version
14+
run: |
15+
go version
16+
17+
- name: Set up mise
18+
uses: jdx/mise-action@v2
19+
with:
20+
version: 2025.8.16
21+
experimental: true
22+
env:
23+
# Adding token here to reduce the likelihood of hitting rate limit issues.
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- id: go-cache-paths
27+
run: |
28+
echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
29+
echo "go-mod=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
30+
31+
# TODO: Make this less brittle.
32+
echo "golanci-lint-cache=/home/runner/.cache/golangci-lint" >> "$GITHUB_OUTPUT"
33+
34+
- name: Go Build Cache
35+
uses: actions/cache@v4
36+
with:
37+
path: ${{ steps.go-cache-paths.outputs.go-build }}
38+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}-linux-amd64
39+
40+
- name: Go Mod Cache
41+
uses: actions/cache@v4
42+
with:
43+
path: ${{ steps.go-cache-paths.outputs.go-mod }}
44+
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}-linux-amd64
45+
46+
- name: golangci-lint Cache
47+
uses: actions/cache@v4
48+
with:
49+
path: ${{ steps.go-cache-paths.outputs.golanci-lint-cache }}
50+
key: ${{ runner.os }}-golangci-lint-${{ hashFiles('**/go.sum') }}-linux-amd64
51+
52+
- name: Lint
53+
run: make lint

.golangci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is generated using `make update-local-lint` to track the linting used in Terragrunt. Do not edit manually.
22
version: "2"
33
run:
4-
go: "1.24"
4+
go: "1.25"
55
issues-exit-code: 1
66
tests: true
77
output:
@@ -54,7 +54,7 @@ linters:
5454
- unparam
5555
- usetesting
5656
- wastedassign
57-
- wsl
57+
- wsl_v5
5858
- zerologlint
5959
disable:
6060
- depguard
@@ -103,6 +103,9 @@ linters:
103103
- -ST1001
104104
unparam:
105105
check-exported: false
106+
wsl_v5:
107+
allow-whole-block: false
108+
branch-max-lines: 2
106109
exclusions:
107110
generated: lax
108111
rules:

README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ You can find older versions on the [Releases Page](https://github.com/gruntwork-
140140
When you run Boilerplate, it performs the following steps:
141141

142142
1. Read the `boilerplate.yml` file in the folder specified by the `--template-url` option to find all defined
143-
varaibles.
143+
variables.
144144
1. Gather values for the variables from any `--var` and `--var-file` options that were passed in and prompting the user
145145
for the rest (unless the `--non-interactive` flag is specified).
146146
1. Copy each file from `--template-url` to `--output-folder`, running each non-binary file through the Go
@@ -289,7 +289,7 @@ variables:
289289
description: Enter the welcome text used by the website dependency
290290

291291
- name: ShowLogo
292-
description: Should the webiste show the logo (true or false)?
292+
description: Should the website show the logo (true or false)?
293293
type: bool
294294
default: true
295295

@@ -688,7 +688,7 @@ Here's an example prompt for a variable with validations that shows how invalid
688688

689689
![Example Boilerplate real-time validation](./docs/bp-validation.png)
690690

691-
Here's an example demonstating how to specify validations when defining your variables:
691+
Here's an example demonstrating how to specify validations when defining your variables:
692692

693693
```yaml
694694
variables:
@@ -1151,6 +1151,41 @@ variables:
11511151

11521152
With this variable, you can have a template file named `{{ .RootTerragruntFileName }}` which will generate a file named according to the value of RootTerragruntFileName.
11531153

1154+
## Running tests
1155+
1156+
To run all tests:
1157+
1158+
```bash
1159+
go test ./...
1160+
```
1161+
1162+
This will run all tests except AWS-dependent integration tests, which are excluded by default since they require AWS credentials.
1163+
1164+
### Running AWS-dependent tests
1165+
1166+
Some integration tests require AWS credentials and are tagged with the `aws` build tag. These tests are also prefixed with `TestAWS` for easy targeting. To run these tests:
1167+
1168+
1. Set up AWS credentials (e.g., using AWS CLI or environment variables):
1169+
1170+
```bash
1171+
export AWS_ACCESS_KEY_ID=your_access_key
1172+
export AWS_SECRET_ACCESS_KEY=your_secret_key
1173+
```
1174+
1175+
2. Run tests with the `aws` build tag enabled:
1176+
1177+
```bash
1178+
go test -tags=aws ./...
1179+
```
1180+
1181+
Or target AWS tests specifically by name:
1182+
1183+
```bash
1184+
go test -tags=aws -run '^TestAWS' ./...
1185+
```
1186+
1187+
These AWS tests validate Terragrunt configurations by running `terragrunt validate-all`, which requires valid AWS credentials to access AWS provider APIs.
1188+
11541189
## Alternative project generators
11551190

11561191
Before creating Boilerplate, we tried a number of other project generators, but none of them met all of our

cli/boilerplate_cli.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package cli
33

44
import (
5+
"context"
56
"fmt"
67

78
"github.com/gruntwork-io/go-commons/entrypoint"
@@ -120,8 +121,10 @@ func runApp(cliContext *cli.Context) error {
120121
return err
121122
}
122123

124+
ctx := context.Background()
125+
123126
// The root boilerplate.yml is not itself a dependency, so we pass an empty Dependency.
124127
emptyDep := variables.Dependency{}
125128

126-
return templates.ProcessTemplate(opts, opts, emptyDep)
129+
return templates.ProcessTemplateWithContext(ctx, opts, opts, emptyDep)
127130
}

0 commit comments

Comments
 (0)