Skip to content

Commit 71f86c5

Browse files
chore: Schedules run of acceptance and migration tests for all HashiCorp Terraform supported versions (#2012)
* get supported versions from API * WIP: call script and print outout in next step * fix lint * temp * temp: trigger action * add checkout * run test suite * add workflow_call to test-suite.yml * separate running tests into another job * remove print step and add inherit secrets * escape the double quotes within the string * escape double quotes * try adding other input * single quotes * return json * format * fix * single quote * Revert "single quote" This reverts commit 690ce3b. * remove strategy * strategy but hardcoding values * use variable * json * format output * missing fromJSON * change to matrix.terraform_version * make array * Revert "make array" This reverts commit 0419f72. * make json array * add double quotes * TEMP: run tests on most resources * Revert "TEMP: run tests on most resources" This reverts commit 676fa4a. * schedule on Saturday and don't run test suite on saturday * remove workflow_call for new action and allow to manually run action passing environment * fix scheduling * remove unnecessary printing * Update scripts/get-terraform-supported-versions.sh Co-authored-by: Andrea Angiolillo <[email protected]> * Update scripts/get-terraform-supported-versions.sh Co-authored-by: Andrea Angiolillo <[email protected]> * Update .github/workflows/terraform-compatibility-matrix.yml Co-authored-by: Andrea Angiolillo <[email protected]> * remove unnecessary provider_matrix * remove ref from checkout action * remove ref from inputs * mention that migration tests always use dev environment * revert PR change and use +x when checking json_array empty --------- Co-authored-by: Andrea Angiolillo <[email protected]>
1 parent e2a1e06 commit 71f86c5

File tree

3 files changed

+157
-2
lines changed

3 files changed

+157
-2
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: "HashiCorp Terraform Compatibility Matrix"
2+
run-name: 'HashiCorp Terraform Compatibility Matrix ${{ inputs.atlas_cloud_env }}'
3+
4+
on:
5+
schedule:
6+
- cron: "0 0 1-7 * 6" # runs first Saturday of the month at midnight UTC
7+
workflow_dispatch:
8+
inputs:
9+
atlas_cloud_env:
10+
description: 'Atlas cloud environment used, can be either `dev` or `qa`, empty for `dev`. Migration tests will always use `dev`'
11+
type: string
12+
required: false
13+
test_group:
14+
description: 'Test group to run, e.g. advanced_cluster, empty for all'
15+
type: string
16+
required: false
17+
18+
jobs:
19+
get-supported-versions:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
23+
- name: Get HashiCorp Terraform supported versions
24+
shell: bash
25+
id: get-terraform-supported-versions
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
run: |
29+
output=$(./scripts/get-terraform-supported-versions.sh)
30+
quoted_output=$(echo "${output}" | jq -c .)
31+
echo "supported_versions=${quoted_output}" >> "${GITHUB_OUTPUT}"
32+
outputs:
33+
supported_versions: ${{ steps.get-terraform-supported-versions.outputs.supported_versions }}
34+
35+
36+
run-test-supported-versions:
37+
needs: ["get-supported-versions"]
38+
if: ${{ !cancelled() }}
39+
strategy:
40+
max-parallel: 1
41+
fail-fast: false
42+
matrix:
43+
terraform_version: '${{ fromJSON(needs.get-supported-versions.outputs.supported_versions) }}'
44+
name: terrafrom-compatibility-${{ matrix.terraform_version }}-${{ inputs.atlas_cloud_env || 'dev' }}
45+
secrets: inherit
46+
uses: ./.github/workflows/test-suite.yml
47+
with:
48+
terraform_matrix: '["${{ matrix.terraform_version }}"]'
49+
atlas_cloud_env: ${{ inputs.atlas_cloud_env }}
50+

.github/workflows/test-suite.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: 'Test Suite'
22

3-
# Runs acceptance and migrations tests with a set of terraform versions and provider versions (used for migration tests). This worflow is scheduled daily, but can also be run manually.
3+
# Runs acceptance and migrations tests with a set of terraform versions and provider versions (used for migration tests). This worflow is scheduled daily except Saturdays, but can also be run manually.
44
on:
55
workflow_dispatch:
66
inputs:
@@ -10,9 +10,22 @@ on:
1010
provider_matrix:
1111
description: 'Previous MongoDB Atlas Provider version matrix for migration tests (JSON array)'
1212
default: '[""]' # "" for latest version
13+
workflow_call:
14+
inputs:
15+
terraform_matrix:
16+
description: 'Terraform version matrix (JSON array)'
17+
type: string
18+
provider_matrix:
19+
description: 'Previous MongoDB Atlas Provider version matrix for migration tests (JSON array)'
20+
type: string
21+
default: '[""]' # "" for latest version
22+
atlas_cloud_env:
23+
description: 'Atlas cloud environment used, can be either `dev` or `qa`, empty for `dev`'
24+
type: string
25+
required: false
1326

1427
schedule:
15-
- cron: "0 0 * * *" # workflow runs every day at midnight UTC
28+
- cron: "0 0 * * 0-5" # workflow runs every day at midnight UTC except on Saturdays
1629

1730
concurrency:
1831
group: '${{ github.workflow }}'
@@ -64,6 +77,7 @@ jobs:
6477
uses: ./.github/workflows/acceptance-tests.yml
6578
with:
6679
terraform_version: ${{ matrix.terraform_version }}
80+
atlas_cloud_env: ${{ inputs.atlas_cloud_env }}
6781

6882
clean-after:
6983
needs: [mig-tests, acc-tests]
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 MongoDB Inc
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
set -euo pipefail
17+
get_last_day_of_month() {
18+
last_day_of_month=0
19+
case $1 in
20+
01|03|05|07|08|10|12)
21+
last_day_of_month=31 ;;
22+
04|06|09|11)
23+
last_day_of_month=30 ;;
24+
02)
25+
# February: check if it's a leap year
26+
if (( year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ) )); then
27+
last_day_of_month=29
28+
else
29+
last_day_of_month=28
30+
fi
31+
;;
32+
esac
33+
echo $last_day_of_month
34+
}
35+
36+
37+
add_end_support_date() {
38+
new_json_list=$(echo "$1" | jq -c '.[]' | while IFS= read -r obj; do
39+
input_date=$(echo "$obj" | jq -r '.published_at')
40+
41+
# Extract the year, month, day, hour, minute, and second from the input date
42+
year="${input_date:0:4}"
43+
month="${input_date:5:2}"
44+
hour="${input_date:11:2}"
45+
minute="${input_date:14:2}"
46+
second="${input_date:17:2}"
47+
last_day_of_month=$(get_last_day_of_month "$month")
48+
new_year=$((year + 2))
49+
50+
new_date="${new_year}-${month}-${last_day_of_month}T${hour}:${minute}:${second}Z"
51+
52+
echo "$obj" | jq --arg new_date "${new_date}" '.end_support_date = $new_date'
53+
done | jq -s '.')
54+
55+
echo "$new_json_list"
56+
}
57+
58+
page=1
59+
api_version="2022-11-28"
60+
61+
while true; do
62+
response=$(curl -s \
63+
--request GET \
64+
--url "https://api.github.com/repos/hashicorp/terraform/releases?per_page=100&page=$page" \
65+
--header "Authorization: Bearer $GITHUB_TOKEN" \
66+
--header "X-GitHub-Api-Version: $api_version")
67+
if [[ "$(printf '%s\n' "$response" | jq -e 'length == 0')" == "true" ]]; then
68+
break
69+
else
70+
versions=$(echo "$response" | jq -r '.[] | {version: .tag_name, published_at: .published_at}')
71+
filtered_versions_json=$(printf '%s\n' "${versions}" | jq -s '.')
72+
updated_date_versions=$(add_end_support_date "$filtered_versions_json")
73+
filtered_out_deprecated_versions=$(echo "$updated_date_versions" | jq 'map(select((.version | test("alpha|beta|rc"; "i") | not) and ((.end_support_date | fromdate) >= now))) | map(select(.version | endswith(".0")))')
74+
75+
if [ -z ${json_array+x} ]; then
76+
# If json_array is empty, assign filtered_versions directly
77+
json_array=$(jq -n --argjson filtered_versions "${filtered_out_deprecated_versions}" '$filtered_versions')
78+
else
79+
# If json_array is not empty, append filtered_versions to it
80+
json_array=$(echo "$json_array" | jq --argjson filtered_versions "${filtered_out_deprecated_versions}" '. + $filtered_versions')
81+
fi
82+
83+
((page++))
84+
fi
85+
done
86+
87+
versions_array=$(printf '%s\n' "${json_array}" | jq -r '.[] | .version')
88+
89+
formatted_output=$(echo "$versions_array" | awk 'BEGIN { ORS = "" } {gsub(/^v/,"",$1); gsub(/\.0$/,".x",$1); printf("%s\"%s\"", (NR==1?"":", "), $1)}' | sed 's/,"/," /g')
90+
91+
echo "[$formatted_output]" | jq -c .

0 commit comments

Comments
 (0)