* Initial implementation * Fix * fix * fix * Make it look nicer * Update docs * Rename to pr-status-comment * Remove outputs * Update path * update name * Checkout PR in a detached worktree (#626) Co-authored-by: bluwy <bjornlu.dev@gmail.com> * Move comment to separate job * Loosen event requirement * Update * Apply suggestions from code review Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Use TLA * use using * Remove test log --------- Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
2.5 KiB
changesets/action/pr-status
This action generates the changesets status in PRs, e.g. whether it has changeset files and which packages will be released if the PR is merged.
It requires the repo to be checked out, and automatically fetches the PR head ref into a temporary detached worktree in order to infer the changed files and packages. It also requires the pull_request_target event to be triggered in order to have permissions to comment on the PR and to work in PRs from forks.
You can also use the pull_request event if you prefer to lock permissions down and not run for PRs from forks. Make sure to add an if check to prevent the action from failing in fork PRs:
jobs:
pr-status:
if: github.event.pull_request.head.repo.full_name == github.repository
# ...
See the action metadata for details on the inputs and outputs.
Warning
Do not run untrusted code when using the
pull_request_targetevent. The example below only checks out code and does not run any code from the PR. Read more about thepull_request_targetevent in the GitHub documentation.
Example setup
# .github/workflows/comment-changesets-pr-status.yml
name: Comment Changesets status in PRs
on:
pull_request_target:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
pr-status:
runs-on: ubuntu-slim
permissions:
contents: read # to check out files in the repo
outputs:
comment-body: ${{ steps.pr-status.outputs.comment-body }}
steps:
- name: Check out repo
uses: actions/checkout@v6
- name: Generate status
id: pr-status
uses: changesets/action/pr-status@v1
pr-comment:
needs: pr-status
runs-on: ubuntu-slim
permissions:
pull-requests: write # to create and update comments on PRs
steps:
- name: Comment on PR
uses: changesets/action/pr-comment@v1
with:
body: ${{ needs.pr-status.outputs.comment-body }}
update-id: changesets-pr-status
The workflow uses @changesets/action/pr-comment, which is a simple GitHub Action to comment on PRs.