Skip to content

Commit 5dba37d

Browse files
authored
Migrate from CircleCI to GitHub Actions for tests and releases, enable linting (#255)
Reference: #96 Reference: #97 Fixes the previous linting issues: ```console ❯ golangci-lint run ./... internal/reflect/helpers.go:47:20: `getStructTags` - `ctx` is unused (unparam) func getStructTags(ctx context.Context, in reflect.Value, path *tftypes.AttributePath) (map[string]int, error) { ^ internal/reflect/pointer.go:54:27: `pointerSafeZeroValue` - `ctx` is unused (unparam) func pointerSafeZeroValue(ctx context.Context, target reflect.Value) reflect.Value { ^ types/float64.go:13:22: `float64Validate` - `ctx` is unused (unparam) func float64Validate(ctx context.Context, in tftypes.Value, path *tftypes.AttributePath) diag.Diagnostics { ^ types/int64.go:13:20: `int64Validate` - `ctx` is unused (unparam) func int64Validate(ctx context.Context, in tftypes.Value, path *tftypes.AttributePath) diag.Diagnostics { ^ tfsdk/plan.go:210:26: `(Plan).pathExists` - `ctx` is unused (unparam) func (p Plan) pathExists(ctx context.Context, path *tftypes.AttributePath) (bool, diag.Diagnostics) { ^ tfsdk/serve.go:70:43: `(*server).cancelRegisteredContexts` - `ctx` is unused (unparam) func (s *server) cancelRegisteredContexts(ctx context.Context) { ^ tfsdk/state.go:219:27: `(State).pathExists` - `ctx` is unused (unparam) func (s State) pathExists(ctx context.Context, path *tftypes.AttributePath) (bool, diag.Diagnostics) { ^ tfsdk/tftypes_value.go:16:24: `createParentValue` - `ctx` is unused (unparam) func createParentValue(ctx context.Context, parentPath *tftypes.AttributePath, parentType tftypes.Type, childValue interface{}) (tftypes.Value, diag.Diagnostics) { ^ tfsdk/tftypes_value.go:61:23: `upsertChildValue` - `ctx` is unused (unparam) func upsertChildValue(ctx context.Context, parentPath *tftypes.AttributePath, parentValue tftypes.Value, childStep tftypes.AttributePathStep, childValue tftypes.Value) (tftypes.Value, diag.Diagnostics) { ^ tfsdk/value_as_test.go:109:16: S1040: type assertion to the same type: target already has type attr.Value (gosimple) if !val.Equal(target.(attr.Value)) { ^ tfsdk/attribute_plan_modification.go:310:9: SA9003: empty branch (staticcheck) } else if resp.RequiresReplace { ``` All testing and linting workflows verified as successful via: ```shell act -s GITHUB_TOKEN=$GITHUB_TOKEN pull_request ```
1 parent c030a92 commit 5dba37d

20 files changed

+223
-273
lines changed

.circleci/config.yml

-121
This file was deleted.

.github/CONTRIBUTING.md

+65-3
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,63 @@ tfsdk: The `Example` type `Old` field has been removed since it is not necessary
174174
```
175175
``````
176176

177+
## Linting
178+
179+
GitHub Actions workflow bug and style checking is performed via [`actionlint`](https://github.com/rhysd/actionlint).
180+
181+
To run the GitHub Actions linters locally, install the `actionlint` tool, and run:
182+
183+
```shell
184+
actionlint
185+
```
186+
187+
Go code bug and style checking is performed via [`golangci-lint`](https://golangci-lint.run/).
188+
189+
To run the Go linters locally, install the `golangci-lint` tool, and run:
190+
191+
```shell
192+
golangci-lint run ./...
193+
```
194+
177195
## Testing
178196

179197
Code contributions should be supported by both unit and integration tests wherever possible.
180198

181-
### Unit tests
199+
### GitHub Actions Tests
200+
201+
GitHub Actions workflow testing is performed via [`act`](https://github.com/nektos/act).
202+
203+
To run the GitHub Actions testing locally (setting appropriate event):
204+
205+
```shell
206+
act --artifact-server-path /tmp --env ACTIONS_RUNTIME_TOKEN=test -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest pull_request
207+
```
208+
209+
The command options can be added to a `~/.actrc` file:
210+
211+
```text
212+
--artifact-server-path /tmp
213+
--env ACTIONS_RUNTIME_TOKEN=test
214+
-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest
215+
```
216+
217+
So they do not need to be specified every invocation:
218+
219+
```shell
220+
act pull_request
221+
```
222+
223+
To test the `ci-go/terraform-provider-corner` job, a valid GitHub Personal Access Token (PAT) with public read permissions is required. It can be passed in via the `-s GITHUB_TOKEN=...` command option.
224+
225+
### Go Unit Tests
226+
227+
Go code unit testing is perfomed via Go's built-in testing functionality.
228+
229+
To run the Go unit testing locally:
230+
231+
```shell
232+
go test ./...
233+
```
182234

183235
This codebase follows Go conventions for unit testing. Some guidelines include:
184236

@@ -263,6 +315,16 @@ Run the [`changelog-build`](https://pkg.go.dev/github.com/hashicorp/go-changelog
263315
changelog-build -changelog-template .changelog.tmpl -entries-dir .changelog -last-release $(git describe --tags --abbrev=0) -note-template .changelog-note.tmpl -this-release HEAD
264316
```
265317

266-
This will generate a section of Markdown text for the next release. Open the `CHANGELOG.md` file, add a `# X.Y.Z (Unreleased)` header as the first line, then add the output from the `changelog-build` command. The `(Unreleased)` suffix after the version number is required for the current release process.
318+
This will generate a section of Markdown text for the next release. Open the `CHANGELOG.md` file, add a `# X.Y.Z` header as the first line, then add the output from the `changelog-build` command.
319+
320+
Commit, push, create a release Git tag, and push the tag:
321+
322+
```shell
323+
git add CHANGELOG.md
324+
git commit -m "Update CHANGELOG for v1.2.3"
325+
git push
326+
git tag v1.2.3
327+
git push --tags
328+
```
267329

268-
Refer to the HashiCorp internal Engineering documentation for information about completing the release process once the changelog has been prepared.
330+
GitHub Actions will pick up the new release tag and kick off the release workflow.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Continuous integration handling for GitHub Actions workflows
2+
name: ci-github-actions
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- .github/workflows/*.yml
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
actionlint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- id: go-version
18+
# Reference: https://github.com/actions/setup-go/issues/23
19+
run: echo "::set-output name=version::$(cat ./.go-version)"
20+
- uses: actions/setup-go@v2
21+
with:
22+
go-version: ${{ steps.go-version.outputs.version }}
23+
- run: go install github.com/rhysd/actionlint/cmd/actionlint@latest
24+
- run: actionlint

.github/workflows/ci-go.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Continuous integration handling for Go
2+
name: ci-go
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- .github/workflows/test.yml
8+
- .golangci.yml
9+
- .go-version
10+
- go.mod
11+
- '**.go'
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
golangci-lint:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
- id: go-version
22+
# Reference: https://github.com/actions/setup-go/issues/23
23+
run: echo "::set-output name=version::$(cat ./.go-version)"
24+
- uses: actions/setup-go@v2
25+
with:
26+
go-version: ${{ steps.go-version.outputs.version }}
27+
- run: go mod download
28+
- uses: golangci/golangci-lint-action@v2
29+
with:
30+
skip-go-installation: true
31+
terraform-provider-corner:
32+
defaults:
33+
run:
34+
working-directory: terraform-provider-corner
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v2
38+
- uses: actions/checkout@v2
39+
with:
40+
path: terraform-provider-corner
41+
repository: hashicorp/terraform-provider-corner
42+
- id: go-version
43+
# Reference: https://github.com/actions/setup-go/issues/23
44+
run: echo "::set-output name=version::$(cat ./.go-version)"
45+
working-directory: .
46+
- uses: actions/setup-go@v2
47+
with:
48+
go-version: ${{ steps.go-version.outputs.version }}
49+
- run: go mod edit -replace=github.com/hashicorp/terraform-plugin-framework=../
50+
- run: go mod tidy
51+
- run: go test -v ./internal/frameworkprovider
52+
test:
53+
name: test (Go v${{ matrix.go-version }})
54+
runs-on: ubuntu-latest
55+
strategy:
56+
matrix:
57+
go-version: [ '1.17', '1.16' ]
58+
steps:
59+
- uses: actions/checkout@v2
60+
- uses: actions/setup-go@v2
61+
with:
62+
go-version: ${{ matrix.go-version }}
63+
- run: go mod download
64+
- run: go test -coverprofile=coverage.out ./...
65+
- run: go tool cover -html=coverage.out -o coverage.html
66+
- uses: actions/upload-artifact@v2
67+
with:
68+
name: go-${{ matrix.go-version }}-coverage
69+
path: coverage.html

.github/workflows/ci-goreleaser.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Continuous integration handling for GoReleaser
2+
name: ci-goreleaser
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- .goreleaser.yml
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- id: go-version
18+
# Reference: https://github.com/actions/setup-go/issues/23
19+
run: echo "::set-output name=version::$(cat ./.go-version)"
20+
- uses: actions/setup-go@v2
21+
with:
22+
go-version: ${{ steps.go-version.outputs.version }}
23+
- uses: goreleaser/goreleaser-action@v2
24+
with:
25+
args: check

.golangci.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
issues:
2+
max-per-linter: 0
3+
max-same-issues: 0
4+
5+
linters:
6+
disable-all: true
7+
enable:
8+
- deadcode
9+
- durationcheck
10+
- errcheck
11+
- exportloopref
12+
- gofmt
13+
- gosimple
14+
- ineffassign
15+
- makezero
16+
- nilerr
17+
# - paralleltest # Reference: https://github.com/kunwardeep/paralleltest/issues/14
18+
- predeclared
19+
- staticcheck
20+
# - tenv # TODO: Enable when upgrading Go 1.16 to 1.17
21+
- unconvert
22+
- unparam
23+
- varcheck
24+
- vet

.goreleaser.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
project_name: terraform-plugin-framework
22
build:
33
skip: true
4+
milestones:
5+
- close: true
46
release:
5-
github:
6-
changelog:
7-
skip: true
7+
ids:
8+
- 'none'

internal/reflect/helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func commaSeparatedString(in []string) string {
4444

4545
// getStructTags returns a map of Terraform field names to their position in
4646
// the tags of the struct `in`. `in` must be a struct.
47-
func getStructTags(ctx context.Context, in reflect.Value, path *tftypes.AttributePath) (map[string]int, error) {
47+
func getStructTags(_ context.Context, in reflect.Value, path *tftypes.AttributePath) (map[string]int, error) {
4848
tags := map[string]int{}
4949
typ := trueReflectValue(in).Type()
5050
if typ.Kind() != reflect.Struct {

internal/reflect/pointer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Pointer(ctx context.Context, typ attr.Type, val tftypes.Value, target refle
5151
// wrap it in that number of pointers again. The end result is to wind up with
5252
// the same exact type, except now you can be sure it's pointing to actual data
5353
// and will not give you a nil pointer dereference panic unexpectedly.
54-
func pointerSafeZeroValue(ctx context.Context, target reflect.Value) reflect.Value {
54+
func pointerSafeZeroValue(_ context.Context, target reflect.Value) reflect.Value {
5555
pointer := target.Type()
5656
var pointers int
5757
for pointer.Kind() == reflect.Ptr {

scripts/gofmtcheck.sh

-13
This file was deleted.

0 commit comments

Comments
 (0)