@@ -43,10 +43,14 @@ jobs:
4343 outputs :
4444 # Value for the defaulted root-sbd if not provided
4545 root-sbd : ${{ steps.defaults.outputs.root-sbd }}
46+ # Caller PR branch ref
47+ pr-branch : ${{ steps.pr.outputs.ref }}
4648 # The profile to use from the MDRs config/auto-configs-pr.json
4749 profile : ${{ steps.parse.outputs.profile }}
48- # The configs to update from the MDRs config/auto-configs-pr.json
50+ # The configs to update from the MDRs config/auto-configs-pr.json, in a GitHub Actions matrix-parseable JSON array
4951 configs : ${{ steps.read-config.outputs.configs }}
52+ # The configs to update, in a space-separated string
53+ configs-formatted : ${{ steps.read-config.outputs.configs-formatted }}
5054 # The repository containing the configs to update
5155 configs-repo : ${{ steps.read-config.outputs.configs-repo }}
5256 steps :
@@ -111,6 +115,7 @@ jobs:
111115
112116 - name : Get caller repository ref
113117 id : pr
118+ # We need to find the PR ref of the caller repository explicitly, as this workflow trigger (issue_comment) is in the context of the default branch
114119 run : echo "ref=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefName --jq .headRefName)" >> $GITHUB_OUTPUT
115120
116121 - name : Checkout caller repository
@@ -134,13 +139,16 @@ jobs:
134139 exit 1
135140 fi
136141
137- configs=$(jq -cr '.profiles."${{ steps.parse.outputs.profile }}".configs | keys | join(" ")' caller/config/auto-configs-pr.json)
142+ configs=$(jq -cr '.profiles."${{ steps.parse.outputs.profile }}".configs | keys' caller/config/auto-configs-pr.json)
143+ configs_formatted=$(jq -cr '.profiles."${{ steps.parse.outputs.profile }}".configs | keys | join(" ")' caller/config/auto-configs-pr.json)
138144 configs_repo=$(jq -cr '.profiles."${{ steps.parse.outputs.profile }}".configs_repo' caller/config/auto-configs-pr.json)
139145
140146 echo "$configs"
147+ echo "$configs_formatted"
141148 echo "$configs_repo"
142149
143150 echo "configs=$configs" >> $GITHUB_OUTPUT
151+ echo "configs-formatted=$configs_formatted" >> $GITHUB_OUTPUT
144152 echo "configs-repo=$configs_repo" >> $GITHUB_OUTPUT
145153
146154 update-configs :
@@ -149,10 +157,26 @@ jobs:
149157 runs-on : ubuntu-latest
150158 needs :
151159 - setup
160+ strategy :
161+ fail-fast : false
162+ matrix :
163+ config : ${{ fromJson(needs.setup.outputs.configs) }}
164+ env :
165+ GH_TOKEN : ${{ secrets.configs-repo-token }}
166+ CONFIG : ${{ matrix.config }}
167+ PR_URL_ARTIFACT_GLOB : pr-urls-*
168+ PR_URL_ARTIFACT_NAME : pr-urls-${{ matrix.config }}
152169 outputs :
153- # List of URLs of the opened PRs, space-separated
154- pr-urls : ${{ steps.open-prs.outputs.pr-urls }}
170+ pr-url-artifact-glob : ${{ env.PR_URL_ARTIFACT_GLOB }}
171+ # Within which contains the URL of the opened PR
172+ # pr-url: ${{ steps.open-pr.outputs.pr-url }}
155173 steps :
174+ - name : Checkout caller repository
175+ uses : actions/checkout@v4
176+ with :
177+ path : caller
178+ ref : ${{ needs.setup.outputs.pr-branch }}
179+
156180 - name : Checkout caller configs repository
157181 uses : actions/checkout@v4
158182 with :
@@ -196,110 +220,108 @@ jobs:
196220 pr : ${{ github.event.issue.number }}
197221 token : ${{ github.token }}
198222
199- - name : Open PRs
200- id : open-prs
223+ - name : Open PR
224+ id : open-pr
201225 env :
202- GH_TOKEN : ${{ secrets.configs-repo-token }}
203226 DEPLOYMENT_IDENTIFIER : ${{ needs.setup.outputs.root-sbd }}/pr${{ github.event.issue.number }}-${{ steps.previous-deployments.outputs.deployments }}
204227 run : |
205- set +e
206-
207- error=false
208- pr_urls=""
209-
210- for config in ${{ needs.setup.outputs.configs }}; do
211- pr_branch_name="auto/pr${{ github.event.issue.number }}-${{ steps.previous-deployments.outputs.deployments }}/${config}"
212-
213- echo "Creating PR branch $pr_branch_name from $config..."
214- git -C caller-configs checkout $config
215-
216- if git -C caller-configs ls-remote --exit-code --heads origin $pr_branch_name; then
217- # TODO: Feature: Append to the existing PR instead of continuing
218- echo "::error::Branch $pr_branch_name already exists for $config, so a gh PR can't be created from it"
219- error=true
220- continue
221- fi
222-
223- git -C caller-configs checkout -b $pr_branch_name
224-
225- if [ ! -f caller-configs/config.yaml ]; then
226- echo "::error::File config.yaml not found in ${{ needs.setup.outputs.configs-repo }} on branch $config, cannot automatically open configs PRs"
227- error=true
228- continue
229- fi
230-
231- echo "Updating config.yaml in $pr_branch_name to use ${{ env.DEPLOYMENT_IDENTIFIER }}..."
232-
233- # FIXME: This is Gadi-specific
234- # --manifest is still relative to the current working directory, unaffected by the custom PYTHONPATH
235- PYTHONPATH=build-cd python3 -m scripts.model_config_manifest.prerelease_update \
236- --manifest caller-configs/config.yaml \
237- --deployment-target Gadi \
238- --root-sbd ${{ needs.setup.outputs.root-sbd }} \
239- --module ${{ env.DEPLOYMENT_IDENTIFIER }}
240-
241- if [ $? -ne 0 ]; then
242- echo "::error::Failed to update config.yaml in $pr_branch_name to use ${{ env.DEPLOYMENT_IDENTIFIER }}"
243- error=true
244- continue
245- fi
246-
247- echo "Committing and pushing changes..."
248- git -C caller-configs diff
249- git -C caller-configs commit -am "Auto update to use ${{ env.DEPLOYMENT_IDENTIFIER }} as part of ${{ env.RUN_URL }}"
250- git -C caller-configs push --set-upstream origin $pr_branch_name
251-
252- echo "Opening PR for branch $pr_branch_name in repo ${{ needs.setup.outputs.configs-repo }}..."
253- pr_url=$(gh pr create \
254- --draft \
255- --repo "${{ needs.setup.outputs.configs-repo }}" \
256- --title "Auto update $config to use ${{ env.DEPLOYMENT_IDENTIFIER }}" \
257- --body "Auto-generated PR to update $config to use ${{ env.DEPLOYMENT_IDENTIFIER }} from ${{ github.repository }}#${{ github.event.issue.number }}, see ${{ env.RUN_URL }}" \
258- --head "$pr_branch_name" \
259- --base "$config"
260- )
261- if [ $? -ne 0 ]; then
262- echo "::error::Failed to open PR for branch $pr_branch_name in repo ${{ needs.setup.outputs.configs-repo }}"
263- error=true
264- continue
265- fi
266- echo "::notice::Opened PR: $pr_url"
267- pr_urls+="$pr_url "
268-
269- require_repro_check=$(jq -cr \
270- --arg config "$config" \
271- '.profiles."${{ needs.setup.outputs.profile }}".configs.[$config].checks.repro' \
272- caller/config/auto-configs-pr.json
273- )
274- if [[ "$require_repro_check" == "true" ]]; then
275- echo "::notice::The updated $config configuration requested a repro check, commenting !test repro on $pr_url"
276- gh pr comment $pr_url --repo "${{ needs.setup.outputs.configs-repo }}" --body '!test repro'
277- fi
278- done
228+ pr_branch_name="auto/pr${{ github.event.issue.number }}-${{ steps.previous-deployments.outputs.deployments }}/${{ env.CONFIG }}"
229+
230+ echo "Creating PR branch $pr_branch_name from ${{ env.CONFIG }}..."
231+ git -C caller-configs checkout ${{ env.CONFIG }}
279232
280- echo "pr-urls=$pr_urls" >> $GITHUB_OUTPUT
233+ if git -C caller-configs ls-remote --exit-code --heads origin $pr_branch_name; then
234+ # TODO: Feature: Append to the existing PR instead of continuing
235+ echo "::error::Branch $pr_branch_name already exists for ${{ env.CONFIG }}, so a gh PR can't be created from it"
236+ exit 1
237+ fi
281238
282- set -e
239+ git -C caller-configs checkout -b $pr_branch_name
283240
284- if [[ "$error" == "true" ] ]; then
285- echo "::error::One or more errors occurred, see above "
241+ if [ ! -f caller-configs/config.yaml ]; then
242+ echo "::error::File config.yaml not found in ${{ needs.setup.outputs.configs-repo }} on branch ${{ env.CONFIG }}, cannot automatically open configs PRs "
286243 exit 1
287244 fi
288245
246+ echo "Updating config.yaml in $pr_branch_name to use ${{ env.DEPLOYMENT_IDENTIFIER }}..."
247+
248+ # FIXME: This is Gadi-specific
249+ # --manifest is still relative to the current working directory, unaffected by the custom PYTHONPATH
250+ PYTHONPATH=build-cd python3 -m scripts.model_config_manifest.prerelease_update \
251+ --manifest caller-configs/config.yaml \
252+ --deployment-target Gadi \
253+ --root-sbd ${{ needs.setup.outputs.root-sbd }} \
254+ --module ${{ env.DEPLOYMENT_IDENTIFIER }}
255+
256+ echo "Committing and pushing changes..."
257+ git -C caller-configs diff
258+ git -C caller-configs commit -am "Auto update to use ${{ env.DEPLOYMENT_IDENTIFIER }} as part of ${{ env.RUN_URL }}"
259+ git -C caller-configs push --set-upstream origin $pr_branch_name
260+
261+ echo "Opening PR for branch $pr_branch_name in repo ${{ needs.setup.outputs.configs-repo }}..."
262+ pr_url=$(gh pr create \
263+ --draft \
264+ --repo "${{ needs.setup.outputs.configs-repo }}" \
265+ --title "Auto update ${{ env.CONFIG }} to use ${{ env.DEPLOYMENT_IDENTIFIER }}" \
266+ --body "Auto-generated PR to update ${{ env.CONFIG }} to use ${{ env.DEPLOYMENT_IDENTIFIER }} from ${{ github.repository }}#${{ github.event.issue.number }}, see ${{ env.RUN_URL }}" \
267+ --head "$pr_branch_name" \
268+ --base "${{ env.CONFIG }}"
269+ )
270+
271+ echo "::notice::Opened PR: $pr_url"
272+ echo "pr_url=$pr_url" >> $GITHUB_OUTPUT
273+
274+ - name : Determine if repro check required
275+ id : repro-check
276+ run : |
277+ require_repro_check=$(jq --compact-output --raw-output \
278+ --arg config "${{ env.CONFIG }}" \
279+ '.profiles."${{ needs.setup.outputs.profile }}".configs.["${{ env.CONFIG }}"].checks.repro' \
280+ caller/config/auto-configs-pr.json
281+ )
282+ echo "Repro check required: $require_repro_check"
283+ echo "required=$require_repro_check" >> $GITHUB_OUTPUT
284+
285+ - name : Repro check
286+ if : steps.repro-check.outputs.required == 'true'
287+ run : |
288+ echo "::notice::The updated ${{ env.CONFIG }} configuration requested a repro check, commenting !test repro on ${{ steps.open-pr.outputs.pr_url }}"
289+ gh pr comment ${{ steps.open-pr.outputs.pr_url }} --repo "${{ needs.setup.outputs.configs-repo }}" --body '!test repro'
290+
291+ - name : Set PR URL Artifact
292+ run : |
293+ jq --null-input --arg pr_url "${{ steps.open-pr.outputs.pr_url }}" '{pr_url: $pr_url}' > ./${{ env.PR_URL_ARTIFACT_NAME }}
294+
295+ - name : Upload PR URL Artifact
296+ uses : actions/upload-artifact@v6
297+ with :
298+ name : ${{ env.PR_URL_ARTIFACT_NAME }}
299+ path : ./${{ env.PR_URL_ARTIFACT_NAME }}
300+ if-no-files-found : error
301+
289302 result :
290303 name : Result
291304 if : always()
292305 needs :
293306 - setup
294307 - update-configs
295308 runs-on : ubuntu-latest
309+ env :
310+ ARTIFACT_PATH : ./pr-urls
296311 steps :
297312 - name : Checkout build-cd
298313 uses : actions/checkout@v4
299314 with :
300315 repository : access-nri/build-cd
301316 path : build-cd
302317
318+ - name : Download PR URL Artifacts
319+ uses : actions/download-artifact@v6
320+ with :
321+ pattern : ${{ needs.update-configs.outputs.pr-url-artifact-glob }}
322+ merge-multiple : true
323+ path : ${{ env.ARTIFACT_PATH }}
324+
303325 - name : Setup python
304326 uses : actions/setup-python@v5
305327 with :
@@ -312,13 +334,24 @@ jobs:
312334 - name : Comment on caller PR
313335 env :
314336 GH_TOKEN : ${{ github.token }}
337+ # Get all the PR URLs from the matrix jobs and combine them into a single space-separated string
338+ # Then pass it to jinja to comment templating
315339 run : |
340+ if [ -d "${{ env.ARTIFACT_PATH }}" ]; then
341+ pr_urls=$(jq --slurp --raw-output \
342+ '[.[] | .pr_url] | join(" ")' \
343+ ${{ env.ARTIFACT_PATH }}/${{ needs.update-configs.outputs.pr-url-artifact-glob }}
344+ )
345+ fi
346+
347+ echo "PR URLs passed to template: $pr_urls"
348+
316349 jinja \
317350 --define model_configs_repo "${{ needs.setup.outputs.configs-repo }}" \
318351 --define run_url "${{ env.RUN_URL }}" \
319- --define pr_urls "${{ needs.update-configs.outputs.pr-urls }} " \
352+ --define pr_urls "$pr_urls " \
320353 --define profile "${{ needs.setup.outputs.profile }}" \
321- --define configs "${{ needs.setup.outputs.configs }}" \
354+ --define configs "${{ needs.setup.outputs.configs-formatted }}" \
322355 --define error "${{ contains(needs.*.result, 'failure') }}" \
323356 build-cd/scripts/jinja_template/templates/auto-prs-comment-body.md.j2 \
324357 > templated.auto-prs-comment-body.md
0 commit comments