Private GitHub Dependencies in React Projects
Include Private GitHub Project as a Dependency
Some of our custom React projects depend on each other. For example, customer-portal depends on react-utility. The way we accomplish this is by pointing the dependency at the repository in GitHub. In the dependencies section of the package.json file, use a GitHub URL instead of a version number.
"dependencies": {
"@fullcount/react": "github:FullCount-Development/react-utility"
}
The package lock should use an ssh URL pointed at the latest commit of the repository.
"node_modules/@fullcount/react": {
"version": "1.14.0",
"resolved": "git+ssh://git@github.com/FullCount-Development/react-utility.git#f1e231c2857868aa20e956fbb0c66bac69039630",
"peerDependencies": {
"@mui/material": "^7.1.0",
"date-fns": "^4.1.0",
"msw": "^2.8.2",
"react": "^18.0.0",
"react-dom": "^18.0.0"
}
},
GitHub Actions
Dependency Project
For GitHub Actions to be able to use another repository, an SSH key must be shared between the two repositories.
If the repository being included as a dependency does not already have a Deploy Key in GitHub under Settings -> Deploy Keys, create a new one using the following steps.
ssh-keygen -C "git@github.com:FullCount-Development/{repo-name}.git"
This will be the key that other projects use to consume this project as a dependency.
Adding the private key as a secret to GitHub
Dependent projects will have to provide the private key during the build process. We store these private keys at the account level in GitHub.
Dependent Project
When consuming another project as a dependency, you will need the SSH private key. These keys are stored at the account level. If the key does not yet exist, follow steps
- uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: |
${{ secrets.REACT_UTILITY_SSH_KEY }}
${{ secrets.REACT_COMPONENTS_SSH_KEY }}
${{ secrets.{REPO_NAME}_SSH_KEY }}
Relevant Documentation