From 0f58353e25319442694ef089a05077cfd31e539a Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Thu, 10 Feb 2022 18:16:45 +0200 Subject: [PATCH] ci: use separate workflows for 'push' and 'pull_request' --- .github/workflows/canary.yaml | 2 +- .github/workflows/ci.yml | 63 +----------------- .../workflows/deploy-artifact-as-branch.yml | 9 +-- .github/workflows/pull_request.yml | 64 +++++++++++++++++++ .github/workflows/{cd.yml => push.yml} | 23 +++---- 5 files changed, 79 insertions(+), 82 deletions(-) create mode 100644 .github/workflows/pull_request.yml rename .github/workflows/{cd.yml => push.yml} (63%) diff --git a/.github/workflows/canary.yaml b/.github/workflows/canary.yaml index 9e0d1247cd..668c0ec1dc 100644 --- a/.github/workflows/canary.yaml +++ b/.github/workflows/canary.yaml @@ -2,7 +2,7 @@ name: Canary Release on: workflow_run: workflows: - - CI + - PullRequest types: - completed jobs: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f460956ec..a08cca8d95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ name: CI -on: [push, pull_request] +on: workflow_call jobs: save-github-event: name: "Save `github.event` as an artifact to use in subsequent 'workflow_run' actions" @@ -183,67 +183,6 @@ jobs: - name: Run Tests run: npm run testonly - benchmark: - name: Run benchmark - runs-on: ubuntu-latest - if: github.event_name == 'pull_request' - steps: - - name: Checkout repo - uses: actions/checkout@v2 - with: - persist-credentials: false - - - name: Deepen cloned repo - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - run: 'git fetch --depth=1 origin $BASE_SHA:refs/tags/BASE' - - - name: Setup Node.js - uses: actions/setup-node@v2 - with: - cache: npm - node-version-file: '.node-version' - - - name: Install Dependencies - run: npm ci --ignore-scripts - - - name: Run Benchmark - run: 'npm run benchmark -- --revs HEAD BASE' - - diff-npm-package: - name: Diff content of NPM package - runs-on: ubuntu-latest - if: github.event_name == 'pull_request' - steps: - - name: Checkout repo - uses: actions/checkout@v2 - with: - persist-credentials: false - - - name: Deepen cloned repo - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - run: 'git fetch --depth=1 origin $BASE_SHA:refs/tags/BASE' - - - name: Setup Node.js - uses: actions/setup-node@v2 - with: - cache: npm - node-version-file: '.node-version' - - - name: Install Dependencies - run: npm ci --ignore-scripts - - - name: Generate report - run: 'node resources/diff-npm-package.js BASE HEAD' - - - name: Upload generated report - uses: actions/upload-artifact@v2 - with: - name: npm-dist-diff.html - path: ./npm-dist-diff.html - if-no-files-found: ignore - build-npm-dist: name: Build 'npmDist' artifact runs-on: ubuntu-latest diff --git a/.github/workflows/deploy-artifact-as-branch.yml b/.github/workflows/deploy-artifact-as-branch.yml index 1e7f994233..586d2dc0e1 100644 --- a/.github/workflows/deploy-artifact-as-branch.yml +++ b/.github/workflows/deploy-artifact-as-branch.yml @@ -26,12 +26,9 @@ jobs: - name: Remove existing files first run: git rm -r . - - name: Download artifact into cloned branch - run: gh run download "$WORKFLOW_ID" -n "$ARTIFACT_NAME" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - WORKFLOW_ID: ${{ inputs.workflow_id }} - ARTIFACT_NAME: ${{ inputs.artifact_name }} + - uses: actions/download-artifact@v2 + with: + name: ${{ inputs.artifact_name }} - name: Publish target branch run: | diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000000..93b17eddc0 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,64 @@ +name: PullRequest +on: pull_request +jobs: + ci: + uses: ./.github/workflows/ci.yml + + benchmark: + name: Run benchmark + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + persist-credentials: false + + - name: Deepen cloned repo + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: 'git fetch --depth=1 origin $BASE_SHA:refs/tags/BASE' + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + cache: npm + node-version-file: '.node-version' + + - name: Install Dependencies + run: npm ci --ignore-scripts + + - name: Run Benchmark + run: 'npm run benchmark -- --revs HEAD BASE' + + diff-npm-package: + name: Diff content of NPM package + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + persist-credentials: false + + - name: Deepen cloned repo + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: 'git fetch --depth=1 origin $BASE_SHA:refs/tags/BASE' + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + cache: npm + node-version-file: '.node-version' + + - name: Install Dependencies + run: npm ci --ignore-scripts + + - name: Generate report + run: 'node resources/diff-npm-package.js BASE HEAD' + + - name: Upload generated report + uses: actions/upload-artifact@v2 + with: + name: npm-dist-diff.html + path: ./npm-dist-diff.html + if-no-files-found: ignore diff --git a/.github/workflows/cd.yml b/.github/workflows/push.yml similarity index 63% rename from .github/workflows/cd.yml rename to .github/workflows/push.yml index a58a771b80..1f82a51e69 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/push.yml @@ -1,29 +1,26 @@ -name: CD -on: - workflow_run: - workflows: - - CI - types: - - completed - branches: - - main +name: Push +on: push jobs: + ci: + uses: ./.github/workflows/ci.yml deploy-to-npm-branch: name: Deploy to `npm` branch - if: github.event.workflow_run.event == 'push' + needs: ci + if: github.ref == 'refs/heads/main' uses: ./.github/workflows/deploy-artifact-as-branch.yml with: - workflow_id: ${{github.event.workflow_run.id}} + workflow_id: ${{github.run_id}} artifact_name: npmDist target_branch: npm commit_message: "Deploy ${{github.event.workflow_run.head_sha}} to 'npm' branch" deploy-to-deno-branch: name: Deploy to `deno` branch - if: github.event.workflow_run.event == 'push' + needs: ci + if: github.ref == 'refs/heads/main' uses: ./.github/workflows/deploy-artifact-as-branch.yml with: - workflow_id: ${{github.event.workflow_run.id}} + workflow_id: ${{github.run_id}} artifact_name: denoDist target_branch: deno commit_message: "Deploy ${{github.event.workflow_run.head_sha}} to 'deno' branch"