Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions scripts/get-version-matrix.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
#!/bin/bash
set -e
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0


function get_latest_version() {
curl -s https://api.github.com/repos/hashicorp/terraform/git/refs/tags | \
jq ".[] | .ref | split(\"/\") | .[2] | select(. | startswith(\"$1\"))" | \
sort -V -r | head -1
if output=$(curl -s -f https://api.github.com/repos/hashicorp/terraform/git/refs/tags); then
echo "$output" | \
jq ".[] | .ref | split(\"/\") | .[2] | select(. | startswith(\"$1\"))" | \
sort -V -r | head -1
else
echo "Error: Failed to connect to GitHub API" >&2
exit 1
fi
}

echo "matrix=[$(get_latest_version v1.0), $(get_latest_version v1.3), $(get_latest_version v1.5), $(get_latest_version v1.7), $(get_latest_version v1.9)]" >> "$GITHUB_OUTPUT"
# Call get_latest_version for each version and handle errors
v1_0=$(get_latest_version v1.0) || exit 1
v1_3=$(get_latest_version v1.3) || exit 1
v1_5=$(get_latest_version v1.5) || exit 1
v1_7=$(get_latest_version v1.7) || exit 1
v1_9=$(get_latest_version v1.9) || exit 1

# Construct the matrix
echo "matrix=[$v1_0, $v1_3, $v1_5, $v1_7, $v1_9]" >> "$GITHUB_OUTPUT"
Loading