|
| 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 26 | + - uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0 |
| 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@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 |
| 34 | + with: |
| 35 | + version: v2.11.3 |
| 36 | + |
| 37 | + generate: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 41 | + - uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0 |
| 42 | + with: |
| 43 | + go-version-file: 'go.mod' |
| 44 | + cache: true |
| 45 | + # We need the latest version of Terraform for our documentation generation to use |
| 46 | + - uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85 # v4.0.0 |
| 47 | + with: |
| 48 | + terraform_wrapper: false |
| 49 | + - run: make generate |
| 50 | + - name: git diff |
| 51 | + run: | |
| 52 | + git diff --compact-summary --exit-code || \ |
| 53 | + (echo; echo "Unexpected difference in directories after code generation. Run 'make generate' command and commit."; exit 1) |
| 54 | +
|
| 55 | + # Run acceptance tests in a matrix with Terraform CLI versions |
| 56 | + test: |
| 57 | + name: 'Acceptance Tests: Terraform ${{ matrix.terraform }}' |
| 58 | + needs: build |
| 59 | + runs-on: ubuntu-latest |
| 60 | + timeout-minutes: 15 |
| 61 | + strategy: |
| 62 | + fail-fast: false |
| 63 | + matrix: |
| 64 | + # Terraform versions |
| 65 | + terraform: |
| 66 | + - '1.13.*' |
| 67 | + - '1.14.*' |
| 68 | + steps: |
| 69 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 70 | + - uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0 |
| 71 | + with: |
| 72 | + go-version-file: 'go.mod' |
| 73 | + cache: true |
| 74 | + - uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85 # v4.0.0 |
| 75 | + with: |
| 76 | + terraform_version: ${{ matrix.terraform }} |
| 77 | + terraform_wrapper: false |
| 78 | + - run: go mod download |
| 79 | + - env: |
| 80 | + TF_ACC: "1" |
| 81 | + run: go test -v -cover ./internal/provider/ |
| 82 | + timeout-minutes: 10 |
0 commit comments