1+ name : Helm Package, Push & (Conditional) Release
2+
3+ on :
4+ push :
5+ tags :
6+ - " *"
7+ workflow_dispatch :
8+ inputs :
9+ tag :
10+ description : " The tag to use for packaging (must be provided when triggered manually)."
11+ required : true
12+
13+ permissions :
14+ contents : write # Required for creating GitHub releases
15+
16+ jobs :
17+ package-push-release :
18+ runs-on : ubuntu-latest
19+ steps :
20+ - name : Checkout Repository
21+ uses : actions/checkout@v3
22+
23+ - name : Install Helm (Official)
24+ run : |
25+ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
26+ chmod 700 get_helm.sh
27+ ./get_helm.sh
28+
29+ - name : Determine Versions
30+ id : versions
31+ run : |
32+ # Extract chart name and version from Chart.yaml in the repository root.
33+ CHART_VERSION=$(awk -F": " '/^version:/{print $2}' Chart.yaml | tr -d '[:space:]')
34+ CHART_NAME=$(awk -F": " '/^name:/{print $2}' Chart.yaml | tr -d '[:space:]')
35+ echo "CHART_VERSION=$CHART_VERSION" >> $GITHUB_ENV
36+ echo "CHART_NAME=$CHART_NAME" >> $GITHUB_ENV
37+
38+ # Use the tag from the trigger—manual input (workflow_dispatch) or push event.
39+ if [ -n "${{ github.event.inputs.tag }}" ]; then
40+ EFFECTIVE_VERSION="${{ github.event.inputs.tag }}"
41+ else
42+ EFFECTIVE_VERSION="${GITHUB_REF##*/}"
43+ fi
44+ echo "EFFECTIVE_VERSION=$EFFECTIVE_VERSION" >> $GITHUB_ENV
45+
46+ echo "Chart.yaml version: $CHART_VERSION"
47+ echo "Effective version (tag): $EFFECTIVE_VERSION"
48+
49+ # The following step is necessary even dependencies are not used.
50+ - name : Update Chart Dependencies
51+ run : helm dependency update .
52+
53+ - name : Package Helm Chart
54+ run : |
55+ echo "Packaging chart with version $EFFECTIVE_VERSION"
56+ helm package . --version "$EFFECTIVE_VERSION"
57+
58+ - name : List Packaged Files
59+ run : ls -l *.tgz
60+
61+ - name : Add Helm Repository
62+ run : helm repo add eccr-polytope https://eccr.ecmwf.int/chartrepo/polytope --username '${{ secrets.ECMWF_DOCKER_REGISTRY_USERNAME }}' --password '${{ secrets.ECMWF_DOCKER_REGISTRY_ACCESS_TOKEN }}'
63+
64+ - name : Install cm-push Plugin
65+ run : helm plugin install https://github.com/chartmuseum/helm-push
66+
67+ - name : Push Packaged Chart
68+ run : |
69+ PACKAGE_FILE="${{ env.CHART_NAME }}-${{ env.EFFECTIVE_VERSION }}.tgz"
70+ echo "Pushing package file: $PACKAGE_FILE"
71+ helm cm-push "$PACKAGE_FILE" eccr-polytope
72+
73+ - name : Create GitHub Release if Tag Equals Chart Version
74+ if : ${{ env.EFFECTIVE_VERSION == env.CHART_VERSION }}
75+ uses : softprops/action-gh-release@v2
76+ with :
77+ tag_name : ${{ env.EFFECTIVE_VERSION }}
78+ name : " ${{ env.CHART_NAME }} v${{ env.EFFECTIVE_VERSION }}"
79+ generate_release_notes : true
80+ env :
81+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments