Skip to content

Commit

Permalink
chore(ci): split PR preview action and upgrade deps
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Koops <[email protected]>
  • Loading branch information
jonkoops committed Apr 22, 2024
1 parent 340cea4 commit 9574614
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 310 deletions.
61 changes: 61 additions & 0 deletions .github/actions/setup-project/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Set up and build project
inputs:
skip-build:
description: Skip the build step
required: false
default: 'false'
runs:
using: composite
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
check-latest: true

- name: Enable Corepack
shell: bash
run: corepack enable

- name: Get Yarn configuration
id: yarn-config
shell: bash
run: |
echo "cache-directory=$(yarn cache dir)" >> $GITHUB_OUTPUT
# TODO: This can be simplified to use the `cache` option of the `actions/setup-node` action when it supports Corepack.
# See: https://github.com/actions/setup-node/issues/531
- uses: actions/cache@v4
name: Setup Yarn cache
with:
# Also cache Cypress binary.
path: |
~/.cache/Cypress
${{ steps.yarn-config.outputs.cache-directory }}
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-cache-
- name: Install dependencies
shell: bash
run: yarn install --frozen-lockfile

- uses: actions/cache@v4
if: inputs.skip-build != 'true'
id: cache-build
name: Cache build
with:
path: |
packages/*/dist
packages/*/next
packages/*/deprecated
packages/*/components
packages/react-styles/css
packages/react-core/layouts
packages/react-core/helpers
key: ${{ runner.os }}-build-${{ hashFiles('yarn.lock', '**/package.json', 'packages/**', '!**/node_modules', '!**/dist') }}

- name: Run build
if: inputs.skip-build != 'true' && steps.cache-build.outputs.cache-hit != 'true'
shell: bash
run: yarn build && yarn build:umd
36 changes: 36 additions & 0 deletions .github/workflows/docs-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Preview documentation
on:
pull_request_target:
jobs:
deploy:
name: Build, test & deploy
runs-on: ubuntu-latest
env:
SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }}
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
GH_PR_TOKEN: ${{ secrets.GH_PR_TOKEN }}
GH_PR_NUM: ${{ github.event.number }}
steps:
- name: Check out project
uses: actions/checkout@v4
with:
# Checkout the merge commit so that we can access the PR's changes.
# This is nessesary because `pull_request_target` checks out the base branch.
ref: ${{ github.event.pull_request.merge_commit_sha }}

- name: Set up and build project
uses: ./.github/actions/setup-project

- name: Build documentation
run: yarn build:docs

- name: Upload documentation
if: always()
run: node .github/upload-preview.js packages/react-docs/public

- name: Run accessibility tests
run: yarn serve:docs & yarn test:a11y

- name: Upload accessibility results
if: always()
run: node .github/upload-preview.js packages/react-docs/coverage
99 changes: 99 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: CI
on:
push:
pull_request:
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out project
uses: actions/checkout@v4

- name: Set up project
uses: ./.github/actions/setup-project
with:
skip-build: true

- uses: actions/cache@v4
name: Cache files proccesed by ESLint
with:
path: .eslintcache
key: ${{ runner.os }}-eslint-cache

- name: Run linter
run: yarn lint:all

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out project
uses: actions/checkout@v4

- name: Set up and build project
uses: ./.github/actions/setup-project

unit-tests:
name: Unit tests
runs-on: ubuntu-latest
needs: build
steps:
- name: Check out project
uses: actions/checkout@v4

- name: Set up and build project
uses: ./.github/actions/setup-project

- name: Run tests
run: yarn test --maxWorkers=2

demo-app:
name: Build demo app
runs-on: ubuntu-latest
needs: build
steps:
- name: Check out project
uses: actions/checkout@v4

- name: Set up and build project
uses: ./.github/actions/setup-project

- name: Build demo app
run: yarn build:integration

- name: Upload demo app
uses: actions/upload-artifact@v4
with:
name: demo-app
path: packages/react-integration/demo-app-ts/public

integration-tests:
name: Integration tests
runs-on: ubuntu-latest
needs: demo-app
strategy:
fail-fast: false
matrix:
worker: [0, 1, 2, 3, 4]
steps:
- name: Check out project
uses: actions/checkout@v4

- name: Set up and build project
uses: ./.github/actions/setup-project

- name: Download demo app
uses: actions/download-artifact@v4
with:
name: demo-app
path: packages/react-integration/demo-app-ts/public

- name: Print environment variables
run: printenv

- name: Run Cypress tests
run: yarn serve:integration & yarn test:integration -s $(node .github/split.js)
env:
WORKER_NUM: ${{ matrix.worker }}
WORKER_COUNT: 5
Loading

0 comments on commit 9574614

Please sign in to comment.