Skip to content

Commit f95b992

Browse files
authored
feat: add mono repo bumping functionality (#17)
1 parent 348e41c commit f95b992

File tree

15 files changed

+54871
-20730
lines changed

15 files changed

+54871
-20730
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 98 deletions
This file was deleted.

README.md

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Organization Projects' Dependency Manager
2-
GitHub Action that handles automated update of dependencies in package.json between projects from the same GitHub organization. You run this workflow after npm package release. It searches for libraries in your GitHub organization that depend on this package and bump version through a PR flow.
2+
GitHub Action that handles automated update of dependencies in package.json between projects from the same GitHub organization. You run this workflow after npm package release. It searches for libraries in your GitHub organization that depend on the released packages and creates pull requests with updated dependencies.
33

44
While updating multiple repositories, if there are issues with one of them, the action doesn't fail but continues bumping deps in next repo from the list.
55

@@ -28,15 +28,17 @@ You cannot apply monorepo everywhere, sometimes it doesn't make sense, and you s
2828

2929
tl;dr To find dependent projects, GitHub Search is utilized.
3030

31-
Before you run this action, I suggest you first use manually the search query used by this action. Go to https://github.com and in search box paste `"@myorg/test" user:myorg in:file filename:package.json` (with proper names of course). Identify repositories that have your package in dependencies, but you do not want to automatically update it. Add it to the list of ignored repositories
31+
Before you run this action, I suggest you first use manually the search query used by this action. Go to https://github.com and in search box paste `"@myorg/test" user:myorg path:package.json` (with proper names of course). Identify repositories that have your package in dependencies, but you do not want to automatically update it. Add it to the list of ignored repositories
3232

33-
1. You run this action in package `@myorg/test`
34-
1. After releasing `@myorg/test`, you want latest version of the package to be bumped in other packages in your organization/user called `myorg`
35-
1. The following search is performed `"@myorg/test" user:myorg in:file filename:package.json`
36-
1. Search is not perfect, quotations from `"@myorg/test"` are ignored and result can also contain repositories that have only `@myorg/test-sdk` as dependency
37-
1. All found repositories are cloned (except of `@myorg/test`)
38-
1. Action verifies if you really have `@myorg/test` in dependencies or devDependencies
39-
1. Now the rest, bumping + pushing + creating a pull request
33+
1. You run this action in some repository after releasing a package, let's say `test-packages` in organization `myorg`.
34+
1. If search is set to false (default), only the package.json from the root or from the provided path is processed. If search is set to true, all package.json files are searched using `repo:myorg/test-packages in:file filename:package.json` query and the following processing steps are applied for each of them:
35+
1. The package name and version are read from the package.json file in which the action is running, let's say `@myorg/test` with version `1.0.1`
36+
1. The following search is performed `"@myorg/test" user:myorg in:file filename:package.json` (GitHub still uses the Legacy API for search, so `path:` doesn't work, we need to use `filename:` instead)
37+
1. Search is not perfect, quotations from `"@myorg/test"` are ignored and result can also contain repositories that have only `@myorg/test-sdk` as dependency
38+
1. All found repositories are cloned (except of `@myorg/test`)
39+
1. Action verifies if you really have `@myorg/test` in dependencies or devDependencies
40+
1. Action checks the package.json to see the package manager used (npm, yarn, pnpm or bun) and runs proper install command.
41+
1. Now the rest, bumping + pushing + creating a pull request
4042

4143
Approach with using GitHub search has only one disadvantage, bumping will not work in forks, as forks do not show up in search results. It is still better than cloning all repositories from your organization.
4244

@@ -46,21 +48,43 @@ I provided only unit tests for essential utils. There are no integration tests a
4648

4749
## Action Flow
4850

49-
<img src="diagram.png" alt="flow diagram" width="20%">
51+
```mermaid
52+
graph TD
53+
subgraph Dependency Management
54+
A{Search enabled?}
55+
A -- No --> B[Pick name and version from root package.json]
56+
A -- Yes --> C[Search for all package.json files in repo and read name + version for each]
57+
C --> D[Get list of repos from GitHub search that have dependency in their package.json]
58+
B --> D
59+
60+
subgraph Repo Processing Loop
61+
D --> E[For each repo: Clone if not ignored and create new branch]
62+
E --> F[Verify dependency type dependency or devDependency]
63+
F --> G[Detect and choose package manager from: `npm, yarn, pnpm, bun`]
64+
G --> H[Bump version locally]
65+
H --> I[Push changes and open PR]
66+
I --> E
67+
end
68+
end
69+
I --> J[Autoapprove and Automerge PR]
70+
71+
```
5072

5173
## Configuration
5274

5375
Name | Description | Required | Default
5476
--|------|--|--
5577
github_token | Token to use GitHub API. It must have "repo" scopes so it can push to repos. It cannot be the default GitHub Actions token GITHUB_TOKEN. GitHub Action token's permissions are limited to the repository that contains your workflows. Provide token of the user that has rights to push to the repos that this action is suppose to update. | true | -
56-
packagejson_path | Path to package.json file if not located in the root of the project. Provide just the path without file name. In the format: `./nested/location`. | false | `./`
78+
packagejson_path | Paths to package.json file if not located in the root of the project. Provide just the paths without file name. In the format: `./nested/location`. You can provide single or multiple paths separated by commas. | false | `./`
5779
committer_username | The username (not display name) of the committer will be used to commit changes in the workflow file in a specific repository. In the format `web-flow`. | false | `web-flow`
5880
committer_email | The committer's email that will be used in the commit of changes in the workflow file in a specific repository. In the format `[email protected]`.| false | `[email protected]`
5981
commit_message_prod | It is used as a commit message when bumping dependency from "dependencies" section in package.json. In case dependency is located in both dependencies and devDependencies of dependant, then prod commit message is used. It is also used as a title of the pull request that is created by this action. | false | `fix: update ${dependencyName} to ${dependencyVersion} version`
6082
commit_message_dev | It is used as a commit message when bumping dependency from "devDependencies" section in package.json. It is also used as a title of the pull request that is created by this action. | false | `chore: update ${dependencyName} to ${dependencyVersion} version`
6183
repos_to_ignore | Comma-separated list of repositories that should not get updates from this action. Action already ignores the repo in which the action is triggered so you do not need to add it explicitly. In the format `repo1,repo2`. | false | -
6284
base_branch | Name of the base branch, where changes in package.json must be applied. It is used in PR creation. Branch where changes are introduced is cut from this base branch. If not provided, default branch is used. In the format: `next-major`. | false | -
6385
custom_id | This custom_id is added as a unique identifier value to the PR created by the bot so the bot can later recognize it as created by the bot, so it updates existing PR instead creating new one. If custom_id is not specified, action assumes that you still want bot to create multiple PRs in one repo, with multiple updates. Once you add the custom_id, you enable flow with active one PR per repo | false | -
86+
search | In case you have multiple packages.json files in repository and you want to update by searching for all of them. This is useful for monorepos. **Note: Enabling `search` overrides the list of paths provided.** | false | `false` (only root package.json is updated)
87+
ignore_paths | Comma-separated list of paths to **directories** to ignore when searching for package.json files if `search` is set to true. In the format: `./path/to/ignore,./another/path/to/ignore`. | false | -
6488

6589
## Example
6690

@@ -95,6 +119,31 @@ jobs:
95119
commit_message_dev: "chore: update internal development dependencies"
96120
```
97121
122+
### Multiple package.json files
123+
124+
In case you have multiple package.json files in your repository and you want to update them all, you can provide comma-separated list of paths to `packagejson_path` input.
125+
126+
```yml
127+
- name: Bumping
128+
uses: derberg/npm-dependency-manager-for-your-github-org@v5
129+
with:
130+
github_token: ${{ secrets.CUSTOM_TOKEN }}
131+
packagejson_path: ./path/one,./path/two,./path/three
132+
```
133+
134+
### Searching for package.json files
135+
136+
In case you have multiple package.json files in your repository and you want to update by searching for all of them, enable `search` input. You can specify ignore paths to exclude certain directories from the search. This is useful for monorepos. Note: Enabling `search` overrides the list of paths provided.
137+
138+
```yml
139+
- name: Bumping
140+
uses: derberg/npm-dependency-manager-for-your-github-org@v5
141+
with:
142+
github_token: ${{ secrets.CUSTOM_TOKEN }}
143+
search: true
144+
ignore_paths: ./path/to/ignore,./another/path/to/ignore
145+
```
146+
98147
## Development
99148

100149
```bash
@@ -104,6 +153,11 @@ jobs:
104153
GITHUB_TOKEN=token PACKAGE_JSON_LOC=test GITHUB_REPOSITORY="lukasz-lab/.github" npm start
105154
```
106155

156+
```bash
157+
# LOCAL_REPO_PATH=../test is the path to be appended to all the searched package.json files in case you want to test multiple package.json files in one repo
158+
GITHUB_TOKEN=token GITHUB_REPOSITORY="lukasz-lab/.github" LOCAL_REPO_PATH=../test SEARCH=true npm start
159+
```
160+
107161
## Debug
108162

109163
In case something ain't right, the action doesn't work as expected, enable debugging. Add to **Secrets** of the repository a secret called `ACTIONS_STEP_DEBUG` with value `true`. Now, once you run the action again, there will be additional logs visible that start with `DEBUG: `.

action.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ inputs:
3737
required: false
3838
packagejson_path:
3939
description: >
40-
Path to package.json file if not located in the root of the project. Provide just the path without file name. In the format: `./nested/location`.
40+
Paths to package.json file if not located in the root of the project. Provide just the paths without file name. In the format: `./nested/location` or as a comma-separated list for multiple paths `./path1,./path2`.
4141
default: ./
4242
required: false
4343
repos_to_ignore:
@@ -51,6 +51,16 @@ inputs:
5151
Name of the base branch, where changes in package.json must be applied. It is used in PR creation. If not provided, default branch is used
5252
In the format: `next-major`.
5353
required: false
54+
search:
55+
description: >
56+
Whether to search for multiple package.json files in the repository. Useful for monorepos. Note: Enabling `search` overrides the list of paths provided.
57+
required: false
58+
default: "false"
59+
ignore_paths:
60+
description: >
61+
Comma-separated list of paths/directories that should be ignored when searching for package.json files. Only used if search input is set to true.
62+
In the format: `./path/to/ignore,./another/path/to/ignore`.
63+
required: false
5464
runs:
5565
using: node16
5666
main: dist/index.js

0 commit comments

Comments
 (0)