샘플 GitHub 액션

다음은 기본 분기로 푸시하여 트리거되는 샘플 GitHub 작업입니다. 그런 다음 Cloud Manager Git 저장소의 하위 디렉터리에 푸시합니다. GitHub 작업에는 Cloud Manager의 Git 저장소에 연결하고 푸시할 수 있도록 MAIN_USER과(와) MAIN_PASSWORD의 두 가지 비밀이 제공되어야 합니다.

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

GitHub 작업 사용은 유연합니다. Git 저장소 분기 간의 모든 매핑은 물론 별도의 Git 프로젝트를 기본 프로젝트의 디렉터리 레이아웃으로 매핑할 수 있습니다.

NOTE
샘플 스크립트는 git add를 사용하여 저장소를 업데이트합니다. 이 스크립트는 제거가 포함된 것으로 가정합니다. Git의 기본 구성에 따라 git add --all(으)로 대체해야 합니다.

샘플 Jenkins 작업

다음은 Jenkins 작업 또는 이와 유사한 작업에서 사용할 수 있는 샘플 스크립트이며 다음과 같은 흐름이 있습니다.

  1. Git 저장소의 변경으로 인해 트리거됩니다.
  2. Jenkins 작업은 해당 프로젝트 또는 분기의 최신 상태를 확인합니다.
  3. 그런 다음 작업은 이 스크립트를 트리거합니다.
  4. 이 스크립트는 Cloud Manager의 Git 저장소를 체크아웃하고 프로젝트 코드를 하위 디렉터리에 커밋합니다.

Cloud Manager의 Git 저장소에 연결하고 푸시할 수 있으려면 Jenkins 작업에 두 개의 비밀 MAIN_USERMAIN_PASSWORD이(가) 제공되어야 합니다.

# Username/email used to commit to Cloud Manager's Git repository
export USER_NAME=<NAME>
export USER_EMAIL=<EMAIL>
# Directory within the Cloud Manager Git repository
export PROJECT_DIR=project-a
# Cloud Manager's Git repository
export MAIN_REPOSITORY=https://$MAIN_USER:$MAIN_PASSWORD@git.cloudmanager.adobe.com/<PATH>
# The branch in Cloud Manager's Git repository to push to
export MAIN_BRANCH=<BRANCH_NAME>

# clean up and init
rm -rf target
mkdir target

# mv project to sub folder
mkdir target/sub
for f in .* *
do
    if [ "$f" != "." -a "$f" != ".." -a "$f" != "target" ]
    then
        mv "$f" target/sub
    fi
done
cd target

# capture log and remove git info
cd sub
git log --format="%an : %s" -n 1 > ../commit.txt
rm -rf .git
rm -rf .github
cd ..

# checkout main repository
git clone -b $MAIN_BRANCH $MAIN_REPOSITORY main
cd main

# configure main repository
git config credential.helper cache
git config user.email $USER_EMAIL
git config user.name $USER_NAME

# update project in main
rm -rf $PROJECT_DIR
mv ../sub $PROJECT_DIR

# commit changes to main
git add -f $PROJECT_DIR
git commit -F ../commit.txt
git push

Jenkins 작업 사용은 유연합니다. Git 저장소 분기 간의 모든 매핑은 물론 별도의 Git 프로젝트를 기본 프로젝트의 디렉터리 레이아웃으로 매핑할 수 있습니다.

NOTE
샘플 스크립트는 git add를 사용하여 저장소를 업데이트합니다. 이 스크립트는 제거가 포함된 것으로 가정합니다. Git의 기본 구성에 따라 git add --all(으)로 대체해야 합니다.

Experience Manager