|
| 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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 26 | + - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.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@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0 |
| 34 | + with: |
| 35 | + version: latest |
| 36 | + |
| 37 | + generate: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 41 | + - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 |
| 42 | + with: |
| 43 | + go-version-file: 'go.mod' |
| 44 | + cache: true |
| 45 | + # Temporarily download Terraform 1.8 prerelease for function documentation support. |
| 46 | + # When Terraform 1.8.0 final is released, this can be removed. |
| 47 | + - uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36 # v3.0.0 |
| 48 | + with: |
| 49 | + terraform_version: '1.8.0-alpha20240216' |
| 50 | + terraform_wrapper: false |
| 51 | + - run: go generate ./... |
| 52 | + - name: git diff |
| 53 | + run: | |
| 54 | + git diff --compact-summary --exit-code || \ |
| 55 | + (echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1) |
| 56 | +
|
| 57 | + # Run acceptance tests in a matrix with Terraform CLI versions |
| 58 | + test: |
| 59 | + name: Terraform Provider Acceptance Tests |
| 60 | + needs: build |
| 61 | + runs-on: ubuntu-latest |
| 62 | + timeout-minutes: 15 |
| 63 | + strategy: |
| 64 | + fail-fast: false |
| 65 | + matrix: |
| 66 | + # list whatever Terraform versions here you would like to support |
| 67 | + terraform: |
| 68 | + - '1.0.*' |
| 69 | + - '1.1.*' |
| 70 | + - '1.2.*' |
| 71 | + - '1.3.*' |
| 72 | + - '1.4.*' |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 75 | + - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 |
| 76 | + with: |
| 77 | + go-version-file: 'go.mod' |
| 78 | + cache: true |
| 79 | + - uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36 # v3.0.0 |
| 80 | + with: |
| 81 | + terraform_version: ${{ matrix.terraform }} |
| 82 | + terraform_wrapper: false |
| 83 | + - run: go mod download |
| 84 | + - env: |
| 85 | + TF_ACC: "1" |
| 86 | + run: go test -v -cover ./internal/provider/ |
| 87 | + timeout-minutes: 10 |
0 commit comments