Skip to content

Commit

Permalink
update release helm chart to support new chart (#260)
Browse files Browse the repository at this point in the history
* update release helm chart to support new chart

* update env var

* fix typo

* Update .github/scripts/latest_version_release.sh

Co-authored-by: OriBenHur <102898236+OriBenHur-akeyless@users.noreply.github.com>

* align syntax convention

---------

Co-authored-by: OriBenHur <102898236+OriBenHur-akeyless@users.noreply.github.com>
  • Loading branch information
omriezra and OriBenHur-akeyless authored Nov 21, 2024
1 parent a5517de commit 039f64b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 52 deletions.
103 changes: 64 additions & 39 deletions .github/scripts/latest_version_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,79 @@ service=$(echo "$GITHUB_CONTEXT" | jq -r '.payload.service | select (.!=null)')
major_minor_patch=$(echo "$GITHUB_CONTEXT" | jq -r '.payload.major_minor_patch | select (.!=null)')
app_version=$(echo "$GITHUB_CONTEXT" | jq -r '.payload.app_version | select (.!=null)')

charts=()
if [[ "${service}" == "gateway" ]]; then
chart_dir="akeyless-api-gateway"
charts+=("akeyless-api-gateway" "akeyless-gateway")
elif [[ "${service}" == "zero-trust-bastion" ]]; then
chart_dir="akeyless-secure-remote-access"
charts+=("akeyless-secure-remote-access" "akeyless-gateway")
elif [[ "${service}" == "zt-portal" ]]; then
chart_dir="akeyless-secure-remote-access"
charts+=("akeyless-secure-remote-access")
elif [[ "${service}" == "zero-trust-web-access" ]]; then
chart_dir="akeyless-zero-trust-web-access"
charts+=("akeyless-zero-trust-web-access")
elif [[ "${service}" == "k8s-webhook" ]]; then
chart_dir="akeyless-k8s-secrets-injection"
charts+=("akeyless-k8s-secrets-injection")
else
die "Bad service name"
fi

pushd "$GITHUB_WORKSPACE/charts/$chart_dir"
# bump chart version
chart_version=$(grep '^version:[[:space:]][[:digit:]]' Chart.yaml | awk '{print $2}') || die "Failed to retrieve current chart version"
bump_version "${chart_version}" "${major_minor_patch}"
new_chart_version=$new_version && echo "The new Chart version is: ${new_chart_version}"
sed -i "s/version:.*/version: ${new_chart_version}/g" Chart.yaml

# edit app version
if [[ "${chart_dir}" == "akeyless-secure-remote-access" ]]; then
# edit app service version
if [[ "${service}" == "zero-trust-bastion" ]]; then
sra_inner_chart="ztbVersion"
elif [[ "${service}" == "zt-portal" ]]; then
sra_inner_chart="ztpVersion"
else
die "Bad SRA service name"
fi

sed -i "s/${sra_inner_chart}.*/${sra_inner_chart}: ${app_version}/g" Chart.yaml
# edit sra app version
ztb_app_ver=$(grep 'ztbVersion' Chart.yaml | awk '{print $2}')
ztp_app_ver=$(grep 'ztpVersion' Chart.yaml | awk '{print $2}')
sed -i "s/appVersion.*/appVersion: ${ztb_app_ver}_${ztp_app_ver}/g" Chart.yaml
updated_charts_summary=()
for chart in "${charts[@]}"; do
pushd "$GITHUB_WORKSPACE/charts/${chart}"
# bump chart version
chart_version=$(grep '^version:[[:space:]][[:digit:]]' Chart.yaml | awk '{print $2}') || die "Failed to retrieve current chart version"
bump_version "${chart_version}" "${major_minor_patch}"
new_chart_version=${new_version} && echo "The new Chart version is: ${new_chart_version}"
sed -i "s/version:.*/version: ${new_chart_version}/g" Chart.yaml

else
sed -i "s/appVersion.*/appVersion: ${app_version}/g" Chart.yaml
fi
# edit app version for akeyless-secure-remote-access
if [[ "${{chart}" == "akeyless-secure-remote-access" ]]; then
# edit app service version
if [[ "${service}" == "zero-trust-bastion" ]]; then
sra_inner_chart="ztbVersion"
elif [[ "${service}" == "zt-portal" ]]; then
sra_inner_chart="ztpVersion"
else
die "Bad SRA service name"
fi

sed -i "s/${sra_inner_chart}.*/${sra_inner_chart}: ${app_version}/g" Chart.yaml
# edit sra app version
ztb_app_ver=$(grep 'ztbVersion' Chart.yaml | awk '{print $2}')
ztp_app_ver=$(grep 'ztpVersion' Chart.yaml | awk '{print $2}')
app_version="${ztb_app_ver}_${ztp_app_ver}"
sed -i "s/appVersion.*/appVersion: ${app_version}/g" Chart.yaml

elif [[ "${chart}" == "akeyless-gateway" ]]; then
# edit app version for akeyless-gateway
if [[ "${service}" == "zero-trust-bastion" ]]; then
gateway_inner_chart="sraVersion"
elif [[ "${service}" == "gateway" ]]; then
gateway_inner_chart="gatewayVersion"
else
die "Bad gateway service name"
fi
sed -i "s/${gateway_inner_chart}.*/${gateway_inner_chart}: ${app_version}/g" Chart.yaml
# edit sra app version
gateway_app_ver=$(grep 'gatewayVersion' Chart.yaml | awk '{print $2}')
sra_app_ver=$(grep 'sraVersion' Chart.yaml | awk '{print $2}')
sed -i "s/appVersion.*/appVersion: ${gateway_app_ver}_${sra_app_ver}/g" Chart.yaml
app_version="${gateway_app_ver}_${sra_app_ver}"
else
sed -i "s/appVersion.*/appVersion: ${app_version}/g" Chart.yaml
fi

git add -A && git commit -m "Updated ${service} helm chart version to latest: ${app_version}" || die "Failed to commit changes to git"
git push origin HEAD

git add -A && git commit -m "Updated ${service} helm chart version to latest: ${app_version}" || die "Failed to commit changes to git"
git push origin HEAD
echo "${chart} app version was successfully updated to latest: ${app_version}"
echo "${chart} Helm chart version was updated to: ${new_chart_version}"
updated_charts_summary+=("${chart} app version: ${app_version} Helm chart version: ${new_chart_version}")
popd
done

chart_name="$chart_dir"
echo "$chart_name app version was successfully updated to latest: ${app_version}"
echo "$chart_name Helm chart version was updated to: ${new_chart_version}"
echo "new_chart_version=$new_chart_version" >>$GITHUB_ENV
echo "chart_name=$chart_name" >>$GITHUB_ENV
popd
echo "new_chart_version=$new_chart_version" >> "${GITHUB_ENV}"
echo "new_chart_version=$new_chart_version" >> "${GITHUB_OUTPUT}"
echo "charts=${charts[*]}" >> "${GITHUB_ENV}"
echo "charts=${charts[*]}" >> "${GITHUB_OUTPUT}"
echo "updated_charts_summary=${updated_charts_summary[*]}" >> "${GITHUB_ENV}"
echo "updated_charts_summary=${updated_charts_summary[*]}" >> "${GITHUB_OUTPUT}"
25 changes: 12 additions & 13 deletions .github/workflows/helm_latest_version_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ env:
major_minor_patch: ${{ github.event.deployment.payload.major_minor_patch }}
app_version: ${{ github.event.deployment.payload.app_version }}

run-name: "Release chart for service: ${{ github.event.deployment.payload.service }} version: ${{ github.event.deployment.payload.app_version }} ${{ github.event.deployment.payload.major_minor_patch }}"

jobs:
update-latest-helm-chart-version:
if: github.event.deployment.task == 'update-latest-version'
runs-on: ubuntu-20.04
outputs:
new_chart_version: ${{ steps.vars.outputs.new_chart_version }}
chart_name: ${{ steps.vars.outputs.chart_name }}
new_chart_version: ${{ steps.release.outputs.new_chart_version }}
charts: ${{ steps.release.outputs.charts }}
updated_charts_summary: ${{ steps.release.outputs.updated_charts_summary }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -33,16 +36,11 @@ jobs:
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Update latest helm chart version
id: release
env:
GITHUB_CONTEXT: ${{ toJson(github.event.deployment) }}
run: .github/scripts/latest_version_release.sh

- name: Set Change Variables
id: vars
run: |
echo new_chart_version=${{ env.new_chart_version }} >> $GITHUB_OUTPUT
echo chart_name=${{ env.chart_name }} >> $GITHUB_OUTPUT
- uses: actions/github-script@v7
with:
github-token: ${{ secrets.AKEYLESS_CI_COMMIT_PUSH_TOKEN }}
Expand All @@ -61,16 +59,17 @@ jobs:
if: (github.event.deployment.task == 'update-latest-version')
env:
new_chart_version: ${{ needs.update-latest-helm-chart-version.outputs.new_chart_version }}
chart_name: ${{ needs.update-latest-helm-chart-version.outputs.chart_name }}
charts: ${{ needs.update-latest-helm-chart-version.outputs.charts }}
updated_charts_summary: ${{ needs.update-latest-helm-chart-version.outputs.updated_charts_summary }}
steps:
- name: Prepare Slack Message On Success
id: slack-message-success-creator
run: |
SLACK_MESSAGE="*Service:* $service
*Bump version:* $major_minor_patch
*App Version:* $app_version
*Chart:* $chart_name
*New Chart Version:* $new_chart_version
*Charts:* $charts
*Release summary:* $updated_charts_summary
:helm:"
delimiter="$(openssl rand -hex 8)"
echo "slack-message<<${delimiter}" >> $GITHUB_ENV
Expand All @@ -96,15 +95,15 @@ jobs:
needs: [ update-latest-helm-chart-version ]
if: (failure() && needs.*.result != 'success') && (github.event.deployment.task == 'update-latest-version')
env:
chart_name: ${{ needs.update-latest-helm-chart-version.outputs.chart_name }}
charts: ${{ needs.update-latest-helm-chart-version.outputs.charts }}
steps:
- name: Prepare Slack Message On Failure
id: slack-message-failure-creator
run: |
SLACK_MESSAGE="*Service:* $service
*Bump version:* $major_minor_patch
*App Version:* $app_version
*Chart:* $chart_name
*Chart:* $charts
*Status:* Failure
:terminator:"
delimiter="$(openssl rand -hex 8)"
Expand Down

0 comments on commit 039f64b

Please sign in to comment.