|
| 1 | +name: Release preview |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + preview: |
| 13 | + if: github.event.pull_request.head.repo.full_name == github.repository |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v6 |
| 17 | + with: |
| 18 | + ref: ${{ github.event.pull_request.head.sha }} |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: 26 |
| 24 | + cache: npm |
| 25 | + |
| 26 | + - run: npm ci |
| 27 | + |
| 28 | + - id: preview |
| 29 | + run: | |
| 30 | + GITHUB_EVENT_NAME=push GITHUB_REF="refs/heads/$BRANCH" \ |
| 31 | + node --input-type=module -e ' |
| 32 | + import { readFileSync, writeFileSync } from "node:fs"; |
| 33 | + import semanticRelease from "semantic-release"; |
| 34 | + // haddock-since verifyConditions needs stack on PATH; not worth a GHC install for a preview |
| 35 | + const { plugins } = JSON.parse(readFileSync(".releaserc.json", "utf8")); |
| 36 | + const res = await semanticRelease({ |
| 37 | + dryRun: true, |
| 38 | + branches: [process.env.BRANCH], |
| 39 | + plugins: plugins.filter((p) => !(Array.isArray(p) ? p[0] : p).includes("haddock-since")), |
| 40 | + }); |
| 41 | + writeFileSync("comment.md", res?.nextRelease |
| 42 | + ? `## Release preview\n\nNext version: \`${res.nextRelease.version}\`\n\n${res.nextRelease.notes}` |
| 43 | + : "## Release preview\n\nNo release would be published from this branch.\n"); |
| 44 | + ' |
| 45 | + env: |
| 46 | + BRANCH: ${{ github.head_ref }} |
| 47 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + |
| 49 | + - run: gh pr comment "$NUMBER" --body-file comment.md --edit-last --create-if-none |
| 50 | + env: |
| 51 | + NUMBER: ${{ github.event.pull_request.number }} |
| 52 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments