Skip to content

Commit

Permalink
Add test CI workflow and caching (orcasound#77)
Browse files Browse the repository at this point in the history
* Add test CI workflow and caching

* Remove cache-hit skip for setup-node

* Move re-used code into separate composite actions

* Fix errors
  • Loading branch information
paulcretu authored Mar 13, 2022
1 parent a78f81a commit f4bf9de
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 28 deletions.
21 changes: 21 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Build'
description: 'Builds project'
runs:
using: 'composite'
steps:
# Based on https://nextjs.org/docs/messages/no-cache#github-actions
- uses: actions/cache@v2
id: cache-build
with:
path: |
~/.npm
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Build project
if: steps.cache-build.outputs.cache-hit != 'true'
run: npm run build
shell: bash
14 changes: 14 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Setup'
description: 'Setup node and dependencies'
runs:
using: 'composite'
steps:
- name: Setup node
id: setup-node
uses: actions/setup-node@v2
with:
node-version-file: '.node-version'
cache: 'npm'
- name: Install dependencies
run: npm ci
shell: bash
47 changes: 19 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,36 @@ on:
branches: [main]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- uses: ./.github/actions/build
test:
name: Test
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- uses: ./.github/actions/build
- name: Run tests
run: npm run test
format:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v2
with:
node-version-file: '.node-version'
cache: 'npm'
- name: Install dependencies
run: npm ci
- uses: ./.github/actions/setup
- name: Run prettier
run: npm run format:ci
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v2
with:
node-version-file: '.node-version'
cache: 'npm'
- name: Install dependencies
run: npm ci
- uses: ./.github/actions/setup
- name: Run eslint
run: npm run lint:ci
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v2
with:
node-version-file: '.node-version'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build --if-present
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"test": "echo 'No tests configured'",
"lint": "next lint",
"lint:fix": "next lint --fix",
"lint:ci": "npm run lint -- --max-warnings 0",
Expand Down

0 comments on commit f4bf9de

Please sign in to comment.