How to keep multiple repositories in sync
In a recent Adobe Experience Manager project, there were multiple security restrictions with access, so we enabled a repository for each team to work on the project and enable every organization to manage the permissions.
Additionaly, in AEM as a Cloud Service, there is also a Cloud Manager repository that needs to be kept in sync to trigger the deployment to the managed instances.
We used a continuous integration pipeline to ensure the code repositories were in sync. Below is a diagram with the workflow that was implemented:
To make it work we enabled bitbucket pipelines, configured the repository variables and updated the content of the bitbucket-pipelines.yml file:
image: atlassian/default-image:3
definitions:
steps:
- step: &sync-remote-adobe
name: Push to Adobe Experience cloud
script:
- if [[ $ADOBE_CM_GIT_SLUG ]]; then
- git remote add adobe https://$ADOBE_CM_USERNAME:$ADOBE_CM_PASSWORD@git.cloudmanager.adobe.com/$ADOBE_CM_GIT_SLUG
- git pull adobe $BITBUCKET_BRANCH --tags
- git push adobe $BITBUCKET_BRANCH --tags
- else
- echo "Step skipped, ADOBE_CM_GIT_SLUG variable not configured"
- fi
- step: &push-bitbucket-mirror
name: Push to Bitbucket Mirror
script:
- if [[ $MIRROR_GIT_SLUG ]]; then
- git remote add mirror https://x-token-auth:$MIRROR_TOKEN@bitbucket.org/$MIRROR_GIT_SLUG
- git push mirror $BITBUCKET_BRANCH --tags
- else
- echo "Step skipped, MIRROR_GIT_SLUG variable not configured"
- fi
pipelines:
branches:
develop:
- step: *push-bitbucket-mirror
- step: *sync-remote-adobe
master:
- step: *push-bitbucket-mirror
- step: *sync-remote-adobe
Bonus: Sync repositories using github actions
If you’re looking on how to keep different repositories in sync but and the repositories are hosted on github, you can use the mirror-repository action.
Below is a template to configure it with only 2 steps:
1. Commit a file with the configuration:
.github/workflows/mirror-repo-sync.yml
on:
push:
branches:
- develop
jobs:
sync_to_mirror:
runs-on: ubuntu-20.04
steps:
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: yesolutions/mirror-action@master
with:
REMOTE: ${{ secrets.GIT_REPO }}
GIT_USERNAME: ${{ secrets.GIT_USERNAME }}
GIT_PASSWORD: ${{ secrets.GIT_PASSWORD }}