ci: enhance workflow to set up GitHub CLI and cancel on PR merge or close

This commit is contained in:
chenhaoran 2025-03-13 09:39:06 +08:00
parent 4adee83552
commit ad7afcc437
1 changed files with 7 additions and 0 deletions

View File

@ -8,8 +8,15 @@ jobs:
cancel-workflow:
runs-on: ubuntu-latest
steps:
- name: Set up GitHub CLI
run: |
echo "${{ secrets.GITHUB_TOKEN }}" > ~/.gh_token
gh auth login --with-token < ~/.gh_token
- name: Cancel Workflow if Merged or Closed
if: ${{ github.event.pull_request.merged || github.event.pull_request.state == 'closed' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "PR has been merged or closed, cancelling workflow..."
gh run list --repo ${{ github.repository }} --branch ${{ github.event.pull_request.head.ref }} --workflow "TDengine Test" --status in_progress --json databaseId --jq '.[].databaseId' | xargs -I {} gh run cancel {}