1- name : Build and Publish Helm Chart
2-
3- permissions :
4- contents : read
1+ name : Release Helm Chart
52
63on :
7- release :
8- types :
9- - published
104 push :
115 branches :
12- - main
6+ - main
137 tags :
14- - v*.*.*
8+ - ' v*.*.*'
159 pull_request :
1610 branches :
17- - main
18- paths-ignore :
19- - ' docs/**'
20- - ' **/*.md'
21- types : [labeled, unlabeled, opened, synchronize, reopened]
11+ - main
2212
2313jobs :
24- publish-charts :
14+ helm-chart :
2515 runs-on : ubuntu-latest
26- if : github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'ok-to-chart')
16+ permissions :
17+ contents : read
18+ packages : write
19+
2720 steps :
28- - name : Check out repository
29- uses : actions/checkout@v4
30- - name : Set up Helm
31- uses : azure/setup-helm@v4.3.0
32- with :
33- version : v3.16.2
34- - name : Configure Git
35- run : |
36- git config user.name "$GITHUB_ACTOR"
37- git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
38- - name : Set charts version
39- if : github.event_name == 'push'
40- run : |
41- sed -i "s/version: .*/version: ${GITHUB_REF_NAME#v}/" dist/chart/Chart.yaml
42- - name : Move crds folder out of templates
43- run : mv dist/chart/templates/crd dist/chart/crds
44- - name : Run chart-releaser
45- uses : bitdeps/helm-oci-charts-releaser@v0.1.4
46- with :
47- charts_dir : dist/chart
48- oci_registry : ghcr.io/${{ github.repository_owner }}/charts
49- github_token : ${{ secrets.GITHUB_TOKEN }}
50- oci_password : ${{ secrets.GITHUB_TOKEN }}
51- oci_username : ${{ github.actor }}
52- skip_gh_release : true
21+ - name : Checkout code
22+ uses : actions/checkout@v4
23+
24+ - name : Set up Helm
25+ uses : azure/setup-helm@v4
26+ with :
27+ version : v3.16.2
28+
29+ - name : Determine chart version
30+ id : chart_version
31+ run : |
32+ if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
33+ # Use SHA for main branch
34+ CHART_VERSION="0.0.0-$(echo ${{ github.sha }} | cut -c1-7)"
35+ elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
36+ # Use tag version (strip 'v' prefix)
37+ CHART_VERSION="${GITHUB_REF#refs/tags/v}"
38+ else
39+ # Use PR SHA for dry run
40+ CHART_VERSION="0.0.0-$(echo ${{ github.sha }} | cut -c1-7)"
41+ fi
42+ echo "version=$CHART_VERSION" >> $GITHUB_OUTPUT
43+
44+ - name : Package Helm chart
45+ run : |
46+ helm package dist/chart --version ${{ steps.chart_version.outputs.version }}
47+
48+ - name : Log in to GitHub Container Registry
49+ run : |
50+ echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
51+
52+ - name : Push Helm chart to GHCR
53+ run : |
54+ helm push metal-operator-${{ steps.chart_version.outputs.version }}.tgz oci://ghcr.io/${{ github.repository_owner }}/charts
0 commit comments