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

Add clean-script option #60

Merged
merged 3 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@ jobs:
+ build-script: "ci"
```

#### Clean up state between builds

For repositories or custom monorepo setups where files are modified in ways that are not reset by `npm ci && npm run build`, it may be necessary to define a custom "clean" script. This script resets any file modifications after the upstream (`target`) build ends and your PR code (`HEAD`) is checked out, but before installation of npm dependencies for `HEAD`:

```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:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
+ clean-script: "clean"
```

```jsonc
// package.json
{
"scripts": {
// example - a simple nested node_modules setup:
"postinstall": "cd packages && npm i",
// between the two builds, we need to delete the inner node_modules:
"clean": "rm -rf packages/node_modules"
}
}
```

### Customizing the list of files

`compressed-size-action` defaults to tracking the size of all JavaScript files within `dist/` directories - anywhere in your repository, not just at the root. You can change the list of files to be tracked and reported using the `pattern` and `exclude` options, both of which are [minimatch patterns](https://github.com/motemen/minimatch-cheat-sheet/blob/master/README.md):
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ inputs:
repo-token:
description: 'The GITHUB_TOKEN secret'
required: true
clean-script:
description: 'An npm-script that cleans/resets state between branch builds'
build-script:
description: 'The npm-script to run that builds your project'
default: 'build'
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ async function run(octokit, context, token) {
}
endGroup();

const cleanScript = getInput('clean-script');
if (cleanScript) {
startGroup(`[base] Cleanup via ${npm} run ${cleanScript}`);
await exec(`${npm} run ${cleanScript}`);
endGroup();
}

startGroup(`[base] Install Dependencies`);

yarnLock = await fileExists(path.resolve(cwd, 'yarn.lock'));
Expand Down