Terraform Provider Tests #2989
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Terraform Provider Tests | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| # run at 4 AM UTC every day | |
| - cron: '0 4 * * *' | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| concurrency: | |
| group: acceptancetests | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| jobs: | |
| should_run: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read # Required for checkout | |
| if: github.event_name != 'pull_request' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run-acceptance-tests')) | |
| outputs: | |
| acceptance_tests: ${{ steps.set_acceptance_tests.outputs.acceptance_tests }} | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - id: set_acceptance_tests | |
| name: Only run acceptance tests if necessary | |
| run: echo "acceptance_tests=true" >> $GITHUB_OUTPUT | |
| depscheck: | |
| name: Check Dependencies | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read # Required for checkout | |
| needs: should_run | |
| if: ${{ needs.should_run.outputs.acceptance_tests == 'true' }} | |
| steps: | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Check out code into the Go module directory | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| - name: Set up Go | |
| uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 | |
| with: | |
| cache: true | |
| go-version-file: 'go.mod' | |
| id: go | |
| - name: Run 'go mod tidy' and check for differences | |
| run: | | |
| go mod tidy | |
| git diff --exit-code -- go.mod go.sum || \ | |
| (echo; echo "Unexpected difference in go.mod/go.sum files. Run 'go mod tidy' command or revert any go.mod/go.sum changes and commit."; exit 1) | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read # Required for checkout | |
| needs: should_run | |
| if: ${{ needs.should_run.outputs.acceptance_tests == 'true' }} | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Check out code into the Go module directory | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| - name: Set up Go | |
| uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 | |
| with: | |
| cache: true | |
| go-version-file: 'go.mod' | |
| id: go | |
| - name: Get dependencies | |
| run: | | |
| go mod download | |
| - name: Build | |
| run: | | |
| go build -v . | |
| tests: | |
| name: Running Test | |
| needs: [build, should_run] | |
| if: ${{ needs.should_run.outputs.acceptance_tests == 'true' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write # Required for OIDC authentication | |
| contents: read # Required for checkout | |
| steps: | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Check out code into the Go module directory | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| - name: Set up Go | |
| uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 | |
| with: | |
| cache: true | |
| go-version-file: 'go.mod' | |
| id: go | |
| - name: Get dependencies | |
| run: | | |
| go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 | |
| go install github.com/jstemmer/go-junit-report/v2@v2.1.0 | |
| go mod download | |
| - name: "Set up Terraform" | |
| uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2 | |
| - name: Install Power Platform Tools | |
| if: success() || failure() | |
| uses: microsoft/powerplatform-actions/actions-install@6c7b538671a040d11afd8ab94d77bfe3b3ed87e6 # v1.9.1 | |
| - name: Environments cleanup | |
| if: success() || failure() | |
| shell: pwsh | |
| run: | | |
| dotnet tool install --global Microsoft.PowerApps.CLI.Tool --version 1.52.1 | |
| pac auth create --githubFederated --tenant ${{ secrets.ACCEPTANCE_TESTS_ENV_TENANT_ID }} --applicationId ${{ secrets.ACCEPTANCE_TESTS_ENV_CLIENT_ID }} | |
| $output = pac admin list --name "Test" --json | |
| if ($LASTEXITCODE -eq 0 -and $output) { | |
| try { | |
| $environmentsList = $output | ConvertFrom-Json | |
| $environmentsList | ForEach-Object -Parallel { | |
| if ($_.DisplayName.StartsWith("Test")){ | |
| Write-Output $_.DisplayName | |
| pac admin delete -env $_.EnvironmentID | |
| } | |
| } -ThrottleLimit 15 | |
| } catch { | |
| Write-Output "Failed to parse environments list: $_" | |
| Write-Output "Raw output: $output" | |
| } | |
| } else { | |
| Write-Output "Failed to list environments or no output received. Exit code: $LASTEXITCODE" | |
| Write-Output "Output: $output" | |
| } | |
| - name: Run tests | |
| env: | |
| TF_LOG: WARN | |
| TF_ACC: 1 | |
| POWER_PLATFORM_USE_OIDC: true | |
| POWER_PLATFORM_TENANT_ID: ${{ secrets.ACCEPTANCE_TESTS_ENV_TENANT_ID }} | |
| POWER_PLATFORM_CLIENT_ID: ${{ secrets.ACCEPTANCE_TESTS_ENV_CLIENT_ID }} | |
| ARM_USE_OIDC: true | |
| ARM_CLIENT_ID: ${{ secrets.ACCEPTANCE_TESTS_ENV_CLIENT_ID }} | |
| ARM_TENANT_ID: ${{ secrets.ACCEPTANCE_TESTS_ENV_TENANT_ID }} | |
| ARM_SUBSCRIPTION_ID: ${{ secrets.ACCEPTANCE_TESTS_ENV_SUBSCRIPTION_ID }} | |
| run: | | |
| go clean -testcache | |
| # Test Execution Command | |
| # | |
| # Runs Go tests for the Terraform Provider for Power Platform with the following configurations: | |
| # | |
| # - -p 1: Executes tests with parallelism set to 1 (sequential execution) | |
| # - -v: Enables verbose output to display detailed test information | |
| # - 2>&1: Redirects stderr to stdout to capture all output | |
| # - ./...: Runs tests in all packages recursively from the current directory | |
| # - -run ^Test: Executes only functions matching the pattern "^Test" (standard Go test functions) | |
| # - -coverprofile=test-coverage.out: Generates a coverage profile and saves it to test-coverage.out | |
| # - -timeout 600m: Sets a 10-hour timeout for the entire test suite | |
| # - -failfast: Stops test execution immediately upon first failure | |
| # - -shuffle=on: Randomizes test execution order to detect order-dependent test failures | |
| # | |
| # The output is piped to go-junit-report which: | |
| # - -set-exit-code: Preserves the original test exit code | |
| # - -iocopy: Copies test output to stdout while generating the report | |
| # - -out junit.xml: Writes JUnit-formatted test results to junit.xml | |
| go test -p 4 -v 2>&1 ./... -run ^Test -coverprofile=test-coverage.out -timeout 600m -failfast -shuffle=on | go-junit-report -set-exit-code -iocopy -out junit.xml | |
| - name: Prepare coverage report | |
| if: success() || failure() | |
| run: | | |
| go tool cover -html=test-coverage.out -o test-coverage.cov.html | |
| - name: Upload Coverage Artifacts | |
| if: success() || failure() | |
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | |
| with: | |
| name: Test Coverage | |
| path: test-coverage.cov.html | |
| - name: Upload coverage results to Codecov | |
| if: success() || failure() | |
| uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2 | |
| with: | |
| file: test-coverage.out | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| - name: Upload test results to Codecov | |
| if: ${{ !cancelled() }} | |
| uses: codecov/test-results-action@0fa95f0e1eeaafde2c782583b36b28ad0d8c77d3 # v1.2.1 | |
| with: | |
| files: junit.xml | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| - name: Render test results | |
| if: always() | |
| uses: dorny/test-reporter@b082adf0eced0765477756c2a610396589b8c637 # v2.5.0 | |
| with: | |
| name: Test Results | |
| path: junit.xml | |
| reporter: java-junit | |
| use-actions-summary: true |