Skip to content

Commit

Permalink
GitHub Actions: add install action (#5196)
Browse files Browse the repository at this point in the history
* GitHub Actions: add install action
to reduce duplication

* debug, temp

* expect strings
add warnings

* minor, consistency

Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
  • Loading branch information
mrienstra and delucis authored Oct 28, 2022
1 parent b6a478f commit d7b27a1
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 145 deletions.
49 changes: 49 additions & 0 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 6 additions & 13 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,18 @@ 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:
persist-credentials: false
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
Expand All @@ -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
Expand All @@ -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') }}
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 12 additions & 49 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions .github/workflows/snapshot-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d7b27a1

Please sign in to comment.