mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[ci] Add ghstack /land bot
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
name: (Shared) ghstack land
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
permissions: {}
|
||||
|
||||
env:
|
||||
TZ: /usr/share/zoneinfo/America/Los_Angeles
|
||||
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout
|
||||
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1
|
||||
|
||||
jobs:
|
||||
check_access:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
is_member_or_collaborator: ${{ steps.check_access.outputs.result }}
|
||||
steps:
|
||||
- name: Check access
|
||||
id: check_access
|
||||
if: ${{ github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR' }}
|
||||
run: echo "is_member_or_collaborator=true" >> "$GITHUB_OUTPUT"
|
||||
|
||||
check_maintainer:
|
||||
if: ${{ needs.check_access.outputs.is_member_or_collaborator == 'true' }}
|
||||
needs: [check_access]
|
||||
uses: facebook/react/.github/workflows/shared_check_maintainer.yml@main
|
||||
permissions:
|
||||
# Used by check_maintainer
|
||||
contents: read
|
||||
with:
|
||||
actor: ${{ github.event.comment.user.login }}
|
||||
|
||||
ghstack_land:
|
||||
if: ${{ needs.check_maintainer.outputs.is_core_team == 'true' && github.event.issue.pull_request && contains(github.event.comment.body, '/land') }}
|
||||
needs: [check_maintainer]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Add reaction to comment
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const owner = context.repo.owner;
|
||||
const repo = context.repo.repo;
|
||||
const comment_id = "${{ github.event.comment.id }}"
|
||||
|
||||
await github.rest.reactions.createForCommitComment({
|
||||
owner,
|
||||
repo,
|
||||
comment_id,
|
||||
content: "rocket",
|
||||
});
|
||||
- name: Get PR details
|
||||
id: get-pr
|
||||
run: |
|
||||
PR_NUMBER=${{ github.event.issue.number }}
|
||||
echo "PR number is $PR_NUMBER"
|
||||
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
|
||||
|
||||
# Get PR details using GitHub API
|
||||
PR_DATA=$(curl -s \
|
||||
-H "Authorization: token ${{ github.token }}" \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
"${{ github.api_url }}/repos/${{ github.repository }}/pulls/$PR_NUMBER")
|
||||
|
||||
# Extract useful information
|
||||
PR_HEAD_REF=$(echo "$PR_DATA" | jq -r .head.ref)
|
||||
PR_HEAD_SHA=$(echo "$PR_DATA" | jq -r .head.sha)
|
||||
PR_URL="${{ github.server_url }}/${{ github.repository }}/pull/$PR_NUMBER"
|
||||
|
||||
echo "pr_branch=$PR_HEAD_REF" >> $GITHUB_OUTPUT
|
||||
echo "pr_sha=$PR_HEAD_SHA" >> $GITHUB_OUTPUT
|
||||
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
|
||||
echo "pr_branch=$PR_HEAD_REF"
|
||||
echo "pr_sha=$PR_HEAD_SHA"
|
||||
echo "pr_url=$PR_URL"
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ghstack-pip-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('**/requirements.txt') }}
|
||||
restore-keys: |
|
||||
ghstack-pip-${{ runner.arch }}-${{ runner.os }}-
|
||||
ghstack-pip-
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: 3.9
|
||||
- name: Install ghstack
|
||||
run: pip install requests ghstack
|
||||
- name: Check Current CI Status
|
||||
run: |
|
||||
echo ${{ github.event.issue.number }}
|
||||
.github/workflows/scripts/ghstack-perm-check.py ${{ github.event.issue.number }} ${{steps.get-pr.outputs.pr_branch}} <<'EOF'
|
||||
${{ toJson(github) }}
|
||||
EOF
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
- name: Land It!
|
||||
run: |
|
||||
git config --global user.email "bot@react.dev"
|
||||
git config --global user.name "react bot"
|
||||
cat <<EOF > ~/.ghstackrc
|
||||
[ghstack]
|
||||
github_url = github.com
|
||||
github_oauth = $GITHUB_TOKEN
|
||||
github_username = foo
|
||||
remote_name = origin
|
||||
EOF
|
||||
# ghstack land "${{ steps.get-pr.outputs.pr_url }}"
|
||||
echo "${{ steps.get-pr.outputs.pr_url }}"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
Reference in New Issue
Block a user