Skip to content

Commit 04b6a23

Browse files
committed
update cd workflow to generate github release on merge
1 parent f5146e6 commit 04b6a23

1 file changed

Lines changed: 56 additions & 6 deletions

File tree

.github/workflows/cd.yml

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,98 @@
11
name: Build SDK Files & GCS Upload
22

33
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- '**.md'
49
workflow_dispatch:
510

611
jobs:
12+
check_release:
13+
runs-on: ubuntu-22.04
14+
outputs:
15+
should_run: ${{ steps.check_release.outputs.should_run }}
16+
steps:
17+
- name: Check if release merge or workflow dispatch
18+
id: check_release
19+
uses: actions/github-script@v8
20+
with:
21+
script: |
22+
if (context.eventName !== 'push') {
23+
core.setOutput('should_run', 'true');
24+
return;
25+
}
26+
27+
const commit = context.payload.head_commit;
28+
const mergeMatch = commit.message.match(/Merge pull request #(\d+)/);
29+
30+
if (!mergeMatch) {
31+
core.setOutput('should_run', 'false');
32+
return;
33+
}
34+
35+
const { data: pr } = await github.rest.pulls.get({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
pull_number: parseInt(mergeMatch[1])
39+
});
40+
41+
core.setOutput('should_run', pr.title.startsWith('Release') ? 'true' : 'false');
42+
743
test_build_deploy:
844
runs-on: ubuntu-22.04
945

46+
needs: check_release
47+
if: needs.check_release.outputs.should_run == 'true'
48+
1049
steps:
1150
- uses: actions/checkout@v5
1251
- name: Use Node.js
1352
uses: actions/setup-node@v5
1453
with:
1554
node-version-file: '.nvmrc'
1655

17-
- name: '[Setup] Install dependencies'
56+
- name: 'Install dependencies'
1857
run: npm ci
1958

20-
- name: '[Build] Staging'
59+
- name: 'Build for Staging'
2160
run: npm run build:staging
2261

23-
- name: '[Build] Production'
62+
- name: 'Build for Production'
2463
run: npm run build:prod
2564

2665
- name: 'Authenticate to Google Cloud'
2766
uses: 'google-github-actions/auth@v1'
2867
with:
2968
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
3069

31-
- name: '[Deploy] Upload SDK Files to GCS'
70+
- name: 'Upload SDK Files to GCS'
3271
uses: 'google-github-actions/upload-cloud-storage@v1'
3372
with:
3473
path: 'build/releases'
3574
destination: 'sdk-builds-persistence-onesignal/web-sdk/${{ github.sha }}'
3675
parent: false
3776

38-
- name: '[Deploy] Get SDK Version'
77+
- name: 'Get SDK Version'
3978
id: get_version
4079
run: echo "SDK_VERSION=$(node -p "require('./package.json').config.sdkVersion")" >> $GITHUB_OUTPUT
4180

42-
- name: '[Deploy] Create turbine pr'
81+
- name: 'Create turbine pr'
4382
run: ./build/scripts/turbine.sh
4483
env:
4584
GH_TURBINE_TOKEN: ${{ secrets.GH_TURBINE_TOKEN }}
4685
GITHUB_SHA: ${{ github.sha }}
4786
GITHUB_RUN_ID: ${{ github.run_id }}
4887
SDK_VERSION: ${{ steps.get_version.outputs.SDK_VERSION }}
88+
89+
- name: 'Create GiatHub Release'
90+
uses: actions/github-script@v8
91+
with:
92+
script: |
93+
await github.rest.actions.createWorkflowDispatch({
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
workflow_id: 'create-release-on-github.yml',
97+
ref: 'main'
98+
});

0 commit comments

Comments
 (0)