From 9418f555ab9128dd702dcbdc7c36a3a451bcf571 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 2 Apr 2024 23:02:51 +0000 Subject: [PATCH 1/2] add more Signed-off-by: Peter Zhu --- .github/workflows/backport.yml | 61 +++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 8f933b2ada..5af9e1ea04 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -1,9 +1,9 @@ name: Backport -on: - pull_request_target: - types: - - closed - - labeled +on: [pull_request] +# pull_request_target: +# types: +# - closed +# - labeled jobs: backport: @@ -14,27 +14,34 @@ jobs: name: Backport # Only react to merged PRs for security reasons. # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target. - if: > - github.event.pull_request.merged - && ( - github.event.action == 'closed' - || ( - github.event.action == 'labeled' - && contains(github.event.label.name, 'backport') - ) - ) +# if: > +# github.event.pull_request.merged +# && ( +# github.event.action == 'closed' +# || ( +# github.event.action == 'labeled' +# && contains(github.event.label.name, 'backport') +# ) +# ) steps: - - name: GitHub App token - id: github_app_token - uses: tibdex/github-app-token@v1.5.0 - with: - app_id: ${{ secrets.APP_ID }} - private_key: ${{ secrets.APP_PRIVATE_KEY }} - # opensearch-trigger-bot installation ID - installation_id: 22958780 +# - name: GitHub App token +# id: github_app_token +# uses: tibdex/github-app-token@v1.5.0 +# with: +# app_id: ${{ secrets.APP_ID }} +# private_key: ${{ secrets.APP_PRIVATE_KEY }} +# # opensearch-trigger-bot installation ID +# #installation_id: 22958780 - - name: Backport - uses: VachaShah/backport@v2.1.0 - with: - github_token: ${{ steps.github_app_token.outputs.token }} - head_template: backport/backport-<%= number %>-to-<%= base %> +# - name: Backport +# uses: VachaShah/backport@v2.1.0 +# with: +# github_token: ${{ steps.github_app_token.outputs.token }} +# head_template: backport/backport-<%= number %>-to-<%= base %> + + - name: Check gh + run: | + PR_BRANCH=test123123 + gh pr list -R peterzhuamazon/documentation-website --json "number,headRefName" --state open | jq -r ".[] | select(.headRefName == \"$PR_BRANCH\") | .number" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From a188c14ad971c11d4ed306a55f187fd64b4e472c Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 2 Apr 2024 23:16:54 +0000 Subject: [PATCH 2/2] Add more Signed-off-by: Peter Zhu --- .github/workflows/backport.yml | 64 ++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 5af9e1ea04..54999718d1 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -1,9 +1,9 @@ name: Backport -on: [pull_request] -# pull_request_target: -# types: -# - closed -# - labeled +on: + pull_request_target: + types: + - closed + - labeled jobs: backport: @@ -14,34 +14,36 @@ jobs: name: Backport # Only react to merged PRs for security reasons. # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target. -# if: > -# github.event.pull_request.merged -# && ( -# github.event.action == 'closed' -# || ( -# github.event.action == 'labeled' -# && contains(github.event.label.name, 'backport') -# ) -# ) + if: > + github.event.pull_request.merged + && ( + github.event.action == 'closed' + || ( + github.event.action == 'labeled' + && contains(github.event.label.name, 'backport') + ) + ) steps: -# - name: GitHub App token -# id: github_app_token -# uses: tibdex/github-app-token@v1.5.0 -# with: -# app_id: ${{ secrets.APP_ID }} -# private_key: ${{ secrets.APP_PRIVATE_KEY }} -# # opensearch-trigger-bot installation ID -# #installation_id: 22958780 + - name: GitHub App token + id: github_app_token + uses: tibdex/github-app-token@v1.5.0 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + # opensearch-trigger-bot installation ID + #installation_id: 22958780 -# - name: Backport -# uses: VachaShah/backport@v2.1.0 -# with: -# github_token: ${{ steps.github_app_token.outputs.token }} -# head_template: backport/backport-<%= number %>-to-<%= base %> + - name: Backport + uses: VachaShah/backport@v2.1.0 + with: + github_token: ${{ steps.github_app_token.outputs.token }} + head_template: backport/backport-<%= number %>-to-<%= base %> - - name: Check gh + - name: Label new backport PR with backport-automerge label run: | - PR_BRANCH=test123123 - gh pr list -R peterzhuamazon/documentation-website --json "number,headRefName" --state open | jq -r ".[] | select(.headRefName == \"$PR_BRANCH\") | .number" + PR_BRANCH=backport/backport-<%= number %>-to-<%= base %> + PR_NUMBER=`gh pr list -R peterzhuamazon/documentation-website --json "number,headRefName" --state open | jq -r ".[] | select(.headRefName == \"$PR_BRANCH\") | .number"` + echo "Update Backport PR #$PR_NUMBER on branch $PR_BRANCH with backport-automerge label" + gh issue edit -R peterzhuamazon/documentation-website $PR_NUMBER --add-label backport-automerge env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ steps.github_app_token.outputs.token }}