3030 github_app_pem :
3131 description : GitHub APP pem to authenticate with
3232 required : false
33+ vault_repo_secret_name :
34+ description : Vault secret name that holds repository's GitHub App credentials to authenticate with
35+ required : false
3336 helm_repo_token :
3437 description : GitHub api token to use against the helm-charts repository
3538 required : false
4144 CR_PACKAGE_PATH : " ${{ github.workspace }}/.cr-release-packages"
4245 CR_TOOL_PATH : " ${{ github.workspace }}/.cr-tool"
4346 HELM_TAG_PREFIX : " ${{ inputs.helm_tag_prefix }}"
47+ REF_NAME : " ${{ github.ref_name }}"
4448
4549jobs :
4650 setup :
5458 with :
5559 fetch-depth : 0
5660 path : source
61+ persist-credentials : false
5762
5863 - name : Set up chart-testing
59- uses : helm/chart-testing-action@v2.1 .0
64+ uses : helm/chart-testing-action@0d28d3144d3a25ea2cc349d6e59901c4ff469b3b # v2.7 .0
6065
6166 - name : List changed charts
6267 id : list-changed
6570
6671 latest_tag=$( if ! git describe --tags --abbrev=0 2> /dev/null ; then git rev-list --max-parents=0 --first-parent HEAD ; fi )
6772
68- echo "Running: ct list-changed --config ${CT_CONFIGFILE} --since ${latest_tag} --target-branch ${{ github.ref_name } }"
69- changed=$(ct list-changed --config "${CT_CONFIGFILE}" --since "${latest_tag}" --target-branch "${{ github.ref_name } }")
73+ echo "Running: ct list-changed --config ${CT_CONFIGFILE} --since ${latest_tag} --target-branch ${REF_NAME }"
74+ changed=$(ct list-changed --config "${CT_CONFIGFILE}" --since "${latest_tag}" --target-branch "${REF_NAME }")
7075 echo "${changed}"
7176 num_changed=$(wc -l <<< ${changed})
7277 if [[ "${num_changed}" -gt "1" ]] ; then
@@ -94,30 +99,48 @@ jobs:
9499 needs : [setup]
95100 runs-on : ubuntu-latest
96101 permissions :
102+ id-token : write # allows GitHub App to generate id-token from Github's OIDC
97103 contents : write # allows GITHUB_TOKEN to push chart release, create release, and push tags to github
98104 packages : write # allows GITHUB_TOKEN to push package to ghcr
99105 env :
100- github_app_id : ${{ secrets.github_app_id }}
106+ # APP_ID and PRIVATE_KEY are overwritten by credentials from vault, if configured
107+ GITHUB_APP_ID : ${{ secrets.github_app_id }}
108+ PRIVATE_KEY : ${{ secrets.github_app_pem }}
109+ VAULT_REPO_SECRET_NAME : ${{ secrets.vault_repo_secret_name }}
101110 if : needs.setup.outputs.changed == 'true'
102111 steps :
103- - name : Create a GitHub App installation access token
104- if : env.github_app_id != ''
105- uses : tibdex/github-app-token@v2
112+ - name : Retrieve GitHub App credentials from Vault
113+ if : env.VAULT_REPO_SECRET_NAME != ''
114+ id : get-secrets
115+ uses : grafana/shared-workflows/actions/get-vault-secrets@28361cdb22223e5f1e34358c86c20908e7248760 # v1.1.0
116+ with :
117+ repo_secrets : |
118+ GITHUB_APP_ID=${{ env.VAULT_REPO_SECRET_NAME }}:app-id
119+ PRIVATE_KEY=${{ env.VAULT_REPO_SECRET_NAME }}:private-key
120+
121+ - name : Generate GitHub App Token
122+ if : env.GITHUB_APP_ID != ''
106123 id : app-token
124+ uses : actions/create-github-app-token@v1
107125 with :
108- app_id : ${{ secrets.github_app_id }}
109- private_key : ${{ secrets.github_app_pem }}
126+ # Variables generated by the previous step get-secrets
127+ app-id : ${{ env.GITHUB_APP_ID }}
128+ private-key : ${{ env.PRIVATE_KEY }}
129+ owner : ${{ github.repository_owner }}
110130
111131 - name : Set the correct token (Github App or PAT)
132+ env :
133+ HELM_REPO_TOKEN : ${{ secrets.helm_repo_token }}
134+ APP_TOKEN : ${{ steps.app-token.outputs.token }}
112135 run : |
113- if [[ "${{ env.github_app_id } }" == '' ]]; then
114- echo "AUTHTOKEN=${{ secrets.helm_repo_token } }" >> $GITHUB_ENV
136+ if [[ "${GITHUB_APP_ID }" == '' ]]; then
137+ echo "AUTHTOKEN=${HELM_REPO_TOKEN }" >> $GITHUB_ENV
115138 else
116- echo "AUTHTOKEN=${{ steps.app-token.outputs.token } }" >> $GITHUB_ENV
139+ echo "AUTHTOKEN=${APP_TOKEN }" >> $GITHUB_ENV
117140 fi
118141
119142 - name : Checkout
120- uses : actions/checkout@v4
143+ uses : actions/checkout@v4 # zizmor: ignore[artipacked] without this ignore comment, zizmor would complain that persist-credentials is not explicitly set to false. We need it set to true (default) to be able to push the release tags later on in this workflow
121144 with :
122145 fetch-depth : 0
123146 path : source
@@ -130,12 +153,12 @@ jobs:
130153
131154 - name : Checkout helm-charts
132155 # The cr tool only works if the target repository is already checked out
133- uses : actions/checkout@v4
156+ uses : actions/checkout@v4 # zizmor: ignore[artipacked] without this ignore comment, zizmor would complain that persist-credentials is not explicitly set to false. We need it set to true (default) to be able to push the release tags later on in this workflow
134157 with :
135158 fetch-depth : 0
136159 repository : grafana/helm-charts
137160 path : helm-charts
138- token : ${{ env.AUTHTOKEN }}
161+ token : ${{ env.AUTHTOKEN }}
139162
140163 - name : Configure Git for helm-charts
141164 run : |
@@ -144,15 +167,17 @@ jobs:
144167 git config user.email "[email protected] " 145168
146169 - name : Install Helm
147- uses : azure/setup-helm@v4
170+ uses : azure/setup-helm@b9e51907a09c216f16ebe8536097933489208112 # v4.3.0
148171 with :
149172 version : v3.16.2
150173
151174 - name : Parse Chart.yaml
152175 id : parse-chart
176+ env :
177+ CHARTPATH : ${{ needs.setup.outputs.chartpath }}
153178 run : |
154179 cd source
155- changed="${{ needs.setup.outputs.chartpath } }"
180+ changed="${CHARTPATH }"
156181 description=$(yq ".description" < ${changed}/Chart.yaml)
157182 name=$(yq ".name" < ${changed}/Chart.yaml)
158183 version=$(yq ".version" < ${changed}/Chart.yaml)
@@ -166,10 +191,12 @@ jobs:
166191 echo "packagename=${name}-${version}" >> $GITHUB_OUTPUT
167192
168193 - name : Add dependency chart repos
194+ env :
195+ CHARTPATH : ${{ steps.parse-chart.outputs.chartpath }}
169196 run : |
170197 cd source
171198 # Skip the header line and make sure that tabs are expanded into spaces
172- deps=$(helm dependency list "${{ steps.parse-chart.outputs.chartpath } }" | tail +2 | expand)
199+ deps=$(helm dependency list "${CHARTPATH }" | tail +2 | expand)
173200 while read -r row; do
174201 IFS=' ' read -ra parts <<< "$row"
175202 name="${parts[0]}"
@@ -190,20 +217,24 @@ jobs:
190217 rm -f cr.tar.gz
191218
192219 - name : Create helm package
220+ env :
221+ CHARTPATH : ${{ steps.parse-chart.outputs.chartpath }}
193222 run : |
194223 cd source
195- "${CR_TOOL_PATH}/cr" package "${{ steps.parse-chart.outputs.chartpath } }" --config "${CR_CONFIGFILE}" --package-path "${CR_PACKAGE_PATH}"
224+ "${CR_TOOL_PATH}/cr" package "${CHARTPATH }" --config "${CR_CONFIGFILE}" --package-path "${CR_PACKAGE_PATH}"
196225 echo "Result of chart package:"
197226 ls -l "${CR_PACKAGE_PATH}"
198227
199228 - name : Create tag and check if exists on origin
229+ env :
230+ TAGNAME : ${{ steps.parse-chart.outputs.tagname }}
200231 run : |
201232 cd source
202- echo "Making tag ${{ steps.parse-chart.outputs.tagname } }"
203- git tag "${{ steps.parse-chart.outputs.tagname } }"
233+ echo "Making tag ${TAGNAME }"
234+ git tag "${TAGNAME }"
204235
205236 - name : Make github release
206- uses : softprops/action-gh-release@v1
237+ uses : softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # tags/ v1
207238 with :
208239 body : |
209240 ${{ steps.parse-chart.outputs.desc }}
@@ -219,18 +250,20 @@ jobs:
219250 token : ${{ env.AUTHTOKEN }}
220251
221252 - name : Push release tag on origin
253+ env :
254+ TAGNAME : ${{ steps.parse-chart.outputs.tagname }}
222255 run : |
223256 cd source
224- echo "Pushing tag ${{ steps.parse-chart.outputs.tagname } }"
225- git push origin "${{ steps.parse-chart.outputs.tagname } }"
257+ echo "Pushing tag ${TAGNAME }"
258+ git push origin "${TAGNAME }"
226259
227260 - name : Update helm repo index.yaml
228261 run : |
229262 cd helm-charts
230263 "${CR_TOOL_PATH}/cr" index --config "${CR_CONFIGFILE}" --token "${{ env.AUTHTOKEN }}" --index-path "${CR_INDEX_PATH}" --package-path "${CR_PACKAGE_PATH}" --push
231264
232265 - name : Login to GHCR
233- uses : docker/login-action@v3.0 .0
266+ uses : docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6 .0
234267 with :
235268 registry : ghcr.io
236269 username : ${{ github.actor }}
@@ -239,5 +272,7 @@ jobs:
239272 password : ${{ secrets.GITHUB_TOKEN }}
240273
241274 - name : Push charts to GHCR
275+ env :
276+ PACKAGENAME : ${{ steps.parse-chart.outputs.packagename }}
242277 run : |
243- helm push "${{ env. CR_PACKAGE_PATH }} /${{ steps.parse-chart.outputs.packagename } }.tgz" "oci://ghcr.io/${GITHUB_REPOSITORY_OWNER}/helm-charts"
278+ helm push "${CR_PACKAGE_PATH} /${PACKAGENAME }.tgz" "oci://ghcr.io/${GITHUB_REPOSITORY_OWNER}/helm-charts"
0 commit comments