diff --git a/.github/workflows/ghstack_land.yml b/.github/workflows/ghstack_land.yml new file mode 100644 index 00000000000..ce81b569b8a --- /dev/null +++ b/.github/workflows/ghstack_land.yml @@ -0,0 +1,48 @@ +name: Merge ghstack PRs to main +on: + pull_request: + branches: + - 'gh/*/[0-9]+/base' + - 'kirklandsigntest/*' +jobs: + ghstack_land: + name: ghstack-land + runs-on: ubuntu-22.04 + permissions: + pull-requests: write + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: '0' + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Try to merge PR to main + run: | + pip install ghstack + pip install pygithub + + PR_NUMBER=$(echo "$GITHUB_REF" | grep -oE '[0-9]+') + + echo "Checking whether PR $PR_NUMBER is merged" + PR_MERGED=$(python -c "from github import Github; g = Github(); repo = g.get_repo('pytorch/executorch'); pr = repo.get_pull(${PR_NUMBER}); print(1 if pr.merged else 0)") + if [ "$PR_MERGED" = "0" ]; then + echo $"PR $PR_NUMBER is not merged. No op here." + fi + python -c "from github import Auth, Github; g = Github(auth=Auth.Token('${GITHUB_TOKEN}')); repo = g.get_repo('pytorch/executorch'); pr = repo.get_pull(${PR_NUMBER}); pr.create_issue_comment('This PR is not merged into main. Trying to merge it.')" + exit 0 + + cd .github/workflows/scripts + git config --global user.email "pytorchbot@users.noreply.github.com" + git config --global user.name "PyTorch Bot" + cat < ~/.ghstackrc + [ghstack] + github_url = github.com + github_oauth = $GITHUB_TOKEN + github_username = pytorchbot + remote_name = origin + EOF + # ghstack land "https://github.com/pytorch/executorch/pull/${PR_NUMBER}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REF: ${{ github.ref }}