Skip to content

Commit

Permalink
Ability to provide app version from action for helm install (#74)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
s-vitaliy authored May 30, 2024
1 parent de9bf39 commit cb7d2e3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions build_helm_chart/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
21 changes: 17 additions & 4 deletions build_helm_chart/build_chart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/"

0 comments on commit cb7d2e3

Please sign in to comment.