mirror of
https://github.com/tabler/tabler.git
synced 2026-08-27 12:36:28 +04:00
chore: add /generate-changeset slash command workflow
Co-authored-by: codecalm <1282324+codecalm@users.noreply.github.com>
This commit is contained in:
co-authored by
codecalm
parent
9c4dc73a8b
commit
b4c3a66e58
@@ -0,0 +1,89 @@
|
||||
name: Generate Changeset
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
generate-changeset:
|
||||
name: Generate Changeset
|
||||
if: >
|
||||
github.event.issue.pull_request != null &&
|
||||
contains(github.event.comment.body, '/generate-changeset')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Add reaction to comment
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
await github.rest.reactions.createForIssueComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: context.payload.comment.id,
|
||||
content: '+1',
|
||||
});
|
||||
|
||||
- name: Get PR branch info
|
||||
id: pr
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const pr = await github.rest.pulls.get({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: context.issue.number,
|
||||
});
|
||||
core.setOutput('head_ref', pr.data.head.ref);
|
||||
core.setOutput('head_sha', pr.data.head.sha);
|
||||
core.setOutput('title', pr.data.title);
|
||||
|
||||
- name: Checkout PR branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ steps.pr.outputs.head_ref }}
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Parse bump type from comment
|
||||
id: bump
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const body = context.payload.comment.body.trim();
|
||||
const match = body.match(/\/generate-changeset\s+(patch|minor|major)/i);
|
||||
core.setOutput('type', match ? match[1].toLowerCase() : 'patch');
|
||||
|
||||
- name: Generate changeset file
|
||||
env:
|
||||
BUMP_TYPE: ${{ steps.bump.outputs.type }}
|
||||
PR_TITLE: ${{ steps.pr.outputs.title }}
|
||||
run: |
|
||||
CHANGESET_ID=$(tr -dc 'a-z' < /dev/urandom | fold -w 12 | head -n 1)
|
||||
FILENAME=".changeset/${CHANGESET_ID}.md"
|
||||
|
||||
cat > "$FILENAME" << EOF
|
||||
---
|
||||
"@tabler/core": $BUMP_TYPE
|
||||
"@tabler/preview": $BUMP_TYPE
|
||||
"@tabler/docs": $BUMP_TYPE
|
||||
---
|
||||
|
||||
$PR_TITLE
|
||||
EOF
|
||||
|
||||
# Trim leading whitespace from heredoc
|
||||
sed -i 's/^ //' "$FILENAME"
|
||||
|
||||
echo "Generated: $FILENAME"
|
||||
cat "$FILENAME"
|
||||
|
||||
- name: Commit and push changeset
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add .changeset/
|
||||
git commit -m "chore: add changeset for PR #${{ github.event.issue.number }}"
|
||||
git push
|
||||
Reference in New Issue
Block a user