Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Automates changing Terraform supported versions in provider do…
…cumentation (#2058)
- Loading branch information
Showing
6 changed files
with
213 additions
and
45 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
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,30 @@ | ||
name: Update Terraform Compatibility Matrix documentation | ||
|
||
# Checks if any changes are required to be made to our documentation for supported Terraform versions. Runs daily and can be triggered manually. | ||
on: | ||
schedule: | ||
- cron: "0 7 * * *" # Everyday at 7:00 AM | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update-tf-compatibility-matrix: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 | ||
- name: Update files | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: make update-tf-compatibility-matrix | ||
- name: Verify Changed files | ||
uses: tj-actions/verify-changed-files@843c0b95f87cd81a2efe729380c6d1f11fb3ea12 | ||
id: verify-changed-files | ||
- name: Create PR | ||
uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e | ||
if: steps.verify-changed-files.outputs.files_changed == 'true' | ||
with: | ||
title: "doc: Updates Terraform Compatibility Matrix documentation" | ||
commit-message: "doc: Updates Terraform Compatibility Matrix documentation" | ||
delete-branch: true | ||
branch: terraform-compatibility-matrix-update | ||
body: Automatic updates for Terraform Compatibility Matrix documentation |
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
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,102 @@ | ||
#!/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 | ||
|
||
input_array=$(./scripts/get-terraform-supported-versions.sh "true") | ||
|
||
indexFile="website/docs/index.html.markdown" | ||
|
||
transform_array() { | ||
local arr="$1" | ||
local updated_arr="[" | ||
local isFirstElement=true | ||
|
||
for ((i = 0; i < $(jq length <<<"$arr"); i++)); do | ||
version=$(jq -r ".[$i].version" <<<"$arr" | sed 's/^v//;s/\.0/.x/') | ||
published_at=$(jq -r ".[$i].published_at" <<<"$arr" | cut -dT -f1) | ||
end_support_date=$(jq -r ".[$i].end_support_date" <<<"$arr" | cut -dT -f1) | ||
|
||
if [ "$isFirstElement" = false ]; then | ||
updated_arr+="," | ||
fi | ||
updated_arr+="{\"version\": \"$version\", \"published_at\": \"$published_at\", \"end_support_date\": \"$end_support_date\"}" | ||
isFirstElement=false | ||
done | ||
|
||
updated_arr+="]" | ||
|
||
echo "$updated_arr" | ||
} | ||
|
||
generate_matrix_markup() { | ||
local output_array="$1" | ||
|
||
table="| HashiCorp Terraform Release | HashiCorp Terraform Release Date | HashiCorp Terraform Full Support End Date | MongoDB Atlas Support End Date |\n" | ||
table+="|:-------:|:------------:|:------------:|:------------:|\n" | ||
|
||
for ((i = 0; i < $(jq length <<<"$output_array"); i++)); do | ||
version=$(jq -r ".[$i].version" <<<"$output_array") | ||
published_at=$(jq -r ".[$i].published_at" <<<"$output_array") | ||
end_support_date=$(jq -r ".[$i].end_support_date" <<<"$output_array") | ||
|
||
table+="| $version | $published_at | $end_support_date | $end_support_date |\n" | ||
done | ||
|
||
echo -e "$table" | ||
} | ||
|
||
update_index_markdown_file() { | ||
local markup="$1" | ||
local tempFile="$indexFile.tmp" | ||
local placeholderStart="<!-- MATRIX_PLACEHOLDER_START -->" | ||
local placeholderEnd="<!-- MATRIX_PLACEHOLDER_END -->" | ||
local inPlaceholder=0 | ||
|
||
# Ensure the temp file is empty or does not exist | ||
: > "$tempFile" | ||
|
||
while IFS= read -r line || [[ -n "$line" ]]; do | ||
if [[ "$line" == "$placeholderStart" ]]; then | ||
inPlaceholder=1 | ||
echo "$line" >>"$tempFile" | ||
echo "$markup" >>"$tempFile" | ||
continue | ||
fi | ||
|
||
if [[ "$line" == "$placeholderEnd" ]]; then | ||
inPlaceholder=0 | ||
echo "$line" >>"$tempFile" | ||
continue | ||
fi | ||
|
||
if [[ $inPlaceholder -eq 0 ]]; then | ||
echo "$line" >>"$tempFile" | ||
fi | ||
done <"$indexFile" | ||
|
||
mv "$tempFile" "$indexFile" | ||
|
||
echo "Updated Terraform version compatibility matrix in $indexFile" | ||
} | ||
|
||
# Transform the array data | ||
updated_array=$(transform_array "$input_array") | ||
|
||
# Generate markup for the compatibility matrix | ||
markup=$(generate_matrix_markup "$updated_array") | ||
|
||
# Update the Markdown file with the generated markup | ||
update_index_markdown_file "$markup" |
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