Skip to content

Commit

Permalink
Updated workflows (#2847)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatChen authored Jun 13, 2024
1 parent 66059b4 commit 75a200c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 49 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 }}
12 changes: 3 additions & 9 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -20,18 +15,17 @@ 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

- 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' }}
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/ship.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}}
Expand All @@ -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
}}
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}}
Expand All @@ -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
}}
Expand Down
54 changes: 34 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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 != '' }}
Expand All @@ -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
Expand Down

0 comments on commit 75a200c

Please sign in to comment.