|
| 1 | +name: (Shared) ghstack land |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +permissions: {} |
| 8 | + |
| 9 | +env: |
| 10 | + TZ: /usr/share/zoneinfo/America/Los_Angeles |
| 11 | + # https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout |
| 12 | + SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1 |
| 13 | + |
| 14 | +jobs: |
| 15 | + check_access: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + is_member_or_collaborator: ${{ steps.check_access.outputs.result }} |
| 19 | + steps: |
| 20 | + - name: Check access |
| 21 | + id: check_access |
| 22 | + if: ${{ github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR' }} |
| 23 | + run: echo "is_member_or_collaborator=true" >> "$GITHUB_OUTPUT" |
| 24 | + |
| 25 | + check_maintainer: |
| 26 | + if: ${{ needs.check_access.outputs.is_member_or_collaborator == 'true' }} |
| 27 | + needs: [check_access] |
| 28 | + uses: facebook/react/.github/workflows/shared_check_maintainer.yml@main |
| 29 | + permissions: |
| 30 | + # Used by check_maintainer |
| 31 | + contents: read |
| 32 | + with: |
| 33 | + actor: ${{ github.event.comment.user.login }} |
| 34 | + |
| 35 | + ghstack_land: |
| 36 | + if: ${{ needs.check_maintainer.outputs.is_core_team == 'true' && github.event.issue.pull_request && contains(github.event.comment.body, '/land') }} |
| 37 | + needs: [check_maintainer] |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - name: Add reaction to comment |
| 41 | + uses: actions/github-script@v7 |
| 42 | + with: |
| 43 | + script: | |
| 44 | + const owner = context.repo.owner; |
| 45 | + const repo = context.repo.repo; |
| 46 | + const comment_id = "${{ github.event.comment.id }}" |
| 47 | +
|
| 48 | + await github.rest.reactions.createForCommitComment({ |
| 49 | + owner, |
| 50 | + repo, |
| 51 | + comment_id, |
| 52 | + content: "rocket", |
| 53 | + }); |
| 54 | + - name: Get PR details |
| 55 | + id: get-pr |
| 56 | + run: | |
| 57 | + PR_NUMBER=${{ github.event.issue.number }} |
| 58 | + echo "PR number is $PR_NUMBER" |
| 59 | + echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT |
| 60 | +
|
| 61 | + # Get PR details using GitHub API |
| 62 | + PR_DATA=$(curl -s \ |
| 63 | + -H "Authorization: token ${{ github.token }}" \ |
| 64 | + -H "Accept: application/vnd.github.v3+json" \ |
| 65 | + "${{ github.api_url }}/repos/${{ github.repository }}/pulls/$PR_NUMBER") |
| 66 | +
|
| 67 | + # Extract useful information |
| 68 | + PR_HEAD_REF=$(echo "$PR_DATA" | jq -r .head.ref) |
| 69 | + PR_HEAD_SHA=$(echo "$PR_DATA" | jq -r .head.sha) |
| 70 | + PR_URL="${{ github.server_url }}/${{ github.repository }}/pull/$PR_NUMBER" |
| 71 | +
|
| 72 | + echo "pr_branch=$PR_HEAD_REF" >> $GITHUB_OUTPUT |
| 73 | + echo "pr_sha=$PR_HEAD_SHA" >> $GITHUB_OUTPUT |
| 74 | + echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT |
| 75 | + echo "pr_branch=$PR_HEAD_REF" |
| 76 | + echo "pr_sha=$PR_HEAD_SHA" |
| 77 | + echo "pr_url=$PR_URL" |
| 78 | + - uses: actions/checkout@v4 |
| 79 | + - uses: actions/cache@v4 |
| 80 | + with: |
| 81 | + path: ~/.cache/pip |
| 82 | + key: ghstack-pip-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('**/requirements.txt') }} |
| 83 | + restore-keys: | |
| 84 | + ghstack-pip-${{ runner.arch }}-${{ runner.os }}- |
| 85 | + ghstack-pip- |
| 86 | + - uses: actions/setup-python@v4 |
| 87 | + with: |
| 88 | + python-version: 3.9 |
| 89 | + - name: Install ghstack |
| 90 | + run: pip install requests ghstack |
| 91 | + - name: Check Current CI Status |
| 92 | + run: | |
| 93 | + echo ${{ github.event.issue.number }} |
| 94 | + .github/workflows/scripts/ghstack-perm-check.py ${{ github.event.issue.number }} ${{steps.get-pr.outputs.pr_branch}} <<'EOF' |
| 95 | + ${{ toJson(github) }} |
| 96 | + EOF |
| 97 | + env: |
| 98 | + GITHUB_TOKEN: ${{ github.token }} |
| 99 | + - name: Land It! |
| 100 | + run: | |
| 101 | + git config --global user.email "[email protected]" |
| 102 | + git config --global user.name "react bot" |
| 103 | + cat <<EOF > ~/.ghstackrc |
| 104 | + [ghstack] |
| 105 | + github_url = github.com |
| 106 | + github_oauth = $GITHUB_TOKEN |
| 107 | + github_username = foo |
| 108 | + remote_name = origin |
| 109 | + EOF |
| 110 | + ghstack land "${{ steps.get-pr.outputs.pr_url }}" |
| 111 | + env: |
| 112 | + GITHUB_TOKEN: ${{ github.token }} |
0 commit comments