GitHub Action将文件从一个仓库复制到另一个仓库

11
公司已经开发了一种复杂的方法在环境之间移动文件,现在我们希望将某些已构建的JS文件(经过转译和缩小)从一个Github存储库移动到另一个存储库。使用Github Actions是否可以实现这一点?

我认为构建文件不应该保存在代码库中。 - Ziarno
@Ziarno 这是一个特殊情况。 - zero
1个回答

14

最简单的方法是克隆目标仓库,将文件复制到目标仓库中,使用git命令行暂存这些文件,然后提交它们。在脚本步骤中添加以下代码:

run: |
    git clone https://.:${{ secrets.GITHUB_TOKEN }}@github.com/project target
    rm everything but the .git directory
    copy source\files target
    cd target
    git add .
    git diff-index --quiet HEAD || git commit -m "Automatic publish from github.com/project"
    git push target master

1
如果GITHUB_TOKEN没有正确的权限,您可能需要将个人访问令牌存储到GitHub秘密存储中。 - jessehouwing
请参阅此处的令牌权限:https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#permissions-for-the-github_token - jessehouwing
应该在克隆之前执行 "rm -rf target" 命令。 - srikanth Nutigattu
1
另一个有用的补充是修改git commit行以处理没有更改的情况。否则,该操作将失败。git diff-index --quiet HEAD || git commit。创意来源:github.com/cpina此外,上面的网址正确吗?“//:。”是什么? - Robert Lugg
是的,. 是用户名(在使用令牌时无关紧要)。在 : 后面是密码(令牌)。如果您愿意,可以使用 notneeded:github: - jessehouwing
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接