1212 required : false
1313 default : " "
1414 type : string
15+ chart_name :
16+ description : The name of the Helm chart to update
17+ required : false
18+ default : " stack"
19+ type : string
1520
1621jobs :
1722 fetch-app-info :
@@ -113,13 +118,39 @@ jobs:
113118 if : steps.check_chart_path.outputs.chart_exists == 'true'
114119 - name : Install js-yaml in isolated directory
115120 if : steps.check_chart_path.outputs.chart_exists == 'true'
121+ # Install js-yaml in an isolated directory in case the repo already has a package installed that conflicts with js-yaml
116122 run : |
117123 mkdir -p /tmp/js-yaml-install
118124 cd /tmp/js-yaml-install
119125 npm install js-yaml --no-save
126+ - name : Find chart repository URL
127+ id : find_chart_url
128+ if : steps.check_chart_path.outputs.chart_exists == 'true'
129+ uses : actions/github-script@v7
130+ with :
131+ script : |
132+ const fs = require('fs');
133+ const yaml = require('/tmp/js-yaml-install/node_modules/js-yaml');
134+ const chartPath = '${{ steps.check_chart_path.outputs.chart_path }}';
135+ const chartName = '${{ inputs.chart_name }}';
136+
137+ // Read Chart.yaml and find the repository URL for the specified chart
138+ const chartContent = fs.readFileSync(chartPath, 'utf8');
139+ const chartYaml = yaml.load(chartContent);
140+
141+ const dependency = chartYaml.dependencies?.find(dep => dep.name === chartName);
142+
143+ if (dependency && dependency.repository) {
144+ core.setOutput('chart_repository', dependency.repository);
145+ core.setOutput('repository_found', 'true');
146+ core.info(`Found repository for ${chartName}: ${dependency.repository}`);
147+ } else {
148+ core.warning(`Could not find repository URL for chart: ${chartName}`);
149+ core.setOutput('repository_found', 'false');
150+ }
120151 - name : Write updatecli manifest
121152 id : write_manifest
122- if : steps.check_chart_path.outputs.chart_exists == 'true'
153+ if : steps.check_chart_path.outputs.chart_exists == 'true' && steps.find_chart_url.outputs.repository_found == 'true'
123154 uses : actions/github-script@v7
124155 with :
125156 script : |
@@ -128,29 +159,31 @@ jobs:
128159 const appName = '${{ matrix.app_name }}';
129160 const envName = '${{ matrix.env_name }}';
130161 const chartPath = '${{ steps.check_chart_path.outputs.chart_path }}';
162+ const chartName = '${{ inputs.chart_name }}';
163+ const chartRepository = '${{ steps.find_chart_url.outputs.chart_repository }}';
131164
132165 const fileName = 'updatecli-' + appName + '-' + envName + '.yaml';
133166 core.setOutput('UPDATECLI_MANIFEST_FILE', fileName);
134167
135168 const manifest = {
136169 name: 'Helm chart update',
137170 sources: {
138- stackHelmChart : {
139- name: `Get the latest 'stack ' Helm chart version`,
171+ helmChart : {
172+ name: `Get the latest '${chartName} ' Helm chart version`,
140173 kind: 'helmchart',
141174 spec: {
142- url: 'https://chanzuckerberg.github.io/argo-helm-charts' ,
143- name: 'stack'
175+ url: chartRepository ,
176+ name: chartName
144177 }
145178 }
146179 },
147180 targets: {
148181 helmChartVersions: {
149- name: " Bump 'stack ' Helm chart versions" ,
182+ name: ` Bump '${chartName} ' Helm chart versions` ,
150183 kind: 'yaml',
151184 spec: {
152185 engine: 'yamlpath',
153- key: ' $.dependencies[?(@.name == \'stack\ ')].version' ,
186+ key: ` $.dependencies[?(@.name == '${chartName} ')].version` ,
154187 file: chartPath
155188 }
156189 }
@@ -162,7 +195,7 @@ jobs:
162195
163196 - name : Run updatecli
164197 id : run_updatecli
165- if : steps.check_chart_path.outputs.chart_exists == 'true'
198+ if : steps.check_chart_path.outputs.chart_exists == 'true' && steps.find_chart_url.outputs.repository_found == 'true'
166199 run : |
167200 export UPDATE_LOG_FILE=$(uuidgen)-update.log
168201 echo "Running updatecli with manifest ${{ steps.write_manifest.outputs.UPDATECLI_MANIFEST_FILE }}"
@@ -186,15 +219,15 @@ jobs:
186219
187220 - name : Create Pull Request
188221 id : create_pr
189- if : steps.check_chart_path.outputs.chart_exists == 'true'
222+ if : steps.check_chart_path.outputs.chart_exists == 'true' && steps.find_chart_url.outputs.repository_found == 'true'
190223 uses : peter-evans/create-pull-request@v7
191224 with :
192225 add-paths : |
193226 ${{ steps.check_chart_path.outputs.chart_path }}
194- commit-message : update stack helm chart version
195- title : ' chore: update stack helm chart version for ${{ matrix.app_name }} ${{ matrix.env_name }}'
227+ commit-message : update '${{ inputs.chart_name }}' helm chart version
228+ title : " chore: update '${{ inputs.chart_name }}' helm chart version for ${{ matrix.app_name }} ${{ matrix.env_name }}"
196229 body : " ```${{ steps.run_updatecli.outputs.update_logs }}\n ```"
197230 base : ${{ github.event.repository.default_branch }}
198- branch : updatecli-bump-stack -chart-${{ matrix.app_name }}-${{ matrix.env_name }}
231+ branch : updatecli-bump-${{ inputs.chart_name }} -chart-${{ matrix.app_name }}-${{ matrix.env_name }}
199232 delete-branch : true
200233 token : ${{ steps.generate_token.outputs.token }}
0 commit comments