From 14cf6bff24b189bf3febd96b940d963b47c05283 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 16 Dec 2021 01:57:59 +0100 Subject: [PATCH] tools: fix `GitHub actions status when CQ is empty Refs: https://github.com/nodejs/node/pull/40985#issuecomment-995252065 --- .github/workflows/auto-start-ci.yml | 19 ++++++++++++++++--- .github/workflows/commit-queue.yml | 23 ++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.github/workflows/auto-start-ci.yml b/.github/workflows/auto-start-ci.yml index 11ebd15d85ec5a..76263fd1a7351e 100644 --- a/.github/workflows/auto-start-ci.yml +++ b/.github/workflows/auto-start-ci.yml @@ -16,19 +16,33 @@ jobs: if: github.repository == 'nodejs/node' runs-on: ubuntu-latest steps: + - name: Get Pull Requests + continue_on_error: true + id: get_prs_for_ci + run: gh pr list \ + --repo ${{ github.repository }} \ + --base ${{ env.DEFAULT_BRANCH }} \ + --label 'request-ci' \ + --json 'number' \ + -t '::set-output name=numbers::{{ range . }}{{ .number }} {{ end }}' \ + --limit 100 - uses: actions/checkout@v2 + if: ${{ success() }} with: persist-credentials: false # Install dependencies - name: Install Node.js + if: ${{ success() }} uses: actions/setup-node@v2 with: node-version: ${{ env.NODE_VERSION }} - name: Install node-core-utils + if: ${{ success() }} run: npm install -g node-core-utils - name: Setup node-core-utils + if: ${{ success() }} run: | ncu-config set username ${{ secrets.JENKINS_USER }} ncu-config set token none @@ -37,8 +51,7 @@ jobs: ncu-config set repo "$(echo ${{ github.repository }} | cut -d/ -f2)" - name: Start the CI - run: | - PRs=$(gh pr list --label 'request-ci' --json number --jq 'map(.number) | .[]' --limit 100) - ./tools/actions/start-ci.sh "$PRs" + if: ${{ success() }} + run: ./tools/actions/start-ci.sh "${{ steps.get_prs_for_ci.outputs.numbers }}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/commit-queue.yml b/.github/workflows/commit-queue.yml index dbaf55dafc34fa..7e57153ad71fff 100644 --- a/.github/workflows/commit-queue.yml +++ b/.github/workflows/commit-queue.yml @@ -21,7 +21,18 @@ jobs: if: github.repository == 'nodejs/node' runs-on: ubuntu-latest steps: + - name: Get Pull Requests + continue_on_error: true + id: get_mergable_pull_requests + run: gh pr list \ + --repo ${{ github.repository }} \ + --base ${{ env.DEFAULT_BRANCH }} \ + --label 'commit-queue' \ + --json 'number' \ + -t '::set-output name=numbers::{{ range . }}{{ .number }} {{ end }}' \ + --limit 100 - uses: actions/checkout@v2 + if: ${{ success() }} with: # Needs the whole git history for ncu to work # See https://github.com/nodejs/node-core-utils/pull/486 @@ -34,6 +45,7 @@ jobs: # Install dependencies - name: Install Node.js + if: ${{ success() }} uses: actions/setup-node@v2 with: node-version: ${{ env.NODE_VERSION }} @@ -41,12 +53,14 @@ jobs: run: npm install -g node-core-utils@latest - name: Set variables + if: ${{ success() }} run: | echo "REPOSITORY=$(echo ${{ github.repository }} | cut -d/ -f2)" >> $GITHUB_ENV echo "OWNER=${{ github.repository_owner }}" >> $GITHUB_ENV echo "DEFAULT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV - name: Configure node-core-utils + if: ${{ success() }} run: | ncu-config set branch ${DEFAULT_BRANCH} ncu-config set upstream origin @@ -57,12 +71,7 @@ jobs: ncu-config set owner "${OWNER}" - name: Start the Commit Queue - run: | - PRs=$(gh pr list \ - --base ${{ env.DEFAULT_BRANCH }} \ - --label 'commit-queue' \ - --json number --jq 'map(.number) | .[]' \ - --limit 100) - ./tools/actions/commit-queue.sh ${{ env.OWNER }} ${{ env.REPOSITORY }} "$PRs" + if: ${{ success() }} + run: ./tools/actions/commit-queue.sh ${{ env.OWNER }} ${{ env.REPOSITORY }} "${{ steps.get_mergable_pull_requests.outputs.numbers }}" env: GITHUB_TOKEN: ${{ secrets.GH_USER_TOKEN }}