Skip to content

Commit 816b018

Browse files
author
Liam Cervante
authored
Merge branch 'main' into main
2 parents 7d13798 + 9402a85 commit 816b018

File tree

171 files changed

+4279
-1866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+4279
-1866
lines changed

.github/actions/equivalence-test/action.yml

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
# SPDX-License-Identifier: BUSL-1.1
33

44
name: equivalence-test
5-
description: "Execute the suite of Terraform equivalence tests in testing/equivalence-tests"
5+
description: "Execute the suite of Terraform equivalence tests in testing/equivalence-tests and update the golden files."
66
inputs:
7-
target-terraform-version:
8-
description: "The version of Terraform to use in execution."
9-
required: true
10-
target-terraform-branch:
11-
description: "The branch within this repository to update and compare."
12-
required: true
137
target-equivalence-test-version:
148
description: "The version of the Terraform equivalence tests to use."
159
default: "0.3.0"
@@ -19,9 +13,22 @@ inputs:
1913
target-arch:
2014
description: "Current architecture"
2115
default: "amd64"
16+
current-branch:
17+
description: "What branch are we currently on?"
18+
required: true
19+
new-branch:
20+
description: "Name of new branch to be created for the review."
21+
required: true
22+
reviewers:
23+
description: "Comma-separated list of GitHub usernames to request review from."
24+
required: true
25+
message:
26+
description: "Message to include in the commit."
27+
required: true
2228
runs:
2329
using: "composite"
2430
steps:
31+
2532
- name: "download equivalence test binary"
2633
shell: bash
2734
run: |
@@ -30,15 +37,13 @@ runs:
3037
./bin/equivalence-tests \
3138
${{ inputs.target-os }} \
3239
${{ inputs.target-arch }}
33-
- name: "download terraform binary"
40+
41+
- name: Build terraform
3442
shell: bash
35-
run: |
36-
./.github/scripts/equivalence-test.sh download_terraform_binary \
37-
${{ inputs.target-terraform-version }} \
38-
./bin/terraform \
39-
${{ inputs.target-os }} \
40-
${{ inputs.target-arch }}
43+
run: ./.github/scripts/equivalence-test.sh build_terraform_binary ./bin/terraform
44+
4145
- name: "run and update equivalence tests"
46+
id: execute
4247
shell: bash
4348
run: |
4449
./bin/equivalence-tests update \
@@ -47,15 +52,27 @@ runs:
4752
--binary=$(pwd)/bin/terraform
4853
4954
changed=$(git diff --quiet -- testing/equivalence-tests/outputs || echo true)
50-
if [[ $changed == "true" ]]; then
51-
echo "found changes, and pushing new golden files into branch ${{ inputs.target-terraform-branch }}."
52-
53-
git config user.email "52939924+teamterraform@users.noreply.github.com"
54-
git config user.name "The Terraform Team"
55+
echo "changed=$changed" >> "${GITHUB_OUTPUT}"
5556
56-
git add ./testing/equivalence-tests/outputs
57-
git commit -m "Automated equivalence test golden file update for release ${{ inputs.target-terraform-version }}."
58-
git push
59-
else
60-
echo "found no changes, so not pushing any updates."
61-
fi
57+
- name: "branch, commit, and push changes"
58+
if: steps.execute.outputs.changed == 'true'
59+
shell: bash
60+
run: |
61+
git config user.name "github-actions[bot]"
62+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
63+
git checkout -b ${{ inputs.new-branch }}
64+
git add testing/equivalence-tests/outputs
65+
git commit -m "Update equivalence test golden files."
66+
git push --set-upstream origin ${{ inputs.new-branch }}
67+
68+
- name: "create pull request"
69+
if: steps.execute.outputs.changed == 'true'
70+
shell: bash
71+
run: |
72+
gh pr create \
73+
--draft \
74+
--base ${{ inputs.current-branch }} \
75+
--head ${{ inputs.new-branch }} \
76+
--title "Update equivalence test golden files" \
77+
--body '${{ inputs.message }}' \
78+
--reviewer ${{ inputs.reviewers }}

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ label to enable the backport bot.
3131
3232
-->
3333

34-
1.10.x
34+
1.11.x
3535

3636
## Draft CHANGELOG entry
3737

.github/scripts/equivalence-test.sh

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ Commands:
2626
2727
./equivalence-test.sh download_equivalence_test_binary 0.3.0 ./bin/terraform-equivalence-testing linux amd64
2828
29-
download_terraform_binary <version> <target> <os> <arch>
30-
download_terraform_binary downloads the terraform release binary for a given
31-
version and places it at the target path.
29+
build_terraform_binary <target>
30+
download_terraform_binary builds the Terraform binary and places it at the
31+
target path.
3232
33-
./equivalence-test.sh download_terraform_binary 1.4.3 ./bin/terraform linux amd64
33+
./equivalence-test.sh build_terraform_binary ./bin/terraform
3434
EOF
3535
}
3636

@@ -65,25 +65,17 @@ function download_equivalence_test_binary {
6565
rm releases.json
6666
}
6767

