Github 将特定文件夹从一个分支复制到同一存储库中的另一个分支的操作
Github action to copy specific folders from one branch to another in the same repo
是否有一个 github 操作允许我将特定文件夹(例如 dist 和 static)从一个分支复制到同一私有存储库中的另一个分支。我感谢任何帮助。
这是试图使用 Copycat 操作使其工作的方法。
name: Copying static files
on:
push:
branches:
- src # Set a branch name to trigger deployment
jobs:
copy:
runs-on: ubuntu-latest
steps:
- name: Copycat
uses: andstor/copycat-action@v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }}
src_path: static.
dst_path: /static/
dst_owner: CompanyX
dst_repo_name: MyRepo
dst_branch: dest
src_branch: src
src_wiki: false
dst_wiki: false
- name: Copycat2
uses: andstor/copycat-action@v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }}
src_path: dist.
dst_path: /dist/
dst_owner: CompanyX
dst_repo_name: MyRepo
dst_branch: des
src_branch: src
src_wiki: false
dst_wiki: false
但即使我在我的个人资料中设置了个人令牌,我仍然收到此错误。
fatal: could not read Password for 'https://github.com': No such device or address
如果要提交到同一个存储库,则不必指定个人令牌,只需使用 actions/checkout@v2
(参见 )
在分支之间复制文件的一种解决方案是使用 git checkout [branch] -- $files
,请参阅
以下工作流将源分支上名为 static
的目录中的文件复制到名为 dest
的分支:
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 'action@github.com'
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
是否有一个 github 操作允许我将特定文件夹(例如 dist 和 static)从一个分支复制到同一私有存储库中的另一个分支。我感谢任何帮助。 这是试图使用 Copycat 操作使其工作的方法。
name: Copying static files
on:
push:
branches:
- src # Set a branch name to trigger deployment
jobs:
copy:
runs-on: ubuntu-latest
steps:
- name: Copycat
uses: andstor/copycat-action@v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }}
src_path: static.
dst_path: /static/
dst_owner: CompanyX
dst_repo_name: MyRepo
dst_branch: dest
src_branch: src
src_wiki: false
dst_wiki: false
- name: Copycat2
uses: andstor/copycat-action@v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }}
src_path: dist.
dst_path: /dist/
dst_owner: CompanyX
dst_repo_name: MyRepo
dst_branch: des
src_branch: src
src_wiki: false
dst_wiki: false
但即使我在我的个人资料中设置了个人令牌,我仍然收到此错误。
fatal: could not read Password for 'https://github.com': No such device or address
如果要提交到同一个存储库,则不必指定个人令牌,只需使用 actions/checkout@v2
(参见
在分支之间复制文件的一种解决方案是使用 git checkout [branch] -- $files
,请参阅
以下工作流将源分支上名为 static
的目录中的文件复制到名为 dest
的分支:
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 'action@github.com'
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