|
1 | | -name: publish |
| 1 | +# For trusted publishing releases, it is required to start all releases from a single workflow file. |
| 2 | +# This workflow delegates to the appropriate release workflow based on the event that triggered it. |
2 | 3 |
|
3 | 4 | on: |
| 5 | + # Triggers for canary releases |
| 6 | + schedule: |
| 7 | + - cron: '0 1 * * *' |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + tag: |
| 11 | + description: 'Dist tag for the release. If you chose something different than "canary", make sure to delete it once it is not needed anymore.' |
| 12 | + type: string |
| 13 | + required: false |
| 14 | + default: 'canary' |
| 15 | + # Triggers for official releases |
4 | 16 | release: |
5 | 17 | types: [published] # Trigger when a GitHub Release is published |
6 | 18 |
|
7 | | -env: |
8 | | - DOCS_REPO: SAP/ai-sdk |
9 | | - |
10 | 19 | jobs: |
11 | | - check-release-notes-pr: |
12 | | - name: Check Release Notes PR Status |
13 | | - runs-on: ubuntu-latest |
14 | | - outputs: |
15 | | - release_notes_branch: ${{ steps.determine-branch-name.outputs.release_notes_branch }} |
16 | | - is_merged: ${{ steps.check_pr_status.outputs.merged }} |
17 | | - steps: |
18 | | - - uses: sap/ai-sdk-js/.github/actions/setup@main |
19 | | - with: |
20 | | - node-version: ${{ vars.DEFAULT_NODE_VERSION }} |
21 | | - - name: Determine Docs PR Branch Name |
22 | | - id: determine-branch-name |
23 | | - run: | |
24 | | - VERSION=$(pnpm node -p "require('./package.json').version") |
25 | | - echo "Using version: $VERSION" |
26 | | - BRANCH_NAME="update-release-notes-js-$VERSION" |
27 | | - echo "release_notes_branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT" |
28 | | -
|
29 | | - - name: Check PR Status (Exists, Merged) |
30 | | - id: check_pr_status |
31 | | - run: | |
32 | | - BRANCH_NAME="${{ steps.determine-branch-name.outputs.release_notes_branch }}" |
33 | | - echo "Checking status for PR associated with branch: $BRANCH_NAME" |
34 | | -
|
35 | | - # Get merged status. If gh pr view fails (e.g., PR not found), the step will fail. |
36 | | - MERGED_OUTPUT=$(gh pr view "$BRANCH_NAME" --repo "${{ env.DOCS_REPO }}" --json state --jq '.state == "MERGED" | tostring') |
37 | | -
|
38 | | - # This part only runs if the above command succeeded |
39 | | - echo "PR found. Is Merged: $MERGED_OUTPUT" |
40 | | - echo "merged=$MERGED_OUTPUT" >> "$GITHUB_OUTPUT" |
41 | | - env: |
42 | | - GH_TOKEN: ${{ secrets.GH_CLOUD_SDK_JS_ADMIN_WRITE_TOKEN }} |
43 | | - |
44 | | - - name: 'Check Whether Release Notes PR Can Be Merged' |
45 | | - if: steps.check_pr_status.outputs.merged == 'false' |
46 | | - uses: ./.github/actions/pr-is-mergeable |
47 | | - with: |
48 | | - pr-ref: ${{ steps.determine-branch-name.outputs.release_notes_branch }} |
49 | | - repo: ${{ env.DOCS_REPO }} |
50 | | - token: ${{ secrets.GH_CLOUD_SDK_JS_ADMIN_WRITE_TOKEN }} |
51 | | - excluded-check-runs: | |
52 | | - { |
53 | | - \"Build Cloud SDK Documentation\": [\"dependabot\"] |
54 | | - } |
55 | | -
|
56 | | - publish-npm: |
57 | | - name: Publish to NPM |
58 | | - runs-on: ubuntu-latest |
59 | | - needs: [check-release-notes-pr] |
60 | | - permissions: |
61 | | - id-token: write |
62 | | - steps: |
63 | | - - uses: sap/ai-sdk-js/.github/actions/setup@main |
64 | | - with: |
65 | | - node-version: 24 # Will install npm 11 needed for trusted publishing |
66 | | - - name: publish |
67 | | - run: | |
68 | | - pnpm changeset publish |
69 | | -
|
70 | | - merge-release-notes-pr: |
71 | | - name: Merge Release Notes PR (if needed) |
72 | | - runs-on: ubuntu-latest |
73 | | - needs: [check-release-notes-pr, publish-npm] |
74 | | - if: needs.check-release-notes-pr.outputs.is_merged == 'false' |
75 | | - steps: |
76 | | - - name: 'Merge Release Notes PR' |
77 | | - run: | |
78 | | - echo "Attempting to merge PR for branch: ${{ needs.check-release-notes-pr.outputs.release_notes_branch }}" |
79 | | - gh pr merge --squash "${{ needs.check-release-notes-pr.outputs.release_notes_branch }}" --delete-branch --repo "${{ env.DOCS_REPO }}" |
80 | | - env: |
81 | | - GH_TOKEN: ${{ secrets.GH_CLOUD_SDK_JS_ADMIN_WRITE_TOKEN }} |
| 20 | + delegate_to_release_job: |
| 21 | + if: ${{ github.event_name == 'release' }} |
| 22 | + uses: ./.github/workflows/publish-release.yml |
| 23 | + secrets: inherit |
| 24 | + |
| 25 | + delegate_to_canary_job: |
| 26 | + if: ${{ github.event_name != 'release' }} |
| 27 | + uses: ./.github/workflows/publish-canary.yml |
| 28 | + secrets: inherit |
| 29 | + with: |
| 30 | + tag: ${{ github.event_name == 'schedule' && github.event.inputs.tag || 'canary' }} |
0 commit comments