From cb7d2e350e84fdbbab6d7cf77498b10ba14f361c Mon Sep 17 00:00:00 2001 From: Vitalii Savitskii Date: Thu, 30 May 2024 13:50:23 +0200 Subject: [PATCH] Ability to provide app version from action for helm install (#74) * Ability to provide app version from action for helm install * Add ability to override chart version * Fix * Incorrect build condition * Add parameters to readme * Set correct versions in the `helm push` command * Self-review fixes --- README.md | 18 ++++++++++-------- build_helm_chart/action.yaml | 12 ++++++++++++ build_helm_chart/build_chart.sh | 21 +++++++++++++++++---- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index fca9508..bafbf25 100644 --- a/README.md +++ b/README.md @@ -126,14 +126,16 @@ Allows to build helm chart and push it to remote container repository. This action relies on git tags to be present in order to generate an artifact tag. ### Inputs -| Name | Description | Optional | Default value | -|----------------------------|:-----------------------------------------------|----------|---------------| -| container_registry_address | Container registry address | False | | -| application: | Application name | False | | -| container_registry_user | Container registry username | False | | -| container_registry_token | Container registry access token | False | | -| helm_version | Version of helm to install | True | 3.9.2 | -| helm_directory | Location of helm chart related to project root | True | .helm | +| Name | Description | Optional | Default value | +|----------------------------|:-----------------------------------------------------------------------------------|----------|---------------| +| container_registry_address | Container registry address | False | | +| application: | Application name | False | | +| container_registry_user | Container registry username | False | | +| container_registry_token | Container registry access token | False | | +| helm_version | Version of helm to install | True | 3.9.2 | +| helm_directory | Location of helm chart related to project root | True | .helm | +| app_version | Application version to use for the chart. If omitted, the latest tag will be used. | True | | +| chart_version | Chart version to use for the chart. If omitted, the latest tag will be used. | True | | ### Outputs No outputs defined diff --git a/build_helm_chart/action.yaml b/build_helm_chart/action.yaml index 979b212..9692b9f 100644 --- a/build_helm_chart/action.yaml +++ b/build_helm_chart/action.yaml @@ -32,6 +32,16 @@ inputs: required: false default: '.helm' + app_version: + description: Application version to use for the chart. If omitted, the latest tag will be used. + required: false + default: '' + + chart_version: + description: Chart version to use for the chart. If omitted, the latest tag will be used. + required: false + default: '' + runs: using: "composite" steps: @@ -45,4 +55,6 @@ runs: REPO_LOGIN: ${{ inputs.container_registry_user }} REPO_TOKEN: ${{ inputs.container_registry_token }} APPLICATION: ${{ inputs.application }} + APP_VERSION: ${{ inputs.app_version }} + CHART_VERSION: ${{ inputs.chart_version }} shell: bash diff --git a/build_helm_chart/build_chart.sh b/build_helm_chart/build_chart.sh index 4f996bf..5152fc0 100755 --- a/build_helm_chart/build_chart.sh +++ b/build_helm_chart/build_chart.sh @@ -16,11 +16,24 @@ set -Eeuo pipefail -appVersion=$(git describe --tags --abbrev=7) -sed -i "s/appVersion: 0.0.0/appVersion: \"${appVersion:1}\"/" Chart.yaml -sed -i "s/^version: .*/version: \"$appVersion\"/" Chart.yaml + +if [[ -z "$APP_VERSION" ]]; then + appVersion=$(git describe --tags --abbrev=7) +else + appVersion="$APP_VERSION" +fi; + +if [[ -z "$CHART_VERSION" ]]; then + chartVersion=$(git describe --tags --abbrev=7) +else + chartVersion="$CHART_VERSION" +fi; + + +sed -i "s/appVersion: 0.0.0/appVersion: \"$appVersion\"/" Chart.yaml +sed -i "s/^version: .*/version: \"$chartVersion\"/" Chart.yaml helm package . echo "$REPO_TOKEN" | helm registry login "$REPO_ADDRESS" --username "$REPO_LOGIN" --password-stdin echo "oci://$REPO_ADDRESS/helm/" -helm push "$APPLICATION-$appVersion.tgz" "oci://$REPO_ADDRESS/helm/" +helm push "$APPLICATION-$chartVersion.tgz" "oci://$REPO_ADDRESS/helm/"