banner
Zach

Hi,Ztar

Have a good day!
github

Automated Workflow Repository Synchronization

Recently, I read an article by innei, which was very inspiring to me. It was about automatically building projects across repositories and deploying them to servers.

I used Vercel to build innei's Shiro. Since there is a closed-source version now, there is a major pain point that the repository cannot be forked, which makes it difficult to sync commits conveniently. I can only fetch and push from the local repository. I had considered using GitHub actions for automation, but it always failed when I tried it.

Later, I manually synchronized it myself, but after reading the article, I asked GPT and understood what it was all about.

Process#

  1. Check if there are any changes in the source code repository.
  2. Perform scheduled operations.
  3. If there are any changes, perform automatic rebase and push operations.

image

Reference Configuration (Written by GPT)#

name: Sync with upstream repo

on:
  schedule:
    - cron: '0 */6 * * *' # 6 hours
  workflow_dispatch:

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2
        with:
          repository: 'Sync-Repo'
          token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          fetch-depth: 0

      - name: Sync with upstream
        run: |
          git config user.name 'Username'
          git config user.email 'Useremail'
          git remote add upstream 'https://github.com/username/source-repo'
          git fetch upstream
          git checkout main
          git rebase upstream/main
          git push origin main -f

Note: You need to add a secret named PERSONAL_ACCESS_TOKEN to this repository.

Access Permission Token#

How do you obtain a token with access to private repositories?

First, go to Settings -> Developer settings -> Personal access tokens (classic) -> Generate new token (classic).

image

Make sure to select repo, I'm not sure about workflow.

Then, go to the repository you want to sync.

image

Add the token.

This article is synchronized and updated to xLog by Mix Space.
The original link is https://www.ssstttar.com/posts/programming/auto-sync-repo


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.