Skip to content

Latest commit

 

History

History
102 lines (81 loc) · 2.11 KB

README.md

File metadata and controls

102 lines (81 loc) · 2.11 KB

Javascript Command Github Action

This is a simple action to allow you to run any command defined in your package.json e.g. yarn test or npm test. This command will install packages if that has not been done first, then run the supplied command.

Currently uses node:16.13.1-alpine3.15 docker container.

Examples

Test - Create React App

If you are using the default create react app, ensure that you pass in the flag --watchAll=false so that jest doesn't enter interactive mode, otherwise the action will never finish.

on: [pull_request]

jobs:
  tests:
    name: run tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: Adzz/[email protected]
        with:
          command: test --watchAll=false

This will default to using yarn and the test command specified in your package.json. Alternatively you can define a specific script there:

 "scripts": {
    ...
    "test:ci": "react-scripts test --watchAll=false",
  },

Then do this:

on: [pull_request]

jobs:
  tests:
    name: run tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: Adzz/[email protected]
        with:
          command: test:ci

Using NPM instead of yarn

on: [pull_request]

jobs:
  tests:
    name: run tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: Adzz/[email protected]
        with:
          package-manager: npm
          command: test:ci

Lint then test

In the package.json

 "scripts": {
    ...
    "test:ci": "react-scripts test --watchAll=false",
    "eslint": "eslint . --ext .js --ext .jsx --ext .gql --ext .graphql",
  },
on: [pull_request]

jobs:
  eslint:
    name: run linter
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: Adzz/[email protected]
        with:
          command: eslint
  tests:
    name: run tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: Adzz/[email protected]
        with:
          command: test:ci