Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring an installation script #88

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,44 @@ jobs:
- uses: preactjs/compressed-size-action@v2
```

### Customizing Package Installation

By default, `compressed-size-action` will install dependencies according to your package manager:

- **npm**, without `package-lock.json`: `npm install`
- **npm**, with `package-lock.json`: `npm ci`
- **pnpm**: `pnpm install --frozen-lockfile`
- **yarn**: `yarn --frozen-lockfile`

If you need to run a different installation command, you can use a custom npm script to do so. For example, to use `npm ci` with the `--workspace` option:

```json
{
"scripts": {
"install-deps": "npm ci --workspace=packages/my-subpackage",
}
}
```

This script must be specified as the `install-script` 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: "install-deps"
```

### 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
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ inputs:
default: ${{ github.token }}
clean-script:
description: 'An npm-script that cleans/resets state between branch builds'
install-script:
description: 'The npm-script to run that installs your project'
build-script:
description: 'The npm-script to run that builds your project'
default: 'build'
Expand Down
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ async function run(octokit, context, token) {
installScript = 'npm ci';
}

let configInstallScript = getInput('install-script');
if (configInstallScript) {
installScript = `${packageManager} run ${configInstallScript}`;
}

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

configInstallScript = getInput('install-script');
if (configInstallScript) {
installScript = `${packageManager} run ${configInstallScript}`;
}

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