68-
function download_terraform_binary {
69-
VERSION="${1:-}"
70-
TARGET="${2:-}"
71-
OS="${3:-}"
72-
ARCH="${4:-}"
68+
function build_terraform_binary {
69+
TARGET="${1:-}"
7370

74-
if [[ -z "$VERSION" || -z "$TARGET" || -z "$OS" || -z "$ARCH" ]]; then
75-
echo "missing at least one of [<version>, <target>, <os>, <arch>] arguments"
71+
if [[ -z "$TARGET" ]]; then
72+
echo "target argument"
7673
usage
7774
exit 1
7875
fi
7976

80-
mkdir -p zip
81-
curl "https://releases.hashicorp.com/terraform/${VERSION}/terraform_${VERSION}_${OS}_${ARCH}.zip" > "zip/terraform.zip"
82-
83-
mkdir -p bin
84-
unzip -p "zip/terraform.zip" terraform > "$TARGET"
77+
go build -o "$TARGET" ./
8578
chmod u+x "$TARGET"
86-
rm -r zip
8779
}
8880

8981
function get_target_branch {
@@ -142,14 +134,14 @@ function main {
142134
download_equivalence_test_binary "$2" "$3" "$4" "$5"
143135

144136
;;
145-
download_terraform_binary)
146-
if [ "${#@}" != 5 ]; then
137+
build_terraform_binary)
138+
if [ "${#@}" != 2 ]; then
147139
echo "invalid number of arguments"
148140
usage
149141
exit 1
150142
fi
151143

152-
download_terraform_binary "$2" "$3" "$4" "$5"
144+
build_terraform_binary "$2"
153145

154146
;;
155147
*)

.github/workflows/crt-hook-equivalence-tests.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: equivalence-test-diff
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- ready_for_review
9+
- reopened
10+
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
15+
env:
16+
GH_TOKEN: ${{ github.token }}
17+
18+
jobs:
19+
equivalence-test-diff:
20+
name: "Equivalence Test Diff"
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Fetch source code
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
27+
- name: Determine Go version
28+
id: go
29+
uses: ./.github/actions/go-version
30+
31+
- name: Install Go toolchain
32+
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
33+
with:
34+
go-version: ${{ steps.go.outputs.version }}
35+
cache-dependency-path: go.sum
36+
37+
- name: Download testing framework
38+
shell: bash
39+
run: |
40+
./.github/scripts/equivalence-test.sh download_equivalence_test_binary \
41+
0.4.0 \
42+
./bin/equivalence-tests \
43+
linux \
44+
amd64
45+
46+
- name: Build terraform
47+
shell: bash
48+
run: ./.github/scripts/equivalence-test.sh build_terraform_binary ./bin/terraform
49+
50+
- name: Run equivalence tests
51+
id: equivalence-tests
52+
shell: bash {0} # we want to capture the exit code
53+
run: |
54+
./bin/equivalence-tests diff \
55+
--tests=testing/equivalence-tests/tests \
56+
--goldens=testing/equivalence-tests/outputs \
57+
--binary=$(pwd)/bin/terraform
58+
echo "exit-code=$?" >> "${GITHUB_OUTPUT}"
59+
60+
- name: Equivalence tests failed
61+
if: steps.equivalence-tests.outputs.exit-code == 1 # 1 is the exit code for failure
62+
shell: bash
63+
run: |
64+
gh pr comment ${{ github.event.pull_request.number }} \
65+
--body "The equivalence tests failed. Please investigate [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})."
66+
exit 1 # fail the job
67+
68+
- name: Equivalence tests changed
69+
if: steps.equivalence-tests.outputs.exit-code == 2 # 2 is the exit code for changed
70+
shell: bash
71+
run: |
72+
gh pr comment ${{ github.event.pull_request.number }} \
73+
--body "The equivalence tests will be updated. Please verify the changes [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})."
Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: manual-equivalence-tests
1+
name: equivalence-tests-manual
22

33
on:
44
workflow_dispatch:
@@ -7,18 +7,22 @@ on:
77
type: string
88
description: "Which branch should be updated?"
99
required: true
10-
terraform-version:
10+
new-branch:
1111
type: string
12-
description: "Terraform version to run against (no v prefix, eg. 1.4.4)."
12+
description: "Name of new branch to be created for the review."
1313
required: true
1414
equivalence-test-version:
1515
type: string
16-
description: 'Equivalence testing framework version to use (no v prefix, eg. 0.3.0).'
17-
default: "0.3.0"
16+
description: 'Equivalence testing framework version to use (no v prefix, eg. 0.4.0).'
17+
default: "0.4.0"
1818
required: true
1919

2020
permissions:
21-
contents: write # We push updates to the equivalence tests back into the repository.
21+
contents: write
22+
pull-requests: write
23+
24+
env:
25+
GH_TOKEN: ${{ github.token }}
2226

2327
jobs:
2428
run-equivalence-tests:
@@ -28,10 +32,23 @@ jobs:
2832
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2933
with:
3034
ref: ${{ inputs.target-branch }}
35+
36+
- name: Determine Go version
37+
id: go
38+
uses: ./.github/actions/go-version
39+
40+
- name: Install Go toolchain
41+
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
42+
with:
43+
go-version: ${{ steps.go.outputs.version }}
44+
cache-dependency-path: go.sum
45+
3146
- uses: ./.github/actions/equivalence-test
3247
with:
33-
target-terraform-version: ${{ inputs.terraform-version }}
34-
target-terraform-branch: ${{ inputs.target-branch }}
3548
target-equivalence-test-version: ${{ inputs.equivalence-test-version }}
3649
target-os: linux
3750
target-arch: amd64
51+
current-branch: ${{ inputs.target-branch }}
52+
new-branch: ${{ inputs.new-branch }}
53+
reviewers: ${{ github.actor }}
54+
message: "Update equivalence test golden files."

0 commit comments

Comments
 (0)