feat: Allow shader generators to report different language keys #8267
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: Publish PR package (pkg.pr.new) | |
| on: [pull_request] | |
| jobs: | |
| build-and-publish: | |
| if: github.event.pull_request.head.repo.full_name == github.repository | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| repository-projects: write | |
| steps: | |
| - name: Checkout your repository using git | |
| uses: actions/checkout@v4 | |
| - name: Fetch release ref | |
| run: git fetch --no-tags --depth=1 origin release:release | |
| - name: Print commit id, message and tag | |
| run: | | |
| git show -s --format='%h %s' | |
| echo "github.ref -> {{ github.ref }}" | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| run_install: false | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24.x | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install --recursive --frozen-lockfile | |
| - name: Publish (pkg.pr.new) | |
| run: pnpm exec bun scripts/publish-pkg-pr.ts | |
| - name: Post or update comment | |
| uses: actions/github-script@v6 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const sha = | |
| context.event_name === 'pull_request' | |
| ? context.payload.pull_request.head.sha | |
| : context.payload.after; | |
| const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${sha}`; | |
| const botCommentIdentifier = '**pkg.pr.new**'; | |
| async function findBotComment(issueNumber) { | |
| if (!issueNumber) return null; | |
| const comments = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| }); | |
| return comments.data.find((comment) => | |
| comment.body.includes(botCommentIdentifier) | |
| ); | |
| } | |
| async function findIssueNumber() { | |
| if (context.eventName === 'pull_request') { | |
| if (!context.issue.number) { | |
| throw new Error(`Expected issue number in the context`); | |
| } | |
| return context.issue.number; | |
| } else if (context.eventName === 'push') { | |
| const pullRequests = await github.rest.pulls.list({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| head: `${context.repo.owner}:${context.ref.replace( | |
| 'refs/heads/', | |
| '' | |
| )}`, | |
| }); | |
| if (pullRequests.data.length === 0) { | |
| throw new Error('No open pull request found for this push.'); | |
| } | |
| return pullRequests.data[0].number; | |
| } | |
| } | |
| async function createOrUpdateComment(issueNumber, body) { | |
| if (!issueNumber) { | |
| console.log('No issue number provided. Cannot post or update comment.'); | |
| return; | |
| } | |
| const existingComment = await findBotComment(issueNumber); | |
| if (existingComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existingComment.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| issue_number: issueNumber, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body, | |
| }); | |
| } | |
| } | |
| async function logPublishInfo(output) { | |
| console.log('\n' + '='.repeat(50)); | |
| console.log('Publish Information'); | |
| console.log('='.repeat(50)); | |
| console.log('\nPublished Packages:'); | |
| console.log(output.packages | |
| .map((p) => ` - '${p.url}'\n`) | |
| .join('')); | |
| console.log('\nTemplates:'); | |
| console.log(output.templates); | |
| console.log(`\nCommit URL: ${commitUrl}`); | |
| console.log('\n' + '='.repeat(50)); | |
| } | |
| if (!fs.existsSync('output.json')) { | |
| console.log('No packages changed since release.'); | |
| const body = `**pkg.pr.new** | |
| No packages changed since release`; | |
| await createOrUpdateComment(await findIssueNumber(), body); | |
| return; | |
| } | |
| const output = JSON.parse(fs.readFileSync('output.json', 'utf8')); | |
| const body = `**pkg.pr.new** | |
| *packages* | |
| Ready to be installed by your favorite package manager ⬇️ | |
| ${output.packages | |
| .map((p) => `\`\`\`\n${p.url}\n\`\`\``) | |
| .join('\n')} | |
| *benchmark* | |
| [view benchmark](https://docs.swmansion.com/TypeGPU/benchmark?p=npm-latest_pr-${context.issue.number}) | |
| *commit* | |
| [view commit](${commitUrl})`; | |
| try { | |
| await createOrUpdateComment(await findIssueNumber(), body); | |
| } finally { | |
| await logPublishInfo(output); | |
| } |