Skip to content

Commit 18aa28d

Browse files
committed
ci: clean up cd actions
1 parent a3ef0f0 commit 18aa28d

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

.github/actions/create-pr/action.yml

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,44 @@ inputs:
2626
runs:
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+
}

.github/workflows/cd.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,30 @@ jobs:
4242

4343
sync-repo:
4444
needs: setup
45+
name: ${{ matrix.sdk_name }}
4546
runs-on: ubuntu-latest
47+
permissions:
48+
contents: write
49+
pull-requests: write
4650
strategy:
4751
matrix:
4852
include:
4953
- repo: onesignal-ngx
54+
sdk_name: angular
5055
dist_path: dist/onesignal-ngx.tgz
5156
clone_path: __clone/onesignal-ngx
52-
has_submodules: false
5357
- repo: react-onesignal
58+
sdk_name: react
5459
dist_path: dist/react.tgz
5560
clone_path: __clone/react
56-
has_submodules: true
5761
- repo: onesignal-vue
62+
sdk_name: vue2
5863
dist_path: dist/vue/v2.tgz
5964
clone_path: __clone/vue/v2
60-
has_submodules: false
6165
- repo: onesignal-vue3
66+
sdk_name: vue3
6267
dist_path: dist/vue/v3.tgz
6368
clone_path: __clone/vue/v3
64-
has_submodules: false
6569
steps:
6670
- name: '[Setup] Checkout Repository'
6771
uses: actions/checkout@v6
@@ -83,7 +87,6 @@ jobs:
8387
token: ${{ secrets.GH_PUSH_TOKEN }}
8488
repository: OneSignal/${{ matrix.repo }}
8589
fetch-depth: 0
86-
submodules: ${{ matrix.has_submodules }}
8790
path: ${{ matrix.clone_path }}
8891

8992
- name: '[${{ matrix.repo }}] Patch'

0 commit comments

Comments
 (0)