-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Schedules run of acceptance and migration tests for all HashiC…
…orp 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]>
- Loading branch information
1 parent
e2a1e06
commit 71f86c5
Showing
3 changed files
with
157 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: "HashiCorp Terraform Compatibility Matrix" | ||
run-name: 'HashiCorp Terraform Compatibility Matrix ${{ inputs.atlas_cloud_env }}' | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 1-7 * 6" # runs first Saturday of the month at midnight UTC | ||
workflow_dispatch: | ||
inputs: | ||
atlas_cloud_env: | ||
description: 'Atlas cloud environment used, can be either `dev` or `qa`, empty for `dev`. Migration tests will always use `dev`' | ||
type: string | ||
required: false | ||
test_group: | ||
description: 'Test group to run, e.g. advanced_cluster, empty for all' | ||
type: string | ||
required: false | ||
|
||
jobs: | ||
get-supported-versions: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | ||
- name: Get HashiCorp Terraform supported versions | ||
shell: bash | ||
id: get-terraform-supported-versions | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
output=$(./scripts/get-terraform-supported-versions.sh) | ||
quoted_output=$(echo "${output}" | jq -c .) | ||
echo "supported_versions=${quoted_output}" >> "${GITHUB_OUTPUT}" | ||
outputs: | ||
supported_versions: ${{ steps.get-terraform-supported-versions.outputs.supported_versions }} | ||
|
||
|
||
run-test-supported-versions: | ||
needs: ["get-supported-versions"] | ||
if: ${{ !cancelled() }} | ||
strategy: | ||
max-parallel: 1 | ||
fail-fast: false | ||
matrix: | ||
terraform_version: '${{ fromJSON(needs.get-supported-versions.outputs.supported_versions) }}' | ||
name: terrafrom-compatibility-${{ matrix.terraform_version }}-${{ inputs.atlas_cloud_env || 'dev' }} | ||
secrets: inherit | ||
uses: ./.github/workflows/test-suite.yml | ||
with: | ||
terraform_matrix: '["${{ matrix.terraform_version }}"]' | ||
atlas_cloud_env: ${{ inputs.atlas_cloud_env }} | ||
|
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,91 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2024 MongoDB Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
set -euo pipefail | ||
get_last_day_of_month() { | ||
last_day_of_month=0 | ||
case $1 in | ||
01|03|05|07|08|10|12) | ||
last_day_of_month=31 ;; | ||
04|06|09|11) | ||
last_day_of_month=30 ;; | ||
02) | ||
# February: check if it's a leap year | ||
if (( year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ) )); then | ||
last_day_of_month=29 | ||
else | ||
last_day_of_month=28 | ||
fi | ||
;; | ||
esac | ||
echo $last_day_of_month | ||
} | ||
|
||
|
||
add_end_support_date() { | ||
new_json_list=$(echo "$1" | jq -c '.[]' | while IFS= read -r obj; do | ||
input_date=$(echo "$obj" | jq -r '.published_at') | ||
# Extract the year, month, day, hour, minute, and second from the input date | ||
year="${input_date:0:4}" | ||
month="${input_date:5:2}" | ||
hour="${input_date:11:2}" | ||
minute="${input_date:14:2}" | ||
second="${input_date:17:2}" | ||
last_day_of_month=$(get_last_day_of_month "$month") | ||
new_year=$((year + 2)) | ||
new_date="${new_year}-${month}-${last_day_of_month}T${hour}:${minute}:${second}Z" | ||
echo "$obj" | jq --arg new_date "${new_date}" '.end_support_date = $new_date' | ||
done | jq -s '.') | ||
|
||
echo "$new_json_list" | ||
} | ||
|
||
page=1 | ||
api_version="2022-11-28" | ||
|
||
while true; do | ||
response=$(curl -s \ | ||
--request GET \ | ||
--url "https://api.github.com/repos/hashicorp/terraform/releases?per_page=100&page=$page" \ | ||
--header "Authorization: Bearer $GITHUB_TOKEN" \ | ||
--header "X-GitHub-Api-Version: $api_version") | ||
if [[ "$(printf '%s\n' "$response" | jq -e 'length == 0')" == "true" ]]; then | ||
break | ||
else | ||
versions=$(echo "$response" | jq -r '.[] | {version: .tag_name, published_at: .published_at}') | ||
filtered_versions_json=$(printf '%s\n' "${versions}" | jq -s '.') | ||
updated_date_versions=$(add_end_support_date "$filtered_versions_json") | ||
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")))') | ||
|
||
if [ -z ${json_array+x} ]; then | ||
# If json_array is empty, assign filtered_versions directly | ||
json_array=$(jq -n --argjson filtered_versions "${filtered_out_deprecated_versions}" '$filtered_versions') | ||
else | ||
# If json_array is not empty, append filtered_versions to it | ||
json_array=$(echo "$json_array" | jq --argjson filtered_versions "${filtered_out_deprecated_versions}" '. + $filtered_versions') | ||
fi | ||
|
||
((page++)) | ||
fi | ||
done | ||
|
||
versions_array=$(printf '%s\n' "${json_array}" | jq -r '.[] | .version') | ||
|
||
formatted_output=$(echo "$versions_array" | awk 'BEGIN { ORS = "" } {gsub(/^v/,"",$1); gsub(/\.0$/,".x",$1); printf("%s\"%s\"", (NR==1?"":", "), $1)}' | sed 's/,"/," /g') | ||
|
||
echo "[$formatted_output]" | jq -c . |