Skip to content

Commit a828cd9

Browse files
committed
feat: Update README expt. flags, CI builds guide
1 parent 6d1fc69 commit a828cd9

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

README.md

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# functions-differ
22

33
[![Build and test](https://github.com/haroldadmin/functions-differ/actions/workflows/build-test.yml/badge.svg)](https://github.com/haroldadmin/functions-differ/actions/workflows/build-test.yml)
4+
[![npm](https://img.shields.io/npm/dm/functions-differ)](https://www.npmjs.com/package/functions-differ)
5+
[![npm](https://img.shields.io/npm/v/functions-differ)](https://www.npmjs.com/package/functions-differ)
46

57
A tool to selectively deploy only the Firebase Functions that changed.
68

79
[functions-differ](https://www.npmjs.com/package/functions-differ) takes a list of Firebase Functions from your repository and returns a list of functions that changed since its last invocation.
810
This helps you selectively deploy only the functions that changed, thus saving time during re-deployments.
911

10-
It detects any changes to a function by bundling it into a single minified file, and calculating a hash for it. This works for changes in the function's code, change in its installed dependencies, or any other local imports.
12+
It detects any changes to a function by bundling it into a single minified file, and calculating a hash for it. This works for changes in the function's code, changes in its installed dependencies, or any other local imports.
1113

1214
## Usage
1315

@@ -23,6 +25,8 @@ my-firebase-project
2325

2426
- Specify your function names and their paths in `.differspec.json`:
2527

28+
> This step is optional if you use the experimental `--discover` flag, which lets functions-differ discover the exported Cloud Functions from your project automatically.
29+
2630
```json
2731
{
2832
"functions": {
@@ -52,17 +56,17 @@ The default output is suitable for passing to `firebase deploy --only` command.
5256

5357
`functions-differ` supports the following options:
5458

55-
| Name | Alias | Description | Default |
56-
| ------------- | ----- | ------------------------------------------------------------------------------------------------------------ | --------------------------------------- |
57-
| dir | d | The directory containing `.differspec.json` file | (current working directory) |
58-
| write | w | Write output to `.differspec.json` file or not | true |
59-
| verbose | v | Output verbose logs | false |
60-
| prefix | | Prefix for each function name output | `functions:` |
61-
| sep | | Separator for each output function | `,` |
62-
| bundlerConfig | | Path to the bundler config file which would be passed to esbuild | |
63-
| concurrency | | Number to control the concurrency of the bundling process. Useful in CI/CD flows with limited memory | Number of functions in .differspec.json |
64-
| discover | | Flag indicating whether to use automatic function path discovery | false |
65-
| indexFilePath | | Location of the index.ts file which exports all the functions. Optional. Only used if used with `--discover` | `src/index.ts` |
59+
| Name | Alias | Description | Default |
60+
| ------------- | ----- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |
61+
| dir | d | The directory containing `.differspec.json` file | (current working directory) |
62+
| write | w | Write output to `.differspec.json` file or not | true |
63+
| verbose | v | Output verbose logs | false |
64+
| prefix | | Prefix for each function name output | `functions:` |
65+
| sep | | Separator for each output function | `,` |
66+
| bundlerConfig | | Path to the bundler config file which would be passed to esbuild | |
67+
| concurrency | | Number to control the concurrency of the bundling process. Useful in CI/CD flows with limited memory | Number of functions in .differspec.json |
68+
| discover | | (**Experimental**) Flag indicating whether to use automatic function path discovery | false |
69+
| indexFilePath | | (**Experimental**) Location of the index.ts file which exports all the functions. Optional. Only used if used with `--discover` | `src/index.ts` |
6670

6771
## .differspec.json
6872

@@ -86,3 +90,27 @@ Please discuss bugs, feature requests, and help in Github Issues. Pull requests
8690
Install the package with `npm`:
8791

8892
`npm install -g functions-differ`
93+
94+
## Notes
95+
96+
### Automatic Functions Discovery (Experimental)
97+
98+
`functions-differ` has experimental support for discovering Cloud Functions exported from your project automatically. This lets you skip defining function paths in your `.differspec.json` file manually.
99+
100+
It does this by using the TypeScript AST on exports from your project's root `index.ts` file. It makes the following assumptions about your codebase:
101+
102+
1. The `src/index.ts` file must contain all exported Cloud Functions from your project, and no other exports.
103+
2. Every Cloud Function is defined in a separate file. E.g.: `src/auth/login/index.ts`, `src/auth/register/index.ts`, etc.
104+
105+
If you use automatic functions discovery in your project, make sure the above assumptions hold true.
106+
107+
### Integration with CI/CD
108+
109+
I built `functions-differ` to help reduce the average deployment time of Cloud Functions in a project, but does not offer native support for CI builds.
110+
111+
Files generated during CI builds are usually ephemeral. They are lost once the CI build completes. If you plan to run `functions-differ` in your CI workflow, you need to backup the `.differspec.json` generated by the previous build, and restore it for the next built.
112+
113+
Here are some ways to do that for GitHub Actions:
114+
115+
1. Use [caching](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows) between CI runs for the `.differspec.json` file.
116+
2. Read/store the contents of the `.differspec.json` file in GitHub secrets in each CI run using the `gh` CLI available to every job.

0 commit comments

Comments
 (0)