|
1 | 1 | name: Build SDK Files & GCS Upload |
2 | 2 |
|
3 | 3 | on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths-ignore: |
| 8 | + - '**.md' |
4 | 9 | workflow_dispatch: |
5 | 10 |
|
6 | 11 | 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 | +
|
7 | 43 | test_build_deploy: |
8 | 44 | runs-on: ubuntu-22.04 |
9 | 45 |
|
| 46 | + needs: check_release |
| 47 | + if: needs.check_release.outputs.should_run == 'true' |
| 48 | + |
10 | 49 | steps: |
11 | 50 | - uses: actions/checkout@v5 |
12 | 51 | - name: Use Node.js |
13 | 52 | uses: actions/setup-node@v5 |
14 | 53 | with: |
15 | 54 | node-version-file: '.nvmrc' |
16 | 55 |
|
17 | | - - name: '[Setup] Install dependencies' |
| 56 | + - name: 'Install dependencies' |
18 | 57 | run: npm ci |
19 | 58 |
|
20 | | - - name: '[Build] Staging' |
| 59 | + - name: 'Build for Staging' |
21 | 60 | run: npm run build:staging |
22 | 61 |
|
23 | | - - name: '[Build] Production' |
| 62 | + - name: 'Build for Production' |
24 | 63 | run: npm run build:prod |
25 | 64 |
|
26 | 65 | - name: 'Authenticate to Google Cloud' |
27 | 66 | uses: 'google-github-actions/auth@v1' |
28 | 67 | with: |
29 | 68 | credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' |
30 | 69 |
|
31 | | - - name: '[Deploy] Upload SDK Files to GCS' |
| 70 | + - name: 'Upload SDK Files to GCS' |
32 | 71 | uses: 'google-github-actions/upload-cloud-storage@v1' |
33 | 72 | with: |
34 | 73 | path: 'build/releases' |
35 | 74 | destination: 'sdk-builds-persistence-onesignal/web-sdk/${{ github.sha }}' |
36 | 75 | parent: false |
37 | 76 |
|
38 | | - - name: '[Deploy] Get SDK Version' |
| 77 | + - name: 'Get SDK Version' |
39 | 78 | id: get_version |
40 | 79 | run: echo "SDK_VERSION=$(node -p "require('./package.json').config.sdkVersion")" >> $GITHUB_OUTPUT |
41 | 80 |
|
42 | | - - name: '[Deploy] Create turbine pr' |
| 81 | + - name: 'Create turbine pr' |
43 | 82 | run: ./build/scripts/turbine.sh |
44 | 83 | env: |
45 | 84 | GH_TURBINE_TOKEN: ${{ secrets.GH_TURBINE_TOKEN }} |
46 | 85 | GITHUB_SHA: ${{ github.sha }} |
47 | 86 | GITHUB_RUN_ID: ${{ github.run_id }} |
48 | 87 | 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