Skip to content

Commit

Permalink
[feature] Add install script inputs (#85)
Browse files Browse the repository at this point in the history
* [feature] Add install script inputs

* docs: Add docs for new `install-script` option

Co-authored-by: Alan Orozco <alanorozco@users.noreply.github.com>

* Update action.yml

---------

Co-authored-by: Ryan Christian <rchristian@ryanchristian.dev>
Co-authored-by: Alan Orozco <alanorozco@users.noreply.github.com>
Co-authored-by: Ryan Christian <33403762+rschristian@users.noreply.github.com>
  • Loading branch information
4 people committed Apr 22, 2024
1 parent f2cd878 commit f135bd3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -29,6 +29,26 @@ jobs:
- uses: preactjs/compressed-size-action@v2
```

### Customizing the Installation

By default, `compressed-size-action` will install dependencies according to which lockfiles are present, if any. However, if you need to run a different installation command, you can pass a custom script to do so. For example, to use `npm ci` with the `--workspace` option:

```diff
name: Compressed Size

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: preactjs/compressed-size-action@v2
with:
+ install-script: "npm ci --workspace=packages/my-subpackage"
```

### Customizing the Build

By default, `compressed-size-action` will try to build your PR by running the `"build"` [npm script](https://docs.npmjs.com/misc/scripts) in your `package.json`.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -11,6 +11,9 @@ inputs:
default: ${{ github.token }}
clean-script:
description: 'An npm-script that cleans/resets state between branch builds'
install-script:
required: false
description: 'Custom installation script to run to set up the dependencies in your project'
build-script:
description: 'The npm-script to run that builds your project'
default: 'build'
Expand Down
2 changes: 1 addition & 1 deletion index.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/index.js
Expand Up @@ -70,6 +70,10 @@ async function run(octokit, context, token) {
installScript = 'npm ci';
}

if (getInput('install-script')) {
installScript = getInput('install-script');
}

startGroup(`[current] Install Dependencies`);
console.log(`Installing using ${installScript}`);
await exec(installScript);
Expand Down Expand Up @@ -143,6 +147,10 @@ async function run(octokit, context, token) {
installScript = `npm ci`;
}

if (getInput('install-script')) {
installScript = getInput('install-script');
}

console.log(`Installing using ${installScript}`);
await exec(installScript);
endGroup();
Expand Down

0 comments on commit f135bd3

Please sign in to comment.