|
| 1 | +# Terraform Provider testing workflow. |
| 2 | +name:Tests |
| 3 | + |
| 4 | +# This GitHub action runs your tests for each pull request and push. |
| 5 | +# Optionally, you can turn it on using a schedule for regular testing. |
| 6 | +on: |
| 7 | +pull_request: |
| 8 | +paths-ignore: |
| 9 | + -'README.md' |
| 10 | +push: |
| 11 | +paths-ignore: |
| 12 | + -'README.md' |
| 13 | + |
| 14 | +# Testing only needs permissions to read the repository contents. |
| 15 | +permissions: |
| 16 | +contents:read |
| 17 | + |
| 18 | +jobs: |
| 19 | +# Ensure project builds before running testing matrix |
| 20 | +build: |
| 21 | +name:Build |
| 22 | +runs-on:ubuntu-latest |
| 23 | +timeout-minutes:5 |
| 24 | +steps: |
| 25 | + -uses:actions/checkout@v4 |
| 26 | + -uses:actions/setup-go@v5 |
| 27 | +with: |
| 28 | +go-version-file:'go.mod' |
| 29 | +cache:true |
| 30 | + -run:go mod download |
| 31 | + -run:go build -v . |
| 32 | + -name:Run linters |
| 33 | +uses:golangci/golangci-lint-action@v6 |
| 34 | +with: |
| 35 | +version:latest |
| 36 | + |
| 37 | +generate: |
| 38 | +runs-on:ubuntu-latest |
| 39 | +steps: |
| 40 | + -uses:actions/checkout@v4 |
| 41 | + -uses:actions/setup-go@v5 |
| 42 | +with: |
| 43 | +go-version-file:'go.mod' |
| 44 | +cache:true |
| 45 | + -run:go generate ./... |
| 46 | + -name:git diff |
| 47 | +run:| |
| 48 | + git diff --compact-summary --exit-code || \ |
| 49 | + (echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1) |
| 50 | +
|
| 51 | +# Run acceptance tests in a matrix with Terraform CLI versions |
| 52 | +test: |
| 53 | +name:Terraform Provider Acceptance Tests |
| 54 | +needs:build |
| 55 | +runs-on:ubuntu-latest |
| 56 | +timeout-minutes:15 |
| 57 | +strategy: |
| 58 | +fail-fast:false |
| 59 | +matrix: |
| 60 | +# list whatever Terraform versions here you would like to support |
| 61 | +terraform: |
| 62 | + -'1.0.*' |
| 63 | + -'1.1.*' |
| 64 | + -'1.2.*' |
| 65 | + -'1.3.*' |
| 66 | + -'1.4.*' |
| 67 | + -"1.5.*" |
| 68 | + -"1.6.*" |
| 69 | + -"1.7.*" |
| 70 | + -"1.8.*" |
| 71 | +steps: |
| 72 | + -uses:actions/checkout@v4 |
| 73 | + -uses:actions/setup-go@v5 |
| 74 | +with: |
| 75 | +go-version-file:'go.mod' |
| 76 | +cache:true |
| 77 | + -uses:hashicorp/setup-terraform@v3 |
| 78 | +with: |
| 79 | +terraform_version:${{ matrix.terraform }} |
| 80 | +terraform_wrapper:false |
| 81 | + -run:go mod download |
| 82 | + -env: |
| 83 | +TF_ACC:"1" |
| 84 | +run:go test -v -cover ./internal/provider/ |
| 85 | +timeout-minutes:10 |
| 86 | + |
| 87 | + |
| 88 | +lint: |
| 89 | +name:Lint |
| 90 | +runs-on:ubuntu-latest |
| 91 | +timeout-minutes:5 |
| 92 | +steps: |
| 93 | + -name:Set up Go |
| 94 | +uses:actions/setup-go@v5 |
| 95 | +with: |
| 96 | +go-version:"1.22" |
| 97 | +id:go |
| 98 | + |
| 99 | + -uses:hashicorp/setup-terraform@v3 |
| 100 | +with: |
| 101 | +terraform_version:"1.3.*" |
| 102 | +terraform_wrapper:false |
| 103 | + |
| 104 | + -name:Check out code into the Go module directory |
| 105 | +uses:actions/checkout@v4 |
| 106 | + |
| 107 | + -name:Get dependencies |
| 108 | +run:| |
| 109 | + go mod download |
| 110 | +
|
| 111 | + -name:Lint fmt |
| 112 | +run:| |
| 113 | + make fmt |
| 114 | + git diff --exit-code |
| 115 | +
|
| 116 | + -name:Lint gen |
| 117 | +run:| |
| 118 | + make gen |
| 119 | + git diff --exit-code |