From d7b27a17e3fccb7eb94a6dccf68c32bce9ecd665 Mon Sep 17 00:00:00 2001 From: Michael Rienstra Date: Fri, 28 Oct 2022 09:40:03 -0700 Subject: [PATCH] GitHub Actions: add install action (#5196) * GitHub Actions: add install action to reduce duplication * debug, temp * expect strings add warnings * minor, consistency Co-authored-by: Chris Swithinbank --- .github/actions/install/action.yml | 49 +++++++++++++++++++++ .github/workflows/benchmark.yml | 19 +++----- .github/workflows/check.yml | 13 +----- .github/workflows/ci.yml | 61 +++++--------------------- .github/workflows/format.yml | 11 +---- .github/workflows/main.yml | 13 +----- .github/workflows/nightly.yml | 23 +++------- .github/workflows/release.yml | 13 +----- .github/workflows/scripts.yml | 13 +----- .github/workflows/snapshot-release.yml | 14 +----- 10 files changed, 84 insertions(+), 145 deletions(-) create mode 100644 .github/actions/install/action.yml diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml new file mode 100644 index 000000000..34b1158ea --- /dev/null +++ b/.github/actions/install/action.yml @@ -0,0 +1,49 @@ +name: Install Tools & Dependencies +description: Installs pnpm, JS runtime & package dependencies + +inputs: + node-version: + description: 'Node version' + required: false + default: '16' + js-runtime: + description: 'JS runtime' + required: false + default: 'node' + install-dependencies: + description: 'Install dependencies' + required: false + default: 'true' + +runs: + using: composite + steps: + - name: Check inputs.js-runtime + if: ${{ !contains(fromJson('["node", "deno"]'), inputs.js-runtime) }} + run: echo "::warning::unknown 'js-runtime' value '${{ inputs.js-runtime }}'" + shell: bash + + - name: Check inputs.install-dependencies + if: ${{ !contains(fromJson('["true", "false"]'), inputs.install-dependencies) }} + run: echo "::warning::unknown 'install-dependencies' value '${{ inputs.install-dependencies }}'" + shell: bash + + - name: Setup pnpm + uses: pnpm/action-setup@v2.2.4 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node-version }} + cache: pnpm + + - name: Use Deno + if: ${{ inputs.js-runtime == 'deno' }} + uses: denoland/setup-deno@v1 + with: + deno-version: v1.26.1 + + - name: Install dependencies + if: ${{ fromJSON(inputs.install-dependencies) }} + run: pnpm install + shell: bash diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 3e40038c9..9d7f2db26 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -22,7 +22,7 @@ jobs: MAIN-BENCH-16: ${{ steps.benchmark-main.outputs.BENCH_RESULT16 }} strategy: matrix: - node-version: [14, 16] + NODE_VERSION: [14, 16] steps: - uses: actions/checkout@v3 with: @@ -30,17 +30,10 @@ jobs: ref: ${{github.event.pull_request.head.sha}} repository: ${{github.event.pull_request.head.repo.full_name}} - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 + - name: Install Tools & Dependencies + uses: ./.github/actions/install with: - node-version: ${{ matrix.node-version }} - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install + node-version: ${{ matrix.NODE_VERSION }} - name: Build Packages run: pnpm run build @@ -50,7 +43,7 @@ jobs: run: | pnpm run --silent benchmark > ./bench-result.md result=$(awk '/requests in/' ./bench-result.md) - echo "::set-output name=BENCH_RESULT${{matrix.node-version}}::$result" + echo "::set-output name=BENCH_RESULT${{matrix.NODE_VERSION}}::$result" # main benchmark - uses: actions/checkout@v3 @@ -70,7 +63,7 @@ jobs: run: | pnpm run --silent benchmark > ./bench-result.md result=$(awk '/requests in/' ./bench-result.md) - echo "::set-output name=BENCH_RESULT${{matrix.node-version}}::$result" + echo "::set-output name=BENCH_RESULT${{matrix.NODE_VERSION}}::$result" output-benchmark: if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!bench') }} diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index b8826f538..8b2358316 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -25,17 +25,8 @@ jobs: - name: Check out repository uses: actions/checkout@v3 - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install + - name: Install Tools & Dependencies + uses: ./.github/actions/install - name: Build run: pnpm run build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b98f3bc55..f796699fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,17 +32,8 @@ jobs: - name: Check out repository uses: actions/checkout@v3 - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install + - name: Install Tools & Dependencies + uses: ./.github/actions/install - name: Status run: git status @@ -87,17 +78,10 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup node@${{ matrix.NODE_VERSION }} - uses: actions/setup-node@v3 + - name: Install Tools & Dependencies + uses: ./.github/actions/install with: node-version: ${{ matrix.NODE_VERSION }} - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install - name: Build Packages run: pnpm run build @@ -121,22 +105,11 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup node@${{ matrix.NODE_VERSION }} - uses: actions/setup-node@v3 + - name: Install Tools & Dependencies + uses: ./.github/actions/install with: node-version: ${{ matrix.NODE_VERSION }} - cache: 'pnpm' - - - name: Use Deno - uses: denoland/setup-deno@v1 - with: - deno-version: v1.26.1 - - - name: Install dependencies - run: pnpm install + js-runtime: deno - name: Build Packages run: pnpm run build @@ -160,17 +133,10 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup node@${{ matrix.NODE_VERSION }} - uses: actions/setup-node@v3 + - name: Install Tools & Dependencies + uses: ./.github/actions/install with: node-version: ${{ matrix.NODE_VERSION }} - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install - name: Build Packages run: pnpm run build @@ -192,14 +158,11 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup node@${{ matrix.NODE_VERSION }} - uses: actions/setup-node@v3 + - name: Install Tools & Dependencies + uses: ./.github/actions/install with: node-version: ${{ matrix.NODE_VERSION }} - cache: 'pnpm' + install-dependencies: false - name: Checkout docs uses: actions/checkout@v3 diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 0645326f6..4ff3ada9d 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -17,15 +17,8 @@ jobs: ref: ${{ github.head_ref }} # Needs access to push to main token: ${{ secrets.FREDKBOT_GITHUB_TOKEN }} - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - name: Install dependencies - run: pnpm install + - name: Install Tools & Dependencies + uses: ./.github/actions/install - name: Format code run: pnpm run format:ci - name: Commit changes diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 02344ecdb..e8799a751 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,17 +41,8 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install + - name: Install Tools & Dependencies + uses: ./.github/actions/install - name: Check Modified run: pnpm exec changeset status --output ./status.json diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 528abb6cd..3c074afe4 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -14,17 +14,8 @@ jobs: - name: Check out code using Git uses: actions/checkout@v3 - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install + - name: Install Tools & Dependencies + uses: ./.github/actions/install - name: Collect stats run: node scripts/stats/index.js @@ -48,14 +39,10 @@ jobs: - name: Check out code using Git uses: actions/checkout@v3 - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 + - name: Install Tools & Dependencies + uses: ./.github/actions/install with: - node-version: 16 - cache: 'pnpm' + install-dependencies: false - name: Delete the existing pnpm-lock.yaml file run: rm pnpm-lock.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e3f348c0f..9bf10fa6e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,17 +22,8 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install + - name: Install Tools & Dependencies + uses: ./.github/actions/install - name: Build Packages run: pnpm run build diff --git a/.github/workflows/scripts.yml b/.github/workflows/scripts.yml index 60cf929c7..91b7201ea 100644 --- a/.github/workflows/scripts.yml +++ b/.github/workflows/scripts.yml @@ -30,17 +30,8 @@ jobs: ref: main path: main - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install + - name: Install Tools & Dependencies + uses: ./.github/actions/install - name: Check Bundle Size uses: actions/github-script@v6 diff --git a/.github/workflows/snapshot-release.yml b/.github/workflows/snapshot-release.yml index da37c4b52..9d3d5d20b 100644 --- a/.github/workflows/snapshot-release.yml +++ b/.github/workflows/snapshot-release.yml @@ -51,18 +51,8 @@ jobs: with: ref: ${{ steps.refs.outputs.head_ref }} - - name: Setup PNPM - uses: pnpm/action-setup@v2.2.1 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - registry-url: 'https://registry.npmjs.org' - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install + - name: Install Tools & Dependencies + uses: ./.github/actions/install - name: Build Packages run: pnpm run build