@@ -21,35 +21,22 @@ CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
2121source " ${CUR_DIR} " /validate_semver.sh
2222
2323GITHUB_TOKEN=" ${GITHUB_TOKEN:- } "
24-
2524GIT_CONFIG_USER_NAME=" ${GIT_CONFIG_USER_NAME:- } "
2625GIT_CONFIG_USER_EMAIL=" ${GIT_CONFIG_USER_EMAIL:- } "
27-
2826UPSTREAM_OPERATOR_NAME=" ${UPSTREAM_OPERATOR_NAME:- " sail-operator" } "
2927OWNER=" ${OWNER:- " istio-ecosystem" } "
3028HUB_REPO_URL=" ${HUB_REPO_URL:- github.com/ ${OWNER} / ${UPSTREAM_OPERATOR_NAME} } "
3129HUB_HELM_BRANCH=" ${HUB_HIVE_BRANCH:- " gh-pages" } "
32- HUB_HELM_ARTIFACT_URL=" https://${HUB_REPO_URL} /releases/download/${OPERATOR_VERSION} " /
33-
34- : " ${OPERATOR_VERSION:? " Missing OPERATOR_VERSION variable" } "
3530
36- show_help () {
31+ function show_help() {
3732 cat << EOF
38-
3933 Publish Sail Operator helm artifacts to gh-pages branch
40- It will allow to install Sail Operator via "helm add repo"
41-
42- ./publish-helm-artifacts.sh [options]
43-
34+ Usage: ./publish-helm-artifacts.sh [options]
4435EOF
4536}
4637
47- function update_repo_index() {
48- echo " Update Helm repo index with new artifact"
49- }
50-
5138function prepare_repo() {
52- echo " Prepare repository"
39+ echo " Preparing repository... "
5340
5441 if [ -z " ${GITHUB_TOKEN} " ]; then
5542 die " Please provide GITHUB_TOKEN"
@@ -61,48 +48,70 @@ function prepare_repo() {
6148 TMP_DIR=$( mktemp -d)
6249 trap ' rm -rf "${TMP_DIR}"' EXIT
6350
64- git clone --single-branch --depth=1 --branch " ${HUB_HELM_BRANCH} " " https://${GIT_USER} : ${ GITHUB_TOKEN} @${HUB_REPO_URL} " " ${TMP_DIR} /${UPSTREAM_OPERATOR_NAME} "
51+ git clone --single-branch --depth=1 --branch " ${HUB_HELM_BRANCH} " " https://${GITHUB_TOKEN} @${HUB_REPO_URL} " " ${TMP_DIR} /${UPSTREAM_OPERATOR_NAME} "
6552 cd " ${TMP_DIR} /${UPSTREAM_OPERATOR_NAME} "
6653
6754 if ! git config user.name; then
6855 git config user.name " ${GIT_CONFIG_USER_NAME} "
6956 fi
70-
7157 if ! git config user.email; then
7258 git config user.email " ${GIT_CONFIG_USER_EMAIL} "
7359 fi
7460}
7561
76- function fetch_released_artifact () {
77- echo " Fetch released helm artifact "
62+ function get_latest_release_version () {
63+ echo " Fetching latest release version from GitHub API... "
7864
79- wget " ${HUB_HELM_ARTIFACT_URL} /${UPSTREAM_OPERATOR_NAME} -${OPERATOR_VERSION} .tgz"
65+ latest_version=$( curl -s \
66+ " https://api.github.com/repos/${OWNER} /${UPSTREAM_OPERATOR_NAME} /releases/latest" | \
67+ jq -r .tag_name)
68+ echo " Latest release version: ${latest_version} "
8069}
8170
82- function update_helm_repo_index() {
83- echo " Update index of Helm repo"
84- local helm_branch=" update_helm_artifact_${OPERATOR_VERSION} "
71+ function check_version_in_index() {
72+ echo " Checking if version ${latest_version} exists in index.yaml..."
8573
86- git checkout -b " $helm_branch "
87- helm repo index --merge index.yaml . --url " ${HUB_HELM_ARTIFACT_URL} "
74+ if grep -q " version: ${latest_version} " index.yaml; then
75+ echo " Version ${latest_version} is already in index.yaml. Skipping update."
76+ return 0
77+ else
78+ echo " Version ${latest_version} not found in index.yaml. Updating index."
79+ return 1
80+ fi
81+ }
82+
83+ function add_version_to_index() {
84+ echo " Adding new version to Helm repo index..."
85+
86+ wget " https://${HUB_REPO_URL} /releases/download/${latest_version} /${UPSTREAM_OPERATOR_NAME} -${latest_version} .tgz"
87+ helm repo index --merge index.yaml . --url " https://${HUB_REPO_URL} /releases/download/${latest_version} /"
88+
89+ git checkout -b " update_helm_artifact_${latest_version} "
8890 git add index.yaml
89- git commit -m " Add new sail-operator chart release - ${OPERATOR_VERSION} "
90- git push origin " $helm_branch "
91+ git commit -m " Add new sail-operator chart release - ${latest_version} "
92+ git push origin " update_helm_artifact_${latest_version} "
93+
94+ create_pull_request
95+ }
9196
97+ function create_pull_request {
98+ echo " Creating pull request..."
9299 PAYLOAD=" ${TMP_DIR} /PAYLOAD"
93100
94101 jq -c -n \
95- --arg msg " Add new sail-operator chart release - ${OPERATOR_VERSION } " \
96- --arg head " ${OWNER} :${helm_branch }" \
102+ --arg msg " Add new sail-operator chart release - ${latest_version } " \
103+ --arg head " ${OWNER} :update_helm_artifact_ ${latest_version }" \
97104 --arg base " ${HUB_HELM_BRANCH} " \
98- --arg title " Helm artifact ${OPERATOR_VERSION } " \
105+ --arg title " Helm artifact ${latest_version } " \
99106 ' {head: $head, base: $base, title: $title, body: $msg }' > " ${PAYLOAD} "
100107
101- curl --fail-with-body - X POST \
108+ curl -X POST \
102109 -H " Authorization: token ${GITHUB_TOKEN} " \
103110 -H " Accept: application/vnd.github.v3+json" \
104- https://api.github.com/repos/" ${OWNER} /${UPSTREAM_OPERATOR_NAME} " /pulls \
105- --data-binary " @${PAYLOAD} "
111+ -d @" ${PAYLOAD} " \
112+ " https://api.github.com/repos/${OWNER} /${UPSTREAM_OPERATOR_NAME} /pulls"
113+
114+ rm " ${PAYLOAD} "
106115}
107116
108117while test $# -gt 0; do
@@ -112,12 +121,14 @@ while test $# -gt 0; do
112121 exit 0
113122 ;;
114123 * )
115- echo " Unknown param $1 "
124+ echo " Unknown parameter $1 "
116125 exit 1
117126 ;;
118127 esac
119128done
120129
121130prepare_repo
122- fetch_released_artifact
123- update_helm_repo_index
131+ get_latest_release_version
132+ if ! check_version_in_index; then
133+ add_version_to_index
134+ fi
0 commit comments