95 lines
2.9 KiB
YAML
95 lines
2.9 KiB
YAML
# Adapted from create-t3-app.
|
|
name: Write Prerelease comment
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: ["Release"]
|
|
types:
|
|
- completed
|
|
|
|
jobs:
|
|
comment:
|
|
if: |
|
|
github.repository_owner == 'shadcn-ui' &&
|
|
github.event.workflow_run.event == 'pull_request' &&
|
|
github.event.workflow_run.conclusion == 'success'
|
|
runs-on: ubuntu-latest
|
|
name: Write comment to the PR
|
|
steps:
|
|
# Stable pushes and no-changeset runs upload no artifact, so a missing
|
|
# download is expected — gate the rest of the job on it succeeding.
|
|
- name: Download prerelease info
|
|
id: download
|
|
continue-on-error: true
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: prerelease-info
|
|
run-id: ${{ github.event.workflow_run.id }}
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build comment
|
|
id: info
|
|
if: steps.download.outcome == 'success'
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const fs = require("fs");
|
|
const info = JSON.parse(fs.readFileSync("prerelease-info.json", "utf8"));
|
|
|
|
if (!info.packages || info.packages.length === 0) {
|
|
core.info("No prerelease packages to comment.");
|
|
return;
|
|
}
|
|
|
|
const installs = info.packages
|
|
.map((p) => `pnpm dlx ${p.name}@${p.version}`)
|
|
.join("\n");
|
|
const links = info.packages
|
|
.map(
|
|
(p) =>
|
|
`- [${p.name}@${p.version}](https://www.npmjs.com/package/${p.name}/v/${p.version})`
|
|
)
|
|
.join("\n");
|
|
|
|
const body = [
|
|
`A new ${info.channel} prerelease is available for testing:`,
|
|
"",
|
|
"```sh",
|
|
installs,
|
|
"```",
|
|
"",
|
|
links,
|
|
].join("\n");
|
|
|
|
core.setOutput("pr", info.pr);
|
|
core.setOutput("channel", info.channel);
|
|
core.setOutput("body", body);
|
|
|
|
- name: Comment on PR
|
|
if: steps.info.outputs.body
|
|
uses: marocchino/sticky-pull-request-comment@v2
|
|
with:
|
|
number: ${{ steps.info.outputs.pr }}
|
|
message: ${{ steps.info.outputs.body }}
|
|
|
|
- name: Remove the prerelease label once published
|
|
if: steps.info.outputs.pr
|
|
uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
script: |
|
|
try {
|
|
await github.rest.issues.removeLabel({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: Number("${{ steps.info.outputs.pr }}"),
|
|
name: `release: ${{ steps.info.outputs.channel }}`,
|
|
});
|
|
} catch (error) {
|
|
if (error.status !== 404) {
|
|
throw error;
|
|
}
|
|
|
|
core.info("The prerelease label was already removed.");
|
|
}
|