Terraform Provider Tests #2088
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@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 | |
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@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 | |
with: | |
egress-policy: audit | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Set up Go | |
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.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@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 | |
with: | |
egress-policy: audit | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Set up Go | |
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.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@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 | |
with: | |
egress-policy: audit | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Set up Go | |
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.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 | |
pac auth create --githubFederated --tenant ${{ secrets.ACCEPTANCE_TESTS_ENV_TENANT_ID }} --applicationId ${{ secrets.ACCEPTANCE_TESTS_ENV_CLIENT_ID }} | |
$environmentsList = (pac admin list --name "Test" --json | ConvertFrom-Json) | |
$environmentsList | ForEach-Object -Parallel { | |
if ($_.DisplayName.StartsWith("Test")){ | |
Write-Output $_.DisplayName | |
pac admin delete -env $_.EnvironmentID | |
} | |
} -ThrottleLimit 15 | |
- 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 | |
go test -p 3 -v 2>&1 ./... -run ^Test -coverprofile=test-coverage.out -timeout 300m | 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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
with: | |
name: Test Coverage | |
path: test-coverage.cov.html | |
- name: Upload coverage results to Codecov | |
if: success() || failure() | |
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3 | |
with: | |
file: test-coverage.out | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Upload test results to Codecov | |
if: ${{ !cancelled() }} | |
uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1 | |
with: | |
files: junit.xml | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Render test results | |
if: always() | |
uses: dorny/test-reporter@890a17cecf52a379fc869ab770a71657660be727 # v2.1.0 | |
with: | |
name: Test Results | |
path: junit.xml | |
reporter: java-junit | |
use-actions-summary: true |