A GitHub Action that labels pull requests with the modules(s) that are impacted in a monorepo.
This GitHub Action runs when an pull_request
event webhook is fired in your GitHub repo. The action checks if any of the files in the pull request are in a module (ex. /module1/...
, /module2/...
, from the root of the monorepo). If one or more modules are found, the pull request is labeled with a label for each module repo.
Details
- Directories that beginning with a dot (ex.
/.directory/
) are ignored. - The action supports configuring a list of one or more base directories if modules are within base directories (ex.
/base_directory1/module1/
,/base_directory1/module2/
,/base_directory2/module3/
) such as within Lerna projects - The action supports configuring label prefix and label suffix for labeling.
- The action supports use on GHES instances!
Note: If you're migrating from version 2.x to 3.x, the automatic prefix π Repo: <repo>
is now optional. If you want to keep this prefix or add a different prefix, see "Adding a custom prefix or suffix to labels" below.
Example of PR that has changes in two modules:
Example of monorepo module structure:
To setup this action:
- Create a
.github/worksflows/main.yml
in your GitHub repo (more info). - Add the following code to the
main.yml
file and commit it to the repo'smaster
branch.
name: Monorepo PR Repo Labeler
on: pull_request
jobs:
labelPR:
name: Label PR With Repo(s)
runs-on: ubuntu-latest
steps:
- name: Label PRs
uses: tinkurlab/monorepo-pr-labeler-action
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_DIRS: 'directory1|directory2' # optional
with:
prefix: 'sample_prefix' # optional
suffix: 'sample_suffix' # optional
separator: ' ' # optional
- Optionally add a
BASE_DIRS
variable underenv
if modules are located within one or more base directory(ies). You can configure one (ex.base_directory1
) or more directories (ex.base_directory1|bae_directory2|...
). IfBASE_DIRS
isn't specified, the action will assume the base directories in the repo are your modules (ex.base_directory1
is a module). - Add
prefix
orsuffix
underwith
if you wish to add prefix or suffix the repo name in the label respectively. - Add
separator
underwith
if you wish to add a separator between the prefix, label, and suffix. For example, using a single space character' '
will add a space between them. By default, no separator is added.
The following configuration will look for repos within the folderA
and folderB
directories:
name: Monorepo PR Repo Labeler
on: pull_request
jobs:
labelPR:
name: Label PR With Repo(s)
runs-on: ubuntu-latest
steps:
- name: Label PRs
uses: TinkurLab/monorepo-pr-labeler-action
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_DIRS: 'folderA|folderB' # optional
The following configuration will prefix each label with π
and add a space after the prefix - ex.π Repo A
, π Repo B
, etc:
name: Monorepo PR Repo Labeler
on: pull_request
jobs:
labelPR:
name: Label PR With Repo(s)
runs-on: ubuntu-latest
steps:
- name: Label PRs
uses: tinkurlab/monorepo-pr-labeler-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
prefix: 'π' # optional
separator: ' ' # optional
You can pin the action version (ex. uses: tinkurlab/[email protected]
) to avoid issues due to breaking changes in major version updates.
Version 4.x.x changes the previous functionlity of v3.x.x which automatically added a space between the package name a prefix (if configured) or a suffix (if configured) when labeling pull requests. Starting with version 4.0.0, if a prefix or suffix is configured, an optional seperator can be configured via the separator: ' '
property. This property can be used to add a space or other seperator. If no separator
property is configured, no space or other seperator will be included in the label. It is recommended that you update your action configuration before upgrading to v4.x.x.
If you have suggestions for how this GitHub Action could be improved, or want to report a bug, open an issue! Or pull request! We'd love all and any contributions. For more, check out the Contributing Guide.
This repo is maintained by:
- Adam Zolyak @adamzolyak
- Anshul Sahni @anshulsahni
ISC Β© 2022 Adam Zolyak [email protected] (www.tinkurlab.com)