From d401da70a2e4bc87f5ec4c2e1f82389db2459811 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Mon, 14 Oct 2024 17:14:58 -0700 Subject: [PATCH 1/5] Script to ghstack land --- .github/workflows/ghstack_land.yml | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/ghstack_land.yml diff --git a/.github/workflows/ghstack_land.yml b/.github/workflows/ghstack_land.yml new file mode 100644 index 00000000000..262490554b7 --- /dev/null +++ b/.github/workflows/ghstack_land.yml @@ -0,0 +1,45 @@ +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 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: '0' + - uses: actions/setup-python@v4 + with: + python-version: 3.10 + - 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.GARDENER_PAT }} + GITHUB_REF: ${{ github.ref }} From 723a522ede67ecefc3e89ae284fb40eb7a77f8cf Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Mon, 14 Oct 2024 17:17:50 -0700 Subject: [PATCH 2/5] 3.10 --- .github/workflows/ghstack_land.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ghstack_land.yml b/.github/workflows/ghstack_land.yml index 262490554b7..da57588d7d0 100644 --- a/.github/workflows/ghstack_land.yml +++ b/.github/workflows/ghstack_land.yml @@ -14,7 +14,7 @@ jobs: fetch-depth: '0' - uses: actions/setup-python@v4 with: - python-version: 3.10 + python-version: '3.10' - run: | pip install ghstack pip install pygithub From d44b311506ce92d4bdb04424ca169b3e37d65119 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Mon, 14 Oct 2024 17:20:10 -0700 Subject: [PATCH 3/5] Fix secret --- .github/workflows/ghstack_land.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ghstack_land.yml b/.github/workflows/ghstack_land.yml index da57588d7d0..dee92de1236 100644 --- a/.github/workflows/ghstack_land.yml +++ b/.github/workflows/ghstack_land.yml @@ -41,5 +41,5 @@ jobs: EOF # ghstack land "https://github.com/pytorch/executorch/pull/${PR_NUMBER}" env: - GITHUB_TOKEN: ${{ secrets.GARDENER_PAT }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REF: ${{ github.ref }} From 4bfee28c744006b7f0407261317d9f217087dab9 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Mon, 14 Oct 2024 17:24:03 -0700 Subject: [PATCH 4/5] Add permission --- .github/workflows/ghstack_land.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ghstack_land.yml b/.github/workflows/ghstack_land.yml index dee92de1236..90d91c3083c 100644 --- a/.github/workflows/ghstack_land.yml +++ b/.github/workflows/ghstack_land.yml @@ -15,7 +15,10 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: | + - name: Try to merge PR to main + permissions: + - pull-requests: write + run: | pip install ghstack pip install pygithub From ad69699b7381c478572872b4a642f16fbf7f9d36 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Mon, 14 Oct 2024 17:26:14 -0700 Subject: [PATCH 5/5] Fix permission --- .github/workflows/ghstack_land.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ghstack_land.yml b/.github/workflows/ghstack_land.yml index 90d91c3083c..ce81b569b8a 100644 --- a/.github/workflows/ghstack_land.yml +++ b/.github/workflows/ghstack_land.yml @@ -8,6 +8,8 @@ jobs: ghstack_land: name: ghstack-land runs-on: ubuntu-22.04 + permissions: + pull-requests: write steps: - uses: actions/checkout@v3 with: @@ -16,8 +18,6 @@ jobs: with: python-version: '3.10' - name: Try to merge PR to main - permissions: - - pull-requests: write run: | pip install ghstack pip install pygithub