|
| 1 | +# Terraform Provider testing workflow. |
| 2 | +# https://aran.dev/posts/github-actions-go-private-modules/ |
| 3 | +# https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys#deploy-keys |
| 4 | + |
| 5 | +name: Tests |
| 6 | + |
| 7 | +# This GitHub action runs your tests for each pull request and push. |
| 8 | +# Optionally, you can turn it on using a schedule for regular testing. |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + paths-ignore: |
| 12 | + - 'README.md' |
| 13 | + push: |
| 14 | + paths-ignore: |
| 15 | + - 'README.md' |
| 16 | + |
| 17 | +# Testing only needs permissions to read the repository contents. |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | +env: |
| 21 | + GOPRIVATE: github.com/joescharf/* |
| 22 | + |
| 23 | + |
| 24 | +jobs: |
| 25 | + # Ensure project builds before running testing matrix |
| 26 | + build: |
| 27 | + name: Build |
| 28 | + runs-on: ubuntu-latest |
| 29 | + timeout-minutes: 5 |
| 30 | + steps: |
| 31 | + - name: Add SSH Go Module Private Key |
| 32 | + env: |
| 33 | + SSH_AUTH_SOCK: /tmp/ssh_agent.sock |
| 34 | + run: | |
| 35 | + mkdir -p ~/.ssh |
| 36 | + ssh-keyscan github.com >> ~/.ssh/known_hosts |
| 37 | + ssh-agent -a $SSH_AUTH_SOCK > /dev/null |
| 38 | + ssh-add - <<< "${{ secrets.DEPLOY_KEY }}" |
| 39 | + echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV |
| 40 | +
|
| 41 | + - name: Setup access for private go modules |
| 42 | + run: | |
| 43 | + git config --global url."ssh://[email protected]/joescharf/dbsnapper-cli.git".insteadOf https://github.com/joescharf/dbsnapper |
| 44 | +
|
| 45 | + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 |
| 46 | + - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 |
| 47 | + with: |
| 48 | + go-version-file: 'go.mod' |
| 49 | + cache: true |
| 50 | + - run: go mod download |
| 51 | + - run: go build -v . |
| 52 | + - name: Run linters |
| 53 | + uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1 |
| 54 | + with: |
| 55 | + version: latest |
| 56 | + |
| 57 | + generate: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + steps: |
| 60 | + - name: Add SSH Go Module Private Key |
| 61 | + env: |
| 62 | + SSH_AUTH_SOCK: /tmp/ssh_agent.sock |
| 63 | + run: | |
| 64 | + mkdir -p ~/.ssh |
| 65 | + ssh-keyscan github.com >> ~/.ssh/known_hosts |
| 66 | + ssh-agent -a $SSH_AUTH_SOCK > /dev/null |
| 67 | + ssh-add - <<< "${{ secrets.DEPLOY_KEY }}" |
| 68 | + echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV |
| 69 | +
|
| 70 | + - name: Setup access for private go modules |
| 71 | + run: | |
| 72 | + git config --global url."ssh://[email protected]/joescharf/dbsnapper-cli.git".insteadOf https://github.com/joescharf/dbsnapper |
| 73 | +
|
| 74 | + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 |
| 75 | + - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 |
| 76 | + with: |
| 77 | + go-version-file: 'go.mod' |
| 78 | + cache: true |
| 79 | + # Temporarily download Terraform 1.8 prerelease for function documentation support. |
| 80 | + # When Terraform 1.8.0 final is released, this can be removed. |
| 81 | + - uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v3.1.1 |
| 82 | + with: |
| 83 | + terraform_version: '1.8.0-alpha20240216' |
| 84 | + terraform_wrapper: false |
| 85 | + - run: go generate ./... |
| 86 | + - name: git diff |
| 87 | + run: | |
| 88 | + git diff --compact-summary --exit-code || \ |
| 89 | + (echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1) |
| 90 | +
|
| 91 | + # Run acceptance tests in a matrix with Terraform CLI versions |
| 92 | + # Max parallel = 1 otherwise the tests will fail due to state conflicts. |
| 93 | + test: |
| 94 | + name: Terraform Provider Acceptance Tests |
| 95 | + needs: build |
| 96 | + runs-on: ubuntu-latest |
| 97 | + timeout-minutes: 15 |
| 98 | + strategy: |
| 99 | + fail-fast: false |
| 100 | + max-parallel: 1 |
| 101 | + matrix: |
| 102 | + # list whatever Terraform versions here you would like to support |
| 103 | + terraform: |
| 104 | + - '1.6.*' |
| 105 | + - '1.7.*' |
| 106 | + - '1.8.*' |
| 107 | + steps: |
| 108 | + - name: Add SSH Go Module Private Key |
| 109 | + env: |
| 110 | + SSH_AUTH_SOCK: /tmp/ssh_agent.sock |
| 111 | + run: | |
| 112 | + mkdir -p ~/.ssh |
| 113 | + ssh-keyscan github.com >> ~/.ssh/known_hosts |
| 114 | + ssh-agent -a $SSH_AUTH_SOCK > /dev/null |
| 115 | + ssh-add - <<< "${{ secrets.DEPLOY_KEY }}" |
| 116 | + echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV |
| 117 | +
|
| 118 | + - name: Setup access for private go modules |
| 119 | + run: | |
| 120 | + git config --global url."ssh://[email protected]/joescharf/dbsnapper-cli.git".insteadOf https://github.com/joescharf/dbsnapper |
| 121 | +
|
| 122 | + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 |
| 123 | + - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 |
| 124 | + with: |
| 125 | + go-version-file: 'go.mod' |
| 126 | + cache: true |
| 127 | + - uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v3.1.1 |
| 128 | + with: |
| 129 | + terraform_version: ${{ matrix.terraform }} |
| 130 | + terraform_wrapper: false |
| 131 | + - run: go mod download |
| 132 | + - env: |
| 133 | + TF_ACC: "1" |
| 134 | + DBSNAPPER_AUTHTOKEN: ${{ secrets.DBSNAPPER_AUTHTOKEN }} |
| 135 | + run: go test -v -cover ./internal/provider/ |
| 136 | + timeout-minutes: 10 |
0 commit comments