From a7332308c8cc7bae34597941cd9c8a55596217ce Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Wed, 17 Mar 2021 13:56:40 +0100 Subject: [PATCH] feat: detect install command --- README.md | 2 +- action.yml | 2 +- entrypoint.sh | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4cc1207..b226646 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ The inputs this action uses are: | `NETLIFY_DEPLOY_MESSAGE` | `false` | '' | An optional deploy message | | `build_directory` | `false` | `'build'` | The directory where your files are built | | `functions_directory` | `false` | N/A | The (optional) directory where your Netlify functions are stored | -| `install_command` | `false` | `npm i` | The (optional) command to install dependencies | +| `install_command` | `false` | Auto-detected | The (optional) command to install dependencies. Runs `yarn` when `yarn.lock` is found; `npm i` otherwise | | `build_command` | `false` | `npm run build` | The (optional) command to build static website | | `deploy_alias` | `false` | '' | (Optional) [Deployed site alias](https://cli.netlify.com/commands/deploy) | diff --git a/action.yml b/action.yml index 3a67b4f..d810805 100644 --- a/action.yml +++ b/action.yml @@ -36,7 +36,7 @@ inputs: install_command: description: 'Command to install dependencies' required: false - default: 'npm i' + default: '' build_command: description: 'Command to build static website' diff --git a/entrypoint.sh b/entrypoint.sh index c0b717c..ecd7fa6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,7 +12,15 @@ BUILD_COMMAND=$7 DEPLOY_ALIAS=$8 # Install dependencies -eval ${INSTALL_COMMAND:-"npm i"} +if [[ -n $INSTALL_COMMAND ]] +then + eval $INSTALL_COMMAND +elif [[ -f yarn.lock ]] +then + yarn +else + npm i +fi # Build project eval ${BUILD_COMMAND:-"npm run build"}