Sample GitHub action
The following is a sample GitHub action triggered by a push to the main branch. Then pushing into a subdirectory of Cloud Manager’s Git repository. The GitHub actions must be provided with two secrets, MAIN_USER
and MAIN_PASSWORD
, to be able to connect and push to Cloud Manager’s Git repository.
name: SYNC
env:
# Username/email used to commit to Cloud Manager's Git repository
USER_NAME: <NAME>
USER_EMAIL: <EMAIL>
# Directory within the Cloud Manager Git repository
PROJECT_DIR: project-a
# Cloud Manager's Git repository
MAIN_REPOSITORY: https://$MAIN_USER:$MAIN_PASSWORD@git.cloudmanager.adobe.com/<PATH>
# The branch in Cloud Manager's Git repository to push to
MAIN_BRANCH : <BRANCH_NAME>
# Only run on a push to this branch
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout this project into a sub folder
- uses: actions/checkout@v2
with:
path: sub
# Cleanup sub project
- name: Clean project
run: |
git -C sub log --format="%an : %s" -n 1 > commit.txt
rm -rf sub/.git
rm -rf sub/.github
# Set global git configuration
- name: Set git config
run: |
git config --global credential.helper cache
git config --global user.email ${USER_EMAIL}
git config --global user.name ${USER_NAME}
# Checkout the main project
- name: Checkout main project
run:
git clone -b ${MAIN_BRANCH} ${MAIN_REPOSITORY} ${MAIN_BRANCH}
# Move sub project
- name: Move project to main project
run: |
rm -rf ${MAIN_BRANCH}/${PROJECT_DIR}
mv sub ${MAIN_BRANCH}/${PROJECT_DIR}
- name: Commit Changes
run: |
git -C ${MAIN_BRANCH} add -f ${PROJECT_DIR}
git -C ${MAIN_BRANCH} commit -F ../commit.txt
git -C ${MAIN_BRANCH} push
Using a GitHub action is flexible. Any mapping between branches of the Git repositories can be performed and any mapping of the separate Git projects into the directory layout of the main project.
The sample script uses
git add
to update the repository. The script assumes that removals are included. Depending on the default configuration of Git, it must be replaced with git add --all
.