-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-tflint-aws.sh
executable file
·38 lines (30 loc) · 1.08 KB
/
update-tflint-aws.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# Define the GitHub repository owner and name
owner="terraform-linters"
repo="tflint-ruleset-aws"
# Use curl to make a GET request to the GitHub API to get the latest release information
response=$(curl -s "https://api.github.com/repos/$owner/$repo/releases/latest")
# Check if the request was successful
if [ $? -ne 0 ]; then
echo "Failed to fetch release information."
exit 1
fi
# Parse the JSON response to extract the latest release version
latest_version=$(echo "$response" | grep -oP '"tag_name": "\K([^"]+)')
if [ -z "$latest_version" ]; then
echo "Failed to extract latest version."
exit 1
fi
echo "Latest version of $repo is $latest_version"
strip_version=$(echo "$latest_version" | sed 's/v//g')
hcl_file="./.tflint.hcl"
# Use awk to update the version value in the .hcl file within the plugin block
awk -i inplace '
/plugin "aws" \{/,/\}/ {
if ($0 ~ /version = ".+"/) {
sub(/version = ".+"/, "version = \""new_version"\"")
}
}
{ print }
' new_version="$strip_version" "$hcl_file"
echo "Updated version in $hcl_file to $strip_version"