Deploying to Multiple GitHub Repositories
The approach we suggest is to have a dedicated CircleCI build that pushes the configuration to a list of repositories by leveraging the GitHub API.
The repository this CircleCI project is built on would contain:
- The separate configuration file to be pushed to the other repositories (
global-ci.ymlin this example) - A
config.ymlthat defines the build to push the above configuration file - A file containing the list of repositories in the form “user/repository” or “org/repository” (
satellites.txtin this example)
You would also need to add an environment variable containing a GitHub API token with appropriate permissions/scopes.
Config Example
The config.yml would be:
version: 2.1
jobs:
deploy-config:
docker:
- image: circleci/python
steps:
- checkout
- run:
name: Test
command: |
echo GLOBAL_64=$(base64 -w 0 global-ci.yml) >> $BASH_ENV
while IFS= read -r repo
do
echo BLOB_SHA=$(curl --location --request GET "https://api.github.com/repos/$repo/contents/.circleci/config.yml" --header "Authorization: token ${GH_TOKEN}" --header "Accept: application/vnd.github.v3+json"|jq -r .sha) >> $BASH_ENV
source $BASH_ENV
curl --location --request PUT "https://api.github.com/repos/$repo/contents/.circleci/config.yml" --header "Authorization: token ${GH_TOKEN}" --header "Accept: application/vnd.github.v3+json" --data-raw "{\"message\":\"Global config update\", \"content\":\"$GLOBAL_64\", \"sha\":\"${BLOB_SHA}\"}"
done < "satellites.txt"
workflows:
main:
jobs:
- deploy-config
Storing Config in a Centralized Repository
It is also possible to store config in a separate repository to the code being checked out.
This can be particularly useful for multiple repos that want to share a given config.
To make use of this feature, users will need to be using the GitHub App integration, or the hybrid integration.
When creating a new pipeline definition, select the relevant repository for the config source, as well as the path to the relevant config file for that repository.
You can then create a trigger based on this pipeline definition, which will then make use of the defined config file when running any pipelines.
Comments
Article is closed for comments.