ci: streamline GitHub CLI authentication in cancel workflow

This commit is contained in:
chenhaoran 2025-03-13 10:44:58 +08:00
parent cf3582b964
commit b721ebed76
1 changed files with 1 additions and 7 deletions

View File

@ -8,17 +8,11 @@ jobs:
cancel-workflow:
runs-on: ubuntu-latest
steps:
- name: Set up GitHub CLI
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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 auth login --with-token $GH_TOKEN
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 --repo ${{ github.repository }} {}