From 75a200cc32fe5461191bcc382eda5094b83299c3 Mon Sep 17 00:00:00 2001 From: Cat Chen Date: Thu, 13 Jun 2024 23:46:32 +0000 Subject: [PATCH] Updated workflows (#2847) --- .github/workflows/build.yml | 16 +++++++++-- .github/workflows/eslint.yml | 12 ++------ .github/workflows/release.yml | 1 + .github/workflows/ship.yml | 24 ++++++++-------- .github/workflows/test-pr.yml | 12 ++++---- .github/workflows/test.yml | 54 ++++++++++++++++++++++------------- 6 files changed, 70 insertions(+), 49 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 714441b3..cd094f86 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,24 +16,36 @@ on: jobs: build: name: Build + if: ${{ !startsWith(github.head_ref, 'workflows/tests/') }} runs-on: ubuntu-latest permissions: pull-requests: write contents: write steps: + - uses: actions/create-github-app-token@v1 + id: get-github-app-token + with: + app-id: ${{ secrets.CHECK_GIT_STATUS_BOT_APP_ID }} + private-key: ${{ secrets.CHECK_GIT_STATUS_BOT_APP_PRIVATE_KEY }} + - uses: actions/checkout@v4 with: repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} ref: ${{ inputs.ref || github.head_ref }} + token: ${{ steps.get-github-app-token.outputs.token }} - uses: actions/setup-node@v4 with: node-version-file: '.nvmrc' check-latest: true + cache: yarn - name: Install dependencies run: yarn + - name: Lint + run: yarn lint --fix + - name: Build run: yarn build @@ -45,5 +57,5 @@ jobs: with: fail-if-not-clean: ${{ github.actor != 'dependabot[bot]' || github.actor_id != 49699333 }} push-if-not-clean: true - push-token: ${{ secrets.CHECK_GIT_STATUS_ACTION_TOKEN }} - request-changes-token: ${{ secrets.GITHUB_TOKEN }} + request-changes-if-not-clean: false + push-token: ${{ steps.get-github-app-token.outputs.token }} diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml index eb15f1da..1a0f496b 100644 --- a/.github/workflows/eslint.yml +++ b/.github/workflows/eslint.yml @@ -5,12 +5,7 @@ on: branches: [main] pull_request: branches: [main, '[0-9]+-[0-9]+-*'] - workflow_call: - inputs: - ref: - description: 'Checkout a different git ref instead of the SHA from the GitHub event.' - required: false - type: string + workflow_dispatch: jobs: eslint: @@ -20,13 +15,12 @@ jobs: steps: - uses: actions/checkout@v4 - with: - ref: ${{ inputs.ref }} - uses: actions/setup-node@v4 with: node-version-file: '.nvmrc' check-latest: true + cache: yarn - name: Install dependencies run: yarn install @@ -34,4 +28,4 @@ jobs: - uses: CatChen/eslint-suggestion-action@v4 with: targets: 'src' - fail-check: ${{ github.event_name == 'workflow_call' || (github.event_name == 'push' && github.ref == 'refs/heads/main') }} + fail-check: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 20924c3c..450d7794 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -104,6 +104,7 @@ jobs: node-version-file: '.nvmrc' check-latest: true registry-url: https://registry.npmjs.org/ + cache: yarn - env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/ship.yml b/.github/workflows/ship.yml index 7191c298..76dc5436 100644 --- a/.github/workflows/ship.yml +++ b/.github/workflows/ship.yml @@ -29,9 +29,9 @@ concurrency: group: |- ${{ github.event.pull_request.number || - join(github.event.check_run.pull_requests.*.number, ', ') || - join(github.event.check_suite.pull_requests.*.number, ', ') || - join(github.event.workflow_run.pull_requests.*.number, ', ') || + github.event.check_run.pull_requests[0].number || + github.event.check_suite.pull_requests[0].number || + github.event.workflow_run.pull_requests[0].number || github.sha || github.ref }} @@ -46,9 +46,9 @@ jobs: CONCURRENCY_GROUP: |- ${{ github.event.pull_request.number || - join(github.event.check_run.pull_requests.*.number, ', ') || - join(github.event.check_suite.pull_requests.*.number, ', ') || - join(github.event.workflow_run.pull_requests.*.number, ', ') || + github.event.check_run.pull_requests[0].number || + github.event.check_suite.pull_requests[0].number || + github.event.workflow_run.pull_requests[0].number || github.sha || github.ref }} @@ -61,9 +61,9 @@ jobs: ${{ github.base_ref == 'main' || github.event.pull_request.base.ref == 'main' || - contains(github.event.check_run.pull_requests.*.base.ref, 'main') || - contains(github.event.check_suite.pull_requests.*.base.ref, 'main') || - contains(github.event.workflow_run.pull_requests.*.base.ref, 'main') + contains(github.event.check_run.pull_requests[0].base.ref, 'main') || + contains(github.event.check_suite.pull_requests[0].base.ref, 'main') || + contains(github.event.workflow_run.pull_requests[0].base.ref, 'main') }} runs-on: ubuntu-latest permissions: @@ -93,9 +93,9 @@ jobs: ${{ github.base_ref == 'main' || github.event.pull_request.base.ref == 'main' || - contains(github.event.check_run.pull_requests.*.base.ref, 'main') || - contains(github.event.check_suite.pull_requests.*.base.ref, 'main') || - contains(github.event.workflow_run.pull_requests.*.base.ref, 'main') + contains(github.event.check_run.pull_requests[0].base.ref, 'main') || + contains(github.event.check_suite.pull_requests[0].base.ref, 'main') || + contains(github.event.workflow_run.pull_requests[0].base.ref, 'main') }} runs-on: ubuntu-latest permissions: diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 29f7f467..ee23d2a8 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -8,9 +8,9 @@ concurrency: group: |- ${{ github.event.pull_request.number || - join(github.event.check_run.pull_requests.*.number, ', ') || - join(github.event.check_suite.pull_requests.*.number, ', ') || - join(github.event.workflow_run.pull_requests.*.number, ', ') || + github.event.check_run.pull_requests[0].number || + github.event.check_suite.pull_requests[0].number || + github.event.workflow_run.pull_requests[0].number || github.sha || github.ref }} @@ -27,9 +27,9 @@ jobs: CONCURRENCY_GROUP: |- ${{ github.event.pull_request.number || - join(github.event.check_run.pull_requests.*.number, ', ') || - join(github.event.check_suite.pull_requests.*.number, ', ') || - join(github.event.workflow_run.pull_requests.*.number, ', ') || + github.event.check_run.pull_requests[0].number || + github.event.check_suite.pull_requests[0].number || + github.event.workflow_run.pull_requests[0].number || github.sha || github.ref }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cab4ae7f..cd057da7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,12 +10,6 @@ on: types: - completed workflow_dispatch: - workflow_call: - inputs: - ref: - description: 'Checkout a different git ref instead of the SHA from the GitHub event.' - required: false - type: string jobs: test: @@ -38,7 +32,6 @@ jobs: - uses: actions/checkout@v4 if: ${{ github.event_name != 'workflow_run' }} with: - ref: ${{ inputs.ref }} fetch-depth: 0 - uses: actions/checkout@v4 @@ -176,24 +169,37 @@ jobs: id: check-pr env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TEST_HEAD_PR_NUMBER: ${{ steps.open-head-pr.outputs.test-head-pr-number }} run: | CHECKS_TEMP_FILE="$(mktemp)" + echo "checks-temp-file=$CHECKS_TEMP_FILE" >> $GITHUB_OUTPUT; + sleep 10 - PENDING=$(gh pr checks | cut -f2 | grep pending | wc -l) - while [ $PENDING -ne 0 ] + CHECKS=$(gh pr checks "$TEST_HEAD_PR_NUMBER" | tee -a $CHECKS_TEMP_FILE) + PENDING=$(echo "$CHECKS" | cut -f2 | grep pending | wc -l) + + while [[ $PENDING -gt 0 && -n "$PENDING" ]] do echo "::group::Pending checks: $PENDING" - gh pr checks --watch + gh pr checks "$TEST_HEAD_PR_NUMBER" --watch --fail-fast | tee -a $CHECKS_TEMP_FILE + sleep 10 - PENDING=$(gh pr checks | cut -f2 | grep pending | wc -l) + CHECKS=$(gh pr checks "$TEST_HEAD_PR_NUMBER" | tee -a $CHECKS_TEMP_FILE) + PENDING=$(echo "$CHECKS" | cut -f2 | grep pending | wc -l) + echo "::endgroup::" done - gh pr checks >> $CHECKS_TEMP_FILE - echo "::notice::Temp file content: - $(cat $CHECKS_TEMP_FILE) - " - echo "checks-temp-file=$CHECKS_TEMP_FILE" >> $GITHUB_OUTPUT + if [[ -s $CHECKS_TEMP_FILE ]] + then + echo "::group::Temp file content" + cat $CHECKS_TEMP_FILE + echo "::endgroup::" + else + echo "checks-temp-file=" >> $GITHUB_OUTPUT; + fi + + gh pr checks "$TEST_HEAD_PR_NUMBER" # Let check outcome determine the step exit code - name: Report Checks if: ${{ always() && steps.check-pr.outputs.checks-temp-file != '' }} @@ -203,11 +209,19 @@ jobs: TEST_HEAD_PR_NUMBER: ${{ steps.open-head-pr.outputs.test-head-pr-number }} CHECKS_TEMP_FILE: ${{ steps.check-pr.outputs.checks-temp-file }} run: | - gh pr comment "$BASE_PR_NUMBER" --body "**Checks from #$TEST_HEAD_PR_NUMBER** + gh pr comment "$BASE_PR_NUMBER" --body "**Checks from Push Test PR #$TEST_HEAD_PR_NUMBER** - | Check | Status | - | --- | --- | - $(cat $CHECKS_TEMP_FILE | grep -E 'https://' | tac | awk 'BEGIN { FS ="\t" } ; { if (! seen[$1]++) print }' | sed -E 's/(.*)\t(.*)\t(.*)\t(.*)\t(.*)/| [\1](\4) | \2 |/')" + | Check | Status | Time | + | --- | --- | --: | + $(cat $CHECKS_TEMP_FILE | + grep -E 'https://' | + tac | + awk 'BEGIN { FS ="\t" } ; { if (! seen[$1]++) print }' | + sed -E 's/(.*)\t(pass)\t(.*)\t(.*)\t(.*)/| [**\1**](\4) | ✅ | \3 |/; + s/(.*)\t(fail)\t(.*)\t(.*)\t(.*)/| [*\1*](\4) | ⛔ | \3 |/; + s/(.*)\t(skipping)\t(.*)\t(.*)\t(.*)/| [~\1~](\4) | ⏭️ | |/; + s/(.*)\t(pending)\t(.*)\t(.*)\t(.*)/| [\1](\4) | 🔄 | |/; + s/(.*)\t(.*)\t(.*)\t(.*)\t(.*)/| [\1](\4) | \2 | \3 |/')" rm -f $CHECKS_TEMP_FILE - name: Verify PR