-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathupdate_versions.sh
executable file
·140 lines (105 loc) · 6.09 KB
/
update_versions.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
#This script only works on Linux, not on MacOs. On MacOS, run it inside the toolbox itself.
github_get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | jq -r '.tag_name' | sed 's/v//g'
}
pypi_get_latest_release_remove_rcs() {
#get all releases by they keys(=version number) in order, starting with the highest release
RETURNEDLIST=$(curl -s "https://pypi.org/pypi/$1/json" | jq -r '.releases | keys | sort_by(.) | reverse | .[]')
#go through all releases and echo/return the first which does not alpha/beta/rc identifiers, then break loop
for version in $RETURNEDLIST
do
if [[ "${version}" != *"rc"* && "${version}" != *"b"* && "${version}" != *"a"* ]];
then
echo $version
break
fi
done
}
pypi_get_latest_release() {
curl -s "https://pypi.org/pypi/$1/json" | jq -r '.releases | keys | .[]' | sort -V | tail -n 1
}
replace_version_in_args_file() {
sed -i "s/$1=.*/$1=$2/g" $3
}
fetch_latest_gcloud_version() {
html_content=$(curl -sL "https://cloud.google.com/sdk/docs/release-notes")
latest_version=$(echo "$html_content" | grep -oP '\b[0-9]+\.[0-9]+\.[0-9]+\b' | sort -V | tail -1)
echo "$latest_version"
}
########BASE########
echo "Starting with base versions contained in versions base and complete...."
UBUNTU_VERSION="22.04"
# Manually set base image version ubuntu
replace_version_in_args_file "UBUNTU_VERSION" $UBUNTU_VERSION "args_base.args"
echo "Updating Docker version"
DOCKER_VERSION=$(github_get_latest_release "moby/moby")
replace_version_in_args_file "DOCKER_VERSION" $DOCKER_VERSION "args_base.args"
echo "Updating Kubectl version"
KUBECTL_VERSION=$(github_get_latest_release "kubernetes/kubernetes")
replace_version_in_args_file "KUBECTL_VERSION" $KUBECTL_VERSION "args_base.args"
echo "Updating Helm version"
HELM_VERSION=$(github_get_latest_release "helm/helm")
replace_version_in_args_file "HELM_VERSION" $HELM_VERSION "args_base.args"
echo "Updating Terraform version"
TERRAFORM_VERSION=$(github_get_latest_release "hashicorp/terraform")
replace_version_in_args_file "TERRAFORM_VERSION" $TERRAFORM_VERSION "args_base.args"
echo "Updating Azure-CLI version"
AZ_CLI_VERSION=$(pypi_get_latest_release "azure-cli")
replace_version_in_args_file "AZ_CLI_VERSION" $AZ_CLI_VERSION "args_base.args"
echo "Updating OpenSSH version"
OPENSSH_MAJOR_VERSION=$(curl -s "https://api.github.com/repos/openssh/openssh-portable/tags" | jq -r '.[0].name' | awk '{print substr($0,3,1)}')
OPENSSH_MINOR_VERSION=$(curl -s "https://api.github.com/repos/openssh/openssh-portable/tags" | jq -r '.[0].name' | awk '{print substr($0,5,1)}')
OPENSSH_PATCH_VERSION=$(curl -s "https://api.github.com/repos/openssh/openssh-portable/tags" | jq -r '.[0].name' | awk '{print substr($0,8,1)}')
OPENSSH_VERSION="${OPENSSH_MAJOR_VERSION}.${OPENSSH_MINOR_VERSION}p${OPENSSH_PATCH_VERSION}"
replace_version_in_args_file "OPENSSH_VERSION" $OPENSSH_VERSION "args_base.args"
echo "Updating CRICTL version"
CRICTL_VERSION=$(github_get_latest_release "kubernetes-sigs/cri-tools")
replace_version_in_args_file "CRICTL_VERSION" $CRICTL_VERSION "args_base.args"
echo "Updating Velero version"
VELERO_VERSION=$(github_get_latest_release "vmware-tanzu/velero")
replace_version_in_args_file "VELERO_VERSION" $VELERO_VERSION "args_base.args"
echo "Updating Terraform Sentinel version"
SENTINEL_VERSION=$(curl -sS "https://api.releases.hashicorp.com/v1/releases/sentinel/latest" | jq -r '.version')
replace_version_in_args_file "SENTINEL_VERSION" $SENTINEL_VERSION "args_base.args"
echo "Updating Stern version"
STERN_VERSION=$(github_get_latest_release "stern/stern")
replace_version_in_args_file "STERN_VERSION" $STERN_VERSION "args_base.args"
echo "Updating Kubelogin version"
KUBELOGIN_VERSION=$(github_get_latest_release "Azure/kubelogin")
replace_version_in_args_file "KUBELOGIN_VERSION" $KUBELOGIN_VERSION "args_base.args"
########OPTIONAL########
echo "Starting with optional versions contained in version complete...."
echo "Updating AWS-CLI version"
AWS_CLI_VERSION=$(pypi_get_latest_release "awscli")
replace_version_in_args_file "AWS_CLI_VERSION" $AWS_CLI_VERSION "args_optional.args"
echo "Updating Ansible version"
ANSIBLE_VERSION=$(pypi_get_latest_release_remove_rcs "ansible")
replace_version_in_args_file "ANSIBLE_VERSION" $ANSIBLE_VERSION "args_optional.args"
echo "Updating Jinja version"
JINJA_VERSION=$(pypi_get_latest_release "Jinja2")
replace_version_in_args_file "JINJA_VERSION" $JINJA_VERSION "args_optional.args"
echo "Updating Vault version"
VAULT_VERSION=$(github_get_latest_release "hashicorp/vault")
replace_version_in_args_file "VAULT_VERSION" $VAULT_VERSION "args_optional.args"
echo "Updating README.MD & build.sh"
RELEASE_DATE=$(date --rfc-3339=date)
replace_version_in_args_file "latest" "${RELEASE_DATE}_base" "README.md"
replace_version_in_args_file "project" "${RELEASE_DATE}_base" "README.md"
replace_version_in_args_file "complete" "${RELEASE_DATE}_complete" "README.md"
replace_version_in_args_file "IMAGE_TAG" "\"${RELEASE_DATE}\"" "build.sh"
OC_CLI_VERSION=$(curl -s https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/ | grep -o 'openshift-client-linux-[0-9]*\.[0-9]*\.[0-9]*\.tar\.gz' | sort -V | tail -1 | sed 's/openshift-client-linux-\([0-9]*\.[0-9]*\.[0-9]*\)\.tar\.gz/\1/')
replace_version_in_args_file "OC_CLI_VERSION" $OC_CLI_VERSION "args_optional.args"
GCLOUD_VERSION=$(fetch_latest_gcloud_version)
replace_version_in_args_file "GCLOUD_VERSION" "$GCLOUD_VERSION" "args_optional.args"
######## README.md #######
table_start_line=$(awk '/^\| RELEASE / {print NR}' README.md)
offset=1
insert_line=$((table_start_line + offset))
# Construct the new lines with updated versions
new_lines="| ${RELEASE_DATE}_complete | $UBUNTU_VERSION | $DOCKER_VERSION | $KUBECTL_VERSION | $HELM_VERSION | $TERRAFORM_VERSION | $AZ_CLI_VERSION | $OPENSSH_VERSION | $CRICTL_VERSION | $VELERO_VERSION | $SENTINEL_VERSION | $STERN_VERSION | $KUBELOGIN_VERSION | $OC_CLI_VERSION | $AWS_CLI_VERSION | $GCLOUD_VERSION | $ANSIBLE_VERSION | $JINJA_VERSION | $VAULT_VERSION |"
sed -i "${insert_line}a\\
${new_lines}" README.md
#TODO