-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Execute equivalence tests on every pull request (#35976)
- Loading branch information
1 parent
c816275
commit 449aa90
Showing
7 changed files
with
253 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,8 @@ | |
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
name: equivalence-test | ||
description: "Execute the suite of Terraform equivalence tests in testing/equivalence-tests" | ||
description: "Execute the suite of Terraform equivalence tests in testing/equivalence-tests and update the golden files." | ||
inputs: | ||
target-terraform-version: | ||
description: "The version of Terraform to use in execution." | ||
required: true | ||
target-terraform-branch: | ||
description: "The branch within this repository to update and compare." | ||
required: true | ||
target-equivalence-test-version: | ||
description: "The version of the Terraform equivalence tests to use." | ||
default: "0.3.0" | ||
|
@@ -19,9 +13,22 @@ inputs: | |
target-arch: | ||
description: "Current architecture" | ||
default: "amd64" | ||
current-branch: | ||
description: "What branch are we currently on?" | ||
required: true | ||
new-branch: | ||
description: "Name of new branch to be created for the review." | ||
required: true | ||
reviewers: | ||
description: "Comma-separated list of GitHub usernames to request review from." | ||
required: true | ||
message: | ||
description: "Message to include in the commit." | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
|
||
- name: "download equivalence test binary" | ||
shell: bash | ||
run: | | ||
|
@@ -30,15 +37,13 @@ runs: | |
./bin/equivalence-tests \ | ||
${{ inputs.target-os }} \ | ||
${{ inputs.target-arch }} | ||
- name: "download terraform binary" | ||
- name: Build terraform | ||
shell: bash | ||
run: | | ||
./.github/scripts/equivalence-test.sh download_terraform_binary \ | ||
${{ inputs.target-terraform-version }} \ | ||
./bin/terraform \ | ||
${{ inputs.target-os }} \ | ||
${{ inputs.target-arch }} | ||
run: ./.github/scripts/equivalence-test.sh build_terraform_binary ./bin/terraform | ||
|
||
- name: "run and update equivalence tests" | ||
id: execute | ||
shell: bash | ||
run: | | ||
./bin/equivalence-tests update \ | ||
|
@@ -47,15 +52,24 @@ runs: | |
--binary=$(pwd)/bin/terraform | ||
changed=$(git diff --quiet -- testing/equivalence-tests/outputs || echo true) | ||
if [[ $changed == "true" ]]; then | ||
echo "found changes, and pushing new golden files into branch ${{ inputs.target-terraform-branch }}." | ||
git config user.email "[email protected]" | ||
git config user.name "The Terraform Team" | ||
echo "changed=$changed" >> "${GITHUB_OUTPUT}" | ||
git add ./testing/equivalence-tests/outputs | ||
git commit -m "Automated equivalence test golden file update for release ${{ inputs.target-terraform-version }}." | ||
git push | ||
else | ||
echo "found no changes, so not pushing any updates." | ||
fi | ||
- name: "branch, commit, and push changes" | ||
if: steps.execute.outputs.changed == 'true' | ||
shell: bash | ||
run: | | ||
git checkout -b ${{ inputs.new-branch }} | ||
git add testing/equivalence-tests/outputs | ||
git commit -m "Update equivalence test golden files." | ||
git push --set-upstream origin ${{ inputs.new-branch }} | ||
- name: "create pull request" | ||
if: steps.execute.outputs.changed == 'true' | ||
shell: bash | ||
run: | | ||
gh pr create \ | ||
--base ${{ inputs.current-branch }} \ | ||
--head ${{ inputs.new-branch }} \ | ||
--title "Update equivalence test golden files" \ | ||
--body "This PR updates the equivalence test golden files." \ | ||
--reviewer ${{ inputs.reviewers }} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: equivalence-test-diff | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- synchronize | ||
- ready_for_review | ||
- reopened | ||
- synchronize | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
equivalence-test-diff: | ||
name: "Equivalence Test Diff" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Fetch source code | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: Determine Go version | ||
id: go | ||
uses: ./.github/actions/go-version | ||
|
||
- name: Install Go toolchain | ||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | ||
with: | ||
go-version: ${{ steps.go.outputs.version }} | ||
cache-dependency-path: go.sum | ||
|
||
- name: Download testing framework | ||
shell: bash | ||
run: | | ||
./.github/scripts/equivalence-test.sh download_equivalence_test_binary \ | ||
0.3.0 \ | ||
./bin/equivalence-tests \ | ||
linux \ | ||
amd64 | ||
- name: Build terraform | ||
shell: bash | ||
run: ./.github/scripts/equivalence-test.sh build_terraform_binary ./bin/terraform | ||
|
||
- name: Run equivalence tests | ||
id: equivalence-tests | ||
shell: bash {0} # we want to capture the exit code | ||
run: | | ||
./bin/equivalence-tests diff \ | ||
--tests=testing/equivalence-tests/tests \ | ||
--goldens=testing/equivalence-tests/outputs \ | ||
--binary=$(pwd)/bin/terraform | ||
echo "exit-code=$?" >> "${GITHUB_OUTPUT}" | ||
- name: Equivalence tests failed | ||
if: steps.equivalence-tests.outputs.exit-code == 1 # 1 is the exit code for failure | ||
shell: bash | ||
run: | | ||
gh pr comment ${{ github.event.pull_request.number }} \ | ||
--body "The equivalence tests failed. Please investigate [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ github.job }})." | ||
exit 1 # fail the job | ||
- name: Equivalence tests changed | ||
if: steps.equivalence-tests.outputs.exit-code == 2 # 2 is the exit code for changed | ||
shell: bash | ||
run: | | ||
gh pr comment ${{ github.event.pull_request.number }} \ | ||
--body "The equivalence tests will be updated. Please verify the changes [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ github.job }})." |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: equivalence-test-update | ||
|
||
on: | ||
pull_request_target: | ||
types: [ closed ] | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
check: | ||
name: "Should run equivalence tests?" | ||
runs-on: ubuntu-latest | ||
outputs: | ||
should_run: ${{ steps.target_branch.outputs.should_run }} | ||
steps: | ||
- name: target_branch | ||
id: target_branch | ||
run: | | ||
merged = ${{ github.event.pull_request.merged }} | ||
target_branch = ${{ github.event.pull_request.base.ref }} | ||
targets_release_branch = false | ||
if [ "$target_branch" == "main" ]; then | ||
targets_release_branch = true | ||
elif [ "$target_branch" =~ ^v[0-9]+\.[0-9]+$ ]; then | ||
targets_release_branch = true | ||
fi | ||
should_run=false | ||
if [ "$merged" == "true" ] && [ "$targets_release_branch" == "true" ]; then | ||
should_run=true | ||
fi | ||
echo "should_run=$should_run" >> ${GITHUB_OUTPUT} | ||
run-equivalence-tests: | ||
name: "Run equivalence tests" | ||
needs: | ||
- check | ||
if: needs.check.outputs.should_run == 'true' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
with: | ||
ref: ${{ inputs.target-branch }} | ||
|
||
- name: Determine Go version | ||
id: go | ||
uses: ./.github/actions/go-version | ||
|
||
- name: Install Go toolchain | ||
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | ||
with: | ||
go-version: ${{ steps.go.outputs.version }} | ||
cache-dependency-path: go.sum | ||
|
||
- uses: ./.github/actions/equivalence-test | ||
with: | ||
target-equivalence-test-version: ${{ inputs.equivalence-test-version }} | ||
target-os: linux | ||
target-arch: amd64 | ||
current-branch: ${{ github.event.pull_request.base.ref }} | ||
new-branch: equivalence-testing/${{ github.event.pull_request.head.ref }} | ||
reviewers: ${{ github.event.pull_request.merged_by.login }} | ||
message: "Update equivalence test golden files after ${{ github.event.pull_request.url }}." |
Oops, something went wrong.