Merge pull request #193 from Woosmap/chore/safe-dependency-updates #41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Notify on OpenAPI Schema Changes | |
| on: | |
| push: | |
| branches: [master] | |
| jobs: | |
| detect-and-notify: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| actions: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Find changed schema files | |
| id: schema_changes | |
| run: | | |
| git fetch origin master | |
| # include both schema changes and the merged OpenAPI JSON | |
| CHANGED=$(git diff --name-only origin/master...HEAD \ | |
| specification/schemas/ \ | |
| dist/merged-woosmap-openapi3.json \ | |
| ) | |
| echo "changed_files<<EOF" >> $GITHUB_OUTPUT | |
| echo "$CHANGED" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Find PR | |
| uses: jwalton/gh-find-current-pr@master | |
| id: findPr | |
| with: | |
| state: all | |
| - name: No PR found | |
| if: steps.findPr.outputs.number == '' | |
| run: echo "No PR found for this push. Skipping comment and issue creation." | |
| - name: Comment on PR or linked Issue if schemas changed | |
| if: steps.schema_changes.outputs.changed_files && steps.findPr.outputs.number != '' | |
| uses: actions/github-script@v6 | |
| with: | |
| github-token: ${{ secrets.HELPER_TOKEN }} | |
| script: | | |
| const publicOwner = context.repo.owner; | |
| const publicRepo = context.repo.repo; | |
| const prNumber = ${{ steps.findPr.outputs.number }}; | |
| // 1) grab PR details | |
| const { data: pr } = await github.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', { | |
| owner: publicOwner, | |
| repo: publicRepo, | |
| pull_number: prNumber | |
| }); | |
| const body = pr.body || ""; | |
| // Try both "Owner/Repo#123" and full "https://github.com/Owner/Repo/issues/123" | |
| const urlRegex = /https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/issues\/(\d+)/; | |
| const shortRegex = /([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)#(\d+)/; | |
| let match = body.match(urlRegex) || body.match(shortRegex); | |
| let targetOwner, targetRepo, targetNumber; | |
| if (match) { | |
| // In both cases, groups 1=owner, 2=repo, 3=number | |
| [, targetOwner, targetRepo, targetNumber] = match; | |
| targetNumber = parseInt(targetNumber, 10); | |
| } else { | |
| // No external issue reference → comment on this PR | |
| targetOwner = context.repo.owner; | |
| targetRepo = context.repo.repo; | |
| targetNumber = pr.number; | |
| } | |
| await github.rest.issues.createComment({ | |
| owner: targetOwner, | |
| repo: targetRepo, | |
| issue_number: targetNumber, | |
| body: "🔔 OpenAPI schema has changed. Dependent libraries/SDKs/Plugins need to be updated as well." | |
| }); | |
| - name: Create issue in Woosmap/woosmap if schemas changed | |
| if: steps.schema_changes.outputs.changed_files && steps.findPr.outputs.number != '' | |
| uses: actions/github-script@v6 | |
| with: | |
| github-token: ${{ secrets.HELPER_TOKEN }} | |
| script: | | |
| // 0) Grab the PR payload | |
| const publicOwner = context.repo.owner; | |
| const publicRepo = context.repo.repo; | |
| const prNumber = ${{ steps.findPr.outputs.number }}; | |
| // 1) grab PR details | |
| const { data: pr } = await github.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', { | |
| owner: publicOwner, | |
| repo: publicRepo, | |
| pull_number: prNumber | |
| }); | |
| // 1) Prepare private target repo | |
| const targetOwner = 'Woosmap'; | |
| const targetRepo = 'woosmap'; | |
| const issueTitle = `OpenAPI change: #${pr.number} - ${pr.title}`; | |
| const author = pr.user.login; | |
| // 2) Dedup via listForRepo on the private repo | |
| const { data: openIssues } = await github.rest.issues.listForRepo({ | |
| owner: targetOwner, | |
| repo: targetRepo, | |
| state: 'open', | |
| per_page: 100 | |
| }); | |
| if (openIssues.some(i => i.title === issueTitle)) { | |
| console.log(`Issue "${issueTitle}" already exists; skipping creation.`); | |
| return; | |
| } | |
| // 3) Fetch diff from the PUBLIC repo where this PR lives | |
| let diffText = ''; | |
| try { | |
| const diffRes = await github.request( | |
| 'GET /repos/{owner}/{repo}/pulls/{pull_number}', | |
| { | |
| owner: publicOwner, | |
| repo: publicRepo, | |
| pull_number: pr.number, | |
| mediaType: { format: 'diff' } | |
| } | |
| ); | |
| diffText = diffRes.data; | |
| } catch (err) { | |
| console.warn('Unable to fetch PR diff:', err.message); | |
| } | |
| // 4) Truncate or embed the diff | |
| let diffBlock = ''; | |
| if (diffText) { | |
| const MAX_FULL = 2000; | |
| const MAX_SNIP = 500; | |
| if (diffText.length <= MAX_FULL) { | |
| diffBlock = '```diff\n' + diffText + '\n```'; | |
| } else { | |
| const snippet = diffText.slice(0, MAX_SNIP) + '\n...'; | |
| diffBlock = '```diff\n' + snippet + '\n```'; | |
| } | |
| } | |
| // 5) Build the issue body with a checklist | |
| const bodyLines = [ | |
| `Schema files under \`specification/schemas/\` were updated in PR ${pr.html_url}.`, | |
| '', | |
| `> ${pr.title}`, | |
| '', | |
| diffBlock, | |
| '', | |
| '**Please update these dependent libraries/SDKs/Plugins:**', | |
| '- [ ] MapsJS', | |
| '- [ ] Native SDK', | |
| '- [ ] RN Plugin', | |
| '- [ ] Flutter Plugin' | |
| ].filter(Boolean); | |
| // 6) Create the issue in the PRIVATE repo, assigned to the PR author | |
| await github.rest.issues.create({ | |
| owner: targetOwner, | |
| repo: targetRepo, | |
| title: issueTitle, | |
| body: bodyLines.join('\n'), | |
| assignees: [author] | |
| }); | |
| # - name: Send Slack notification if schemas changed | |
| # if: steps.schema_changes.outputs.changed_files != '' | |
| # uses: slackapi/slack-github-action@v1 | |
| # with: | |
| # payload: | | |
| # { | |
| # "channel": "#mobile", | |
| # "text": "🚨 OpenAPI schema has changed. Please refer to the PR <${{ github.event.pull_request.html_url }}|#${{ github.event.pull_request.number }}> for more insights." | |
| # } | |
| # env: | |
| # SLACK_WEBHOOK_URL: ${{ secrets.WOOSMAP_SLACK_WEBHOOK }} |