Skip to content

Commit

Permalink
Merge pull request #21 from seamapi/feat-workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb authored Jan 18, 2024
2 parents 54288fb + eea5244 commit 09efab3
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: Setup
description: Setup Node.js and install dependencies.

inputs:
node_auth_token:
description: The Node.js auth token.
required: true
node_version:
description: The Node.js version.
required: false
default: "20"
registry_url:
description: The Node.js package registry URL.
required: false
default: https://npm.pkg.github.com
install_dependencies:
description: Install dependencies.
required: false
default: "true"

runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
if: inputs.install_dependencies == 'true'
with:
cache: npm
node-version: ${{ inputs.node_version }}
registry-url: ${{ inputs.registry_url }}
- name: Setup Node.js without cache
uses: actions/setup-node@v3
if: inputs.install_dependencies == 'false'
with:
node-version: ${{ inputs.node_version }}
registry-url: ${{ inputs.registry_url }}
- name: Install dependencies
if: inputs.install_dependencies == 'true'
shell: bash
run: npm ci --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ inputs.node_auth_token }}
- name: Rebuild Node.js modules
shell: bash
run: npm rebuild
- name: Run postinstall script
shell: bash
run: npm run postinstall --if-present
- name: Run prepare script
shell: bash
run: npm run prepare --if-present
- name: Next.js cache
uses: actions/cache@v3
with:
path: |
~/.npm
${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Build NSM
if: inputs.install_dependencies == 'true'
shell: bash
run: npm run build:nsm
156 changes: 156 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
name: Check

on:
push:
branches:
- "**"

jobs:
test:
name: Test (Node.js v${{ matrix.node }} on ${{ matrix.os_name }})
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
node:
- "18"
- "20"
include:
- os: ubuntu-latest
os_name: Linux
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/setup
with:
node_version: ${{ matrix.node }}
node_auth_token: ${{ secrets.GH_TOKEN }}
- name: Test
run: npm test
lint:
name: Lint (Node.js v${{ matrix.node }})
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
node:
- "18"
- "20"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/setup
with:
node_version: ${{ matrix.node }}
node_auth_token: ${{ secrets.GH_TOKEN }}
- name: Lint
run: npm run lint
build:
name: Build
uses: ./.github/workflows/_build.yml
secrets:
node_auth_token: ${{ secrets.GH_TOKEN }}
install:
name: Install (Node.js v${{ matrix.node }} on ${{ matrix.os_name }})
runs-on: ${{ matrix.os }}
timeout-minutes: 30
needs: build
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
node:
- "18"
- "20"
include:
- os: ubuntu-latest
os_name: Linux
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.artifact_name }}
path: .
- name: Find packages
uses: tj-actions/glob@v16
id: packages
with:
files: "*.tgz"
- name: Create package.json
uses: DamianReeves/[email protected]
with:
write-mode: overwrite
path: package.json
contents: |
{"type":"module"}
- name: Create index.js
uses: DamianReeves/[email protected]
with:
write-mode: overwrite
path: index.js
contents: |
import '@seamapi/fake-template'
- name: Install
run: npm install --ignore-scripts --save ${{ steps.packages.outputs.paths }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Rebuild Node.js modules
shell: bash
run: npm rebuild
- name: Run postinstall script
shell: bash
run: npm run postinstall --if-present
- name: Run prepare script
shell: bash
run: npm run prepare --if-present
- name: Run
run: node index.js
typecheck:
name: Typecheck (Node.js v${{ matrix.node }})
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
node:
- "18"
- "20"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/setup
with:
node_version: ${{ matrix.node }}
node_auth_token: ${{ secrets.GH_TOKEN }}
- name: Check types
run: npm run typecheck
dependencies:
name: Dependencies
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/setup
with:
node_auth_token: ${{ secrets.GH_TOKEN }}
- name: Check for dependencies
run: |
if [[ "$(jq -j .dependencies < package.json)" != "null" ]]; then
echo "No direct dependencies allowed, only devDependencies"
exit 1
fi

0 comments on commit 09efab3

Please sign in to comment.