又一只松鼠阿~

Pursue inspiration by doing less.

014.使用Github action复制分支文件到同仓库的另一个分支

2023-08-22


来源:https://github.com/marketplace/actions/file-sync
看第二个回答: https://stackoverflow.com/questions/69577518/github-action-to-copy-specific-folders-from-one-branch-to-another-in-the-same-re

  name: Copy folder to other branch
  
  on: [push]
  
  jobs:
    copy:
      name: Copy my folder
      runs-on: ubuntu-latest
      steps:
        uses: actions/checkout@v2
        name: copy
          env:
            SRC_FOLDER_PATH: 'static'
            TARGET_BRANCH: 'dest'
          run: |
            files=$(find $SRC_FOLDER_PATH -type f) # get the file list
            git config --global user.name 'GitHub Action'
            git config --global user.email '[email protected]'
            git fetch                         # fetch branches
            git checkout $TARGET_BRANCH       # checkout to your branch
            git checkout ${GITHUB_REF##*/} -$files # copy files from the source branch
            git add -A
            git diff-index --quiet HEAD ||  git commit -am "deploy files"  # commit to the repository (ignore if no modification)
            git push origin $TARGET_BRANCH # push to remote branch