@@ -26,18 +26,44 @@ inputs:
2626runs :
2727 using : ' composite'
2828 steps :
29- - name : Create Pull Request
29+ - name : Create or Update Pull Request
3030 uses : actions/github-script@v7
3131 continue-on-error : true
3232 with :
33+ github-token : ${{ inputs.github_token }}
3334 script : |
34- await github.rest.pulls.create({
35+ const title = 'ci: sync with web-shim-codegen v' + '${{ inputs.package_version }}';
36+ const body = 'This update was generated by the GitHub CD action.';
37+
38+ // Check if a PR already exists for this branch
39+ const existingPRs = await github.rest.pulls.list({
3540 owner: '${{ inputs.owner }}',
3641 repo: '${{ inputs.repo }}',
37- title: 'ci: sync with web-shim-codegen v' + '${{ inputs.package_version }}',
38- body: 'This update was generated by the GitHub CD action.',
42+ head: '${{ inputs.owner }}:${{ inputs.head }}',
3943 base: '${{ inputs.base }}',
40- head : '${{ inputs.head }} '
44+ state : 'open '
4145 });
42- env :
43- GITHUB_TOKEN : ${{ inputs.github_token }}
46+
47+ if (existingPRs.data.length > 0) {
48+ // Update existing PR
49+ const pr = existingPRs.data[0];
50+ await github.rest.pulls.update({
51+ owner: '${{ inputs.owner }}',
52+ repo: '${{ inputs.repo }}',
53+ pull_number: pr.number,
54+ title: title,
55+ body: body
56+ });
57+ console.log(`Updated existing PR #${pr.number}`);
58+ } else {
59+ // Create new PR
60+ const pr = await github.rest.pulls.create({
61+ owner: '${{ inputs.owner }}',
62+ repo: '${{ inputs.repo }}',
63+ title: title,
64+ body: body,
65+ base: '${{ inputs.base }}',
66+ head: '${{ inputs.head }}'
67+ });
68+ console.log(`Created new PR #${pr.data.number}`);
69+ }
0 commit comments