git actions으로 다른 레포지토리에 동기화하기

김민아·2023년 1월 17일
0

🔁 다른 레포, 특정 폴더에 동기화하기

LeetCode로 푼 문제를 LeetHub 크롬 확장으로 레포에 동기화하는데, 폴더를 지정할 수 없고 다른 폴더 트리 구조와 맞지 않아 다른 레포로 연결했다.

vscode로 디버깅할 때 은근 신경이 쓰여서 하나의 레포로 관리하기 위해 github actions로 같은 계정 다른 레포에 동기화 하는 방법을 찾아보았다.

원칙적으로(?) trigger per-repository라고 하는데, 의견이 분분한 것 같다. 이런 경우에서 쓰는 건 권장하지 않는 것 같다...🤦🏻‍♀️

시도

이전 vercel 배포을 참고하여 응용했다. 특히 원했던 것은 algorithm/LeetCode 폴더 경로에 push 되는 것이어서 플러그인의 target-directory를 설정해 주었다. 순서는 예전에 자세히 적어놓아서 간단하게 정리했다.

여기서 사용하는 github-action-push-to-another-repository 플러그인 문서에 예시가 아주 잘 나와있다.

시크릿 토큰 발급

  1. 개인 github 설정에서 Personal access tokens > Token을 하나 만들어 준다. repo 권한을 준다.

소스 repo

  1. output 폴더를 생성하기 하기 위해 build.sh 파일을 생성한다.
  2. 토큰을 시크릿 변수로 등록한다.
  3. GitHub Actions 활성화 & 워크플로우 생성한다.

이메일과 테스트 코드도 생략했다.

name: git push into another repo to integrate algorithms
on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    container: pandoc/latex
    steps:
      - uses: actions/checkout@v2
      - name: Install mustache (to update the date)
        run: apk add ruby && gem install mustache
      - name: creates output
        run: sh ./build.sh
      - name: Pushes to another repository
        id: push_directory
        uses: cpina/github-action-push-to-another-repository@main
        env:
          API_TOKEN_GITHUB: ${{ secrets.AUTO_LEETCODE_PUSH }}
        with:
          source-directory: 'output'
          destination-github-username: 'rmaomina'
          destination-repository-name: 'Algorithm'
          commit-message: ${{ github.event.commits[0].message }}
          target-branch: main
          target-directory: 'LeetCode'

실패

커밋 메시지 옆에 ❌를 클릭해서 action detail을 확인할 수 있다. 에러 메시지가 뜬 부분에 output 폴더가 없다고 나와있었는데, 위 쪽에 [team-repo]를 작성하지 않았던 것이다 🤦🏻‍♀️

성공

이제 LeetCode에서 문제를 풀면 LeetHub를 통해 A repo에 쌓이고 동시에 B repo 특정 폴더에 동기화가 된다. 약간의 응용이 있었다면 플러그인에서 특정 디렉토리를 선택할 수 있도록 옵션(target-directory)을 설정한 것이다.

출처

0개의 댓글