Repository navigation
Add Onward Flights to the service directory #387
Workflow file for this run
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: Changed Services | ||
|
Check warning on line 1 in .github/workflows/changed-services.yml
|
||
| on: | ||
| # This job fetches files through the API and treats their contents only as data. | ||
| pull_request_target: # zizmor: ignore[dangerous-triggers] | ||
| types: [opened, synchronize] | ||
| paths: | ||
| - "schemas/services.ts" | ||
| permissions: {} | ||
| jobs: | ||
| comment: | ||
| name: Report changed services | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Secure runner | ||
| uses: tempoxyz/gh-actions/actions/secure-runner@947d9a3ccb2425a9c94d563fd721cc0e33c89e26 # 2026-10-15T00-15-06Z-947d9a3c | ||
| - name: Diff services and comment | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | ||
| with: | ||
| script: | | ||
| async function fileAt({ owner, path, ref, repo }) { | ||
| try { | ||
| const { data } = await github.rest.repos.getContent({ | ||
| owner, | ||
| path, | ||
| ref, | ||
| repo, | ||
| }); | ||
| if (Array.isArray(data) || data.type !== 'file') return null; | ||
| return Buffer.from(data.content, data.encoding || 'base64').toString('utf8'); | ||
| } catch (error) { | ||
| if (error.status === 404) return null; | ||
| throw error; | ||
| } | ||
| } | ||
| function parseServicesTsIds(raw) { | ||
| if (!raw) return new Set(); | ||
| const ids = new Set(); | ||
| for (const m of raw.matchAll(/^\s*id:\s*["']([^"']+)["']/gm)) { | ||
| ids.add(m[1]); | ||
| } | ||
| return ids; | ||
| } | ||
| // --- main --- | ||
| const pr = context.payload.pull_request; | ||
| const path = 'schemas/services.ts'; | ||
| const baseTs = parseServicesTsIds(await fileAt({ | ||
| owner: pr.base.repo.owner.login, | ||
| path, | ||
| ref: pr.base.sha, | ||
| repo: pr.base.repo.name, | ||
| })); | ||
| const headTs = parseServicesTsIds(await fileAt({ | ||
| owner: pr.head.repo.owner.login, | ||
| path, | ||
| ref: pr.head.sha, | ||
| repo: pr.head.repo.name, | ||
| })); | ||
| const allIds = new Set([...baseTs, ...headTs]); | ||
| const added = []; | ||
| const removed = []; | ||
| for (const id of [...allIds].sort()) { | ||
| const wasPresent = baseTs.has(id); | ||
| const isPresent = headTs.has(id); | ||
| if (!wasPresent && isPresent) { | ||
| added.push(id); | ||
| } else if (wasPresent && !isPresent) { | ||
| removed.push(id); | ||
| } | ||
| } | ||
| if (added.length === 0 && removed.length === 0) { | ||
| console.log('No service-level changes detected.'); | ||
| return; | ||
| } | ||
| // --- build comment --- | ||
| const parts = ['## 🔀 Changed Services\n']; | ||
| if (added.length > 0) { | ||
| parts.push('### ✅ Added\n'); | ||
| for (const id of added) { | ||
| parts.push(`- \`${id}\``); | ||
| } | ||
| parts.push(''); | ||
| } | ||
| if (removed.length > 0) { | ||
| parts.push('### ❌ Removed\n'); | ||
| for (const id of removed) { | ||
| parts.push(`- ~~\`${id}\`~~`); | ||
| } | ||
| parts.push(''); | ||
| } | ||
| const body = parts.join('\n'); | ||
| // Upsert comment (find existing by marker) | ||
| const marker = '<!-- changed-services-bot -->'; | ||
| const fullBody = `${marker}\n${body}`; | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| per_page: 100, | ||
| }); | ||
| const existing = comments.find(c => c.body?.includes(marker)); | ||
| if (existing) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body: fullBody, | ||
| }); | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| body: fullBody, | ||
| }); | ||
| } | ||