Field Base: Input #2435
This file contains 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: Check PR changset | |
on: | |
pull_request: | |
jobs: | |
check-changeset: | |
name: Run check | |
if: github.event.pull_request.title != 'Version Packages' | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node.js LTS | |
uses: actions/setup-node@v3 | |
with: | |
node-version: lts/* | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT" | |
- uses: actions/cache@v3 | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install dependencies | |
run: yarn install --prefer-offline --frozen-lockfile --silent | |
- name: Save PR number | |
run: | | |
mkdir -p ./pr | |
echo ${{ github.event.number }} > ./pr/NR | |
- name: Status check | |
run: yarn changeset status --since=`git log origin/main..HEAD --pretty=format:"%h" | tail -1` --output=changeset-status.json | |
- name: Comment when changeset is not found | |
if: failure() | |
run: | | |
cat > ./pr/COMMENT <<- EOM | |
## 🦋 Changeset status | |
No changeset found. You can add a changeset by running \`npx changeset\`, and then commiting the resulting changeset file. | |
If this PR should not cause a new release of any package, then an empty changeset should be added: | |
\`npx changeset add --empty\`. | |
EOM | |
- name: Generate comment text from changeset status | |
uses: actions/github-script@v7 | |
id: generate-comment-text | |
with: | |
script: | | |
const fs = require('fs'); | |
const changesetStatus = JSON.parse(fs.readFileSync('changeset-status.json', 'utf8')); | |
return changesetStatus.releases.map((release) => { | |
const packageName = release.name; | |
const type = release.type; | |
const oldVersion = release.oldVersion; | |
const newVersion = release.newVersion; | |
return `- **${packageName}**: ${oldVersion} → ${newVersion} (**${type}** bump)`; | |
}).join('\n'); | |
- name: Comment when empty changeset is found | |
if: ${{ failure() || steps.generate-comment-text.outputs.result == '""' }} | |
run: | | |
cat > ./pr/COMMENT <<- EOM | |
## 🦋 Changeset status | |
None or empty changeset found. This PR will not result any new releases. | |
If you believe this is incorrect, please add a changeset by running \`npx changeset\`, and then commiting the resulting changeset file. | |
You can also explicitly add an empty changeset by running: | |
\`npx changeset add --empty\` | |
EOM | |
- name: Comment when changeset is found | |
if: steps.generate-comment-text.outputs.result != '""' | |
run: | | |
cat > ./pr/COMMENT <<- EOM | |
## 🦋 Changeset status | |
Based on the included changeset, the following releases will be published as a result of this PR: | |
${{ fromJSON(steps.generate-comment-text.outputs.result) }} | |
*Note:* If unpublished changesets where merged to \`main\` after the first commit of this PR, this | |
list will include those changes in addition to the ones specific to this PR. | |
EOM | |
- name: Upload Artifact | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: pr | |
path: pr/ |