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.
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@master
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
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 ยฉ 2021 Adam Zolyak [email protected] (www.tinkurlab.com)