From ac06514b1f094d25880a86a4358eafad50bc2ec2 Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 30 May 2024 12:44:34 +0100 Subject: [PATCH] Do not duplicate linting work --- .github/workflows/check-docs-site.yml | 17 +++---- .github/workflows/comment-on-linter-error.yml | 47 +++++++------------ .github/workflows/lint.yml | 8 ++++ 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/.github/workflows/check-docs-site.yml b/.github/workflows/check-docs-site.yml index ba2933b459..a7d6efe429 100644 --- a/.github/workflows/check-docs-site.yml +++ b/.github/workflows/check-docs-site.yml @@ -11,9 +11,12 @@ concurrency: cancel-in-progress: true jobs: - lint: - name: Lint + build: + name: Build runs-on: ubuntu-latest + defaults: + run: + working-directory: docs steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v2 @@ -23,11 +26,9 @@ jobs: with: node-version: 18 cache: "pnpm" - - name: Install - run: pnpm install --frozen-lockfile --prefer-offline + cache-dependency-path: | + docs/pnpm-lock.yaml - name: Install Docs - run: cd docs && pnpm install --frozen-lockfile --prefer-offline - - name: lint - run: cd docs && pnpm lint + run: pnpm install --frozen-lockfile --prefer-offline - name: Build - run: cd docs && pnpm build + run: pnpm build diff --git a/.github/workflows/comment-on-linter-error.yml b/.github/workflows/comment-on-linter-error.yml index 0f83bff3ae..f25a502815 100644 --- a/.github/workflows/comment-on-linter-error.yml +++ b/.github/workflows/comment-on-linter-error.yml @@ -1,53 +1,38 @@ name: Comment on lint failure on: - pull_request_target: + workflow_run: + workflows: + - Lint types: - - opened - branches: - - main + - completed concurrency: - group: ${{github.workflow}}-${{github.ref}} + group: "${{github.workflow}}-${{github.event.workflow_run.event}}-${{github.event.workflow_run.head_repository.full_name}}:${{github.event.workflow_run.head_branch}}" cancel-in-progress: true jobs: comment_on_lint_failure: name: Comment on lint failure runs-on: ubuntu-latest + if: | + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'failure' steps: - - name: Checkout repo - uses: actions/checkout@v4 + - uses: ipdxco/workflow-run-context@492ea3967eb2ca7ed76b7888b42fa7649addd975 # v1.1.1 + name: Get workflow run context + id: context with: - ref: "refs/pull/${{ github.event.number }}/merge" - - uses: pnpm/action-setup@v2 - with: - version: 9 - - uses: actions/setup-node@v4 - with: - node-version: 18 - cache: "pnpm" - - name: Install - run: pnpm install --frozen-lockfile --prefer-offline - - name: Build - run: pnpm build - - name: lint - run: pnpm lint - - name: Check dependency versions - run: node scripts/check-dependencies.js - - name: Install website - working-directory: docs/ - run: pnpm install --frozen-lockfile --prefer-offline - - name: Lint website - working-directory: docs/ - run: pnpm lint + artifacts-url: ${{ github.event.workflow_run.artifacts_url }} + artifact-names: event - uses: actions/github-script@v6 name: Comment on failure - if: ${{ failure() }} + env: + NUMBER: ${{ fromJSON(steps.context.outputs.artifacts)['event'].files['event.json'].number }} with: script: | github.rest.issues.createComment({ - issue_number: context.issue.number, + issue_number: process.env.NUMBER, owner: context.repo.owner, repo: context.repo.repo, body: "Thanks for submitting this PR!\n\nUnfortunately, it has some linter errors, so we can't merge it yet. Can you please fix them?\n\nRunning pnpm lint:fix in the root of the repository may fix them automatically." diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1bbe2d44f6..f3bd6a86e1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -47,3 +47,11 @@ jobs: - name: Check dependency versions if: matrix.working-directory == '' run: node scripts/check-dependencies.js + save_event: + name: Save event + runs-on: ubuntu-latest + steps: + - uses: actions/upload-artifact@v4 + with: + name: event + path: ${{ github.event_path }}