Skip to content

Snapshot release by vercel[bot] #7665

Snapshot release by vercel[bot]

Snapshot release by vercel[bot] #7665

name: Snapshot release
run-name: Snapshot release by ${{ github.actor }}
on:
issue_comment:
types: [created]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.actor }}
cancel-in-progress: true
jobs:
snapshot-release:
if: ${{ startsWith(github.event.comment.body, '!snapshot') && github.repository == 'clerk/javascript' && github.event.issue.pull_request }}
runs-on: ${{ vars.RUNNER_LARGE || 'ubuntu-latest-l' }}
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }}
permissions:
contents: read
id-token: write
steps:
- name: Limit action to Clerk members
uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
github-token: ${{ secrets.CLERK_COOKIE_PAT }}
script: |
const isMember = await github.rest.orgs.checkMembershipForUser({
org: 'clerk',
username: context.actor
});
if (!isMember) {
core.setFailed(`@${actor} is not a member of the Clerk organization`);
}
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head
- name: Ensure the PR hasn't changed since initiating the !snapshot command.
uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
github-token: ${{ secrets.CLERK_COOKIE_PAT }}
script: |
const commentCreated = new Date(context.payload.comment.created_at);
const pr = await github.rest.pulls.get({
owner: 'clerk',
repo: 'javascript',
pull_number: context.issue.number,
});
const prLastUpdated = new Date(pr.updated_at);
if (prLastUpdated > commentCreated) {
core.setFailed("The PR has been updated since !snapshot was initiated. Please review the changes and re-run the !snapshot command.");
}
- name: Setup
id: config
uses: ./.github/actions/init
with:
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
turbo-team: ${{ vars.TURBO_TEAM }}
turbo-token: ${{ secrets.TURBO_TOKEN }}
registry-url: 'https://registry.npmjs.org'
- name: Extract snapshot name
id: extract-snapshot-name
uses: actions/github-script@v7
with:
script: |
const match = context.payload.comment.body.match(/!snapshot (.*)/)
const name = match && match[1] || '';
const isKebabCase = name.match(/^[a-z]+(-[a-z]+)*$/)
if(name && !isKebabCase) {
core.setFailed(`Invalid snapshot name: ${name}`);
}
core.setOutput('name', name);
- name: Version packages for snapshot
id: version-packages
run: pnpm version-packages:snapshot ${{ steps.extract-snapshot-name.outputs.name }} | tail -1 >> "$GITHUB_OUTPUT"
- name: Build release
if: steps.version-packages.outputs.success == '1'
run: pnpm turbo build $TURBO_ARGS
- name: Snapshot release
if: steps.version-packages.outputs.success == '1'
run: pnpm release:snapshot
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
- name: Package info
if: steps.version-packages.outputs.success == '1'
id: package-info
uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const files = await (await glob.create("./packages/*/package.json")).glob();
const descriptors = files
.map((file) => {
const { name, version } = JSON.parse(fs.readFileSync(file, "utf8"));
return { name, version };
})
.filter(({ version }) => version.includes("-${{ steps.extract-snapshot-name.outputs.name }}"));
let table = `| Package | Version |\n| --- | --- |\n`;
descriptors.forEach(({ name, version }) => {
table += `| ${name} | ${version} |\n`;
});
const snippets = descriptors
.map(
({ name, version }) =>
`\`${name}\`\n\`\`\`sh\nnpm i ${name}@${version} --save-exact\n\`\`\``
)
.join("\n");
core.setOutput("table", table);
core.setOutput("snippets", snippets);
- name: Update Comment
if: steps.version-packages.outputs.success == '1'
uses: peter-evans/[email protected]
with:
token: ${{ secrets.CLERK_COOKIE_PAT }}
comment-id: ${{ github.event.comment.id }}
reactions: heart
- name: Create snapshot release comment
if: steps.version-packages.outputs.success == '1'
uses: peter-evans/[email protected]
with:
token: ${{ secrets.CLERK_COOKIE_PAT }}
issue-number: ${{ github.event.issue.number }}
body: |
Hey @${{ github.event.comment.user.login }} - the snapshot version command generated the following package versions:
${{ steps.package-info.outputs.table }}
Tip: Use the snippet copy button below to quickly install the required packages.
${{ steps.package-info.outputs.snippets }}