Skip to content

Commit

Permalink
ci: DRY with a composite action
Browse files Browse the repository at this point in the history
  • Loading branch information
kgilpin committed Jan 15, 2024
1 parent 5620d09 commit ee80e85
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 70 deletions.
98 changes: 28 additions & 70 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,10 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Detect Yarn cache dir
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- name: Restore Yarn packages
uses: actions/cache/restore@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Restore node_modules
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
uses: ./.github/workflows/setup-node.yml

- name: Build
run: |
yarn
yarn workspaces foreach -v -t --exclude root --exclude @appland/appmap --exclude @appland/scanner run build
- name: Test
Expand All @@ -101,37 +85,43 @@ jobs:
yarn run lint
yarn run test
test_cli:
test_chromatic:
runs-on: ubuntu-latest

if: github.event_name == 'pull_request'

needs: [yarn_install]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Detect Yarn cache dir
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- name: Restore Yarn packages
uses: actions/cache/restore@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Restore node_modules
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
uses: ./.github/workflows/setup-node.yml

- name: Build
run: |
yarn
yarn run build
yarn workspaces foreach -v -t --exclude root --exclude @appland/appmap --exclude @appland/scanner run build
- name: Test
run: |
cd packages/components
yarn run chromatic
test_cli:
runs-on: ubuntu-latest

needs: [yarn_install]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: ./.github/workflows/setup-node.yml

- name: Build
run: yarn run build

- name: Test
run: |
Expand Down Expand Up @@ -168,26 +158,10 @@ jobs:
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Detect Yarn cache dir
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- name: Restore Yarn packages
uses: actions/cache/restore@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Restore node_modules
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
uses: ./.github/workflows/setup-node.yml

- name: Build
run: |
yarn
yarn workspaces foreach -v -t --exclude root --exclude @appland/appmap --exclude @appland/components run build
- name: Test
Expand All @@ -208,26 +182,10 @@ jobs:
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Detect Yarn cache dir
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- name: Restore Yarn packages
uses: actions/cache/restore@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Restore node_modules
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
uses: ./.github/workflows/setup-node.yml

- name: Build
run: |
yarn
yarn workspaces foreach -v -t --exclude root --exclude @appland/appmap --exclude @appland/components --exclude @appland/scanner run build
- name: Test
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/setup-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Setup Node
description: Sets up Node.js and restores Yarn and node_modules cache
runs:
using: 'composite'
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Detect Yarn cache dir
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- name: Restore Yarn packages
uses: actions/cache/restore@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Restore node_modules
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
- name: Yarn install
run: yarn

0 comments on commit ee80e85

Please sign in to comment.