diff --git a/.github/actions/check-helm-chart-version/action.yml b/.github/actions/check-helm-chart-version/action.yml new file mode 100644 index 00000000..1087d344 --- /dev/null +++ b/.github/actions/check-helm-chart-version/action.yml @@ -0,0 +1,57 @@ +name: check-helm-chart-version +description: Check helm chart version and appVersion in Chart.yaml with package.json version +author: datavisyn + +inputs: + package_file: + description: "Path to the package.json file" + default: "./package.json" + required: false + chart_directory: + description: "Helm chart directory where to find the Chart.yaml file" + required: true +runs: + using: "composite" + steps: + - name: Check helm chart version + run: | + export CHART_YAML=$CHART_DIRECTORY/Chart.yaml + export CHART_VERSION=$(yq '.version' < $CHART_YAML) + export CHART_APP_VERSION=$(yq '.appVersion' < $CHART_YAML) + export CHART_IMAGE_TAG=$(yq '.imageTag' < $CHART_DIRECTORY/values.yaml) + export PACKAGE_VERSION=$(jq -r '.version' $PACKAGE_FILE) + export SHOULD_EXIT=0 + + if [[ $CHART_VERSION != $PACKAGE_VERSION ]]; then + echo "Chart version is not equal to package version." + echo "Chart version: $CHART_VERSION" + echo "Package version: $PACKAGE_VERSION" + echo "---" + export SHOULD_EXIT=1 + fi + + if [[ $CHART_APP_VERSION != $PACKAGE_VERSION ]]; then + echo "Chart appVersion is not equal to package version." + echo "Chart appVersion: $CHART_APP_VERSION" + echo "Package version: $PACKAGE_VERSION" + echo "---" + export SHOULD_EXIT=1 + fi + + if [[ $CHART_IMAGE_TAG != v$PACKAGE_VERSION ]]; then + echo "Chart imageTag is not equal to package version." + echo "Chart imageTag: $CHART_IMAGE_TAG" + echo "Package version: v$PACKAGE_VERSION" + echo "---" + export SHOULD_EXIT=1 + fi + + if [[ $SHOULD_EXIT == 1 ]]; then + echo "Version mismatch. Please update the version in Chart.yaml and values.yaml to match the version in package.json." + echo "Exiting..." + exit 1 + fi + shell: bash + env: + PACKAGE_FILE: ${{ inputs.package_file }} + CHART_DIRECTORY: ${{ inputs.chart_directory }} diff --git a/.github/workflows/check-helm-chart-version.yml b/.github/workflows/check-helm-chart-version.yml new file mode 100644 index 00000000..29e78db2 --- /dev/null +++ b/.github/workflows/check-helm-chart-version.yml @@ -0,0 +1,36 @@ +name: check-helm-chart-version + +on: + workflow_dispatch: + inputs: + package_file: + description: "Path to the package.json file" + default: "./package.json" + required: false + chart_directory: + description: "Helm chart directory where to find the Chart.yaml file" + required: true + +permissions: + id-token: write + contents: read + +env: + WORKFLOW_BRANCH: "new_deployment_build-push-helm-chart" + +jobs: + check-helm-chart-version: + runs-on: ubuntu-20.04 + steps: + # checkout specific source repository + - uses: actions/checkout@v3 + # checkout this workflow repository to get actions + - uses: actions/checkout@v3 + with: + repository: datavisyn/github-workflows + ref: ${{ env.WORKFLOW_BRANCH }} + path: ./tmp/github-workflows + - uses: ./tmp/github-workflows/.github/actions/check-helm-chart-version + with: + package_file: ${{ inputs.package_file }} + current_directory: ${{ inputs.chart_directory }}