examples 추가 #3840
Workflow file for this run
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: Label a PR with its updated packages | |
on: | |
pull_request: | |
types: [opened, synchronize, ready_for_review] | |
jobs: | |
label-pr: | |
if: ${{ github.event.pull_request.draft == false && github.event.pull_request.user.login != 'triple-bot' && !contains(github.event.pull_request.labels.*.name, 'release') }} | |
runs-on: [self-hosted, linux, x64] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: Get changed packages | |
run: | | |
RESPONSE=$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/${{ github.repository }}/compare/${{ github.event.pull_request.base.ref }}...${{ github.event.pull_request.head.ref }}") | |
if [[ $(echo "$RESPONSE" | jq '.total_commits') == null ]]; then | |
echo $RESPONSE | jq '.message' | |
exit 1 | |
fi | |
CHANGED_PACKAGES=$(echo "$RESPONSE" | jq '[.files[].filename | capture("packages/(?<packageName>[^/]+)/") .packageName] | unique | tostring') | |
echo "CHANGED_PACKAGES=$CHANGED_PACKAGES" >> $GITHUB_ENV | |
- name: Label PR | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
PACKAGE_LABELS=$(echo ${{ env.CHANGED_PACKAGES }} | jq .) | |
curl -X POST \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \ | |
-d "{\"labels\": $PACKAGE_LABELS }" |