sonic-buildimage/.github/workflows/pr_cherrypick_poststep.yml
Liu Shilong cabaebb4b0
[action] Update github actions on trigger and label. (#13542)
Why I did it
github action will report error on forked repos. It is not by design.
keep 'Approved for xxx branch' label in auto cherry pick workflow.
How I did it
Disable github action on folked repos.
Keep 'approved for xxx' label in auto cherry pick workflow.
How to verify it
Which release bra
2023-01-30 16:57:39 +08:00

50 lines
1.8 KiB
YAML

name: PostCherryPick
on:
pull_request_target:
types:
- closed
branches:
- '20*'
jobs:
post_cherry_pick:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'automerge') && github.event.pull_request.head.user.login == 'mssonicbld' && startsWith(github.event.pull_request.title, '[action]')
runs-on: ubuntu-latest
steps:
- name: Debug
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo $GITHUB_CONTEXT | jq
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Main
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
TOKEN: ${{ secrets.TOKEN }}
run: |
set -e
pr_url=$(echo $GITHUB_CONTEXT | jq -r ".event.pull_request._links.html.href")
pr_id=$(echo $GITHUB_CONTEXT | jq -r ".event.number")
base_ref=$(echo $GITHUB_CONTEXT | jq -r ".base_ref")
echo ${TOKEN} | gh auth login --with-token
title=$(echo $GITHUB_CONTEXT | jq -r ".event.pull_request.title")
origin_pr_id=$(echo $title | grep -Eo "\[action\] \[PR:[0-9]*\]" | grep -Eo "[0-9]*")
origin_pr_url=$(echo $pr_url | sed "s/$pr_id/$origin_pr_id/")
echo =============================
echo pr_url: $pr_url
echo pr_id: $pr_id
echo base_ref: $base_ref
echo title: $title
echo origin_pr_id: $origin_pr_id
echo origin_pr_url: $origin_pr_url
echo =============================
# Add label
if [[ "$origin_pr_id" == "" ]];then
echo "original PR didn't found."
exit 1
fi
gh pr edit $origin_pr_url --add-label "Included in ${base_ref} Branch"
gh pr edit $origin_pr_url --remove-label "Created PR to ${base_ref} Branch"