【问题标题】:github action to copy a file from one repo to another将文件从一个存储库复制到另一个存储库的 github 操作
【发布时间】:2021-04-22 20:54:20
【问题描述】:

我的公司创建了一种在环境之间移动文件的复杂方法,现在我们想将某些已构建的 JS 文件(已转译和缩小)从一个 github 存储库移动到另一个。这可以使用 github 操作吗?

【问题讨论】:

  • 我认为构建的文件不应该保存在存储库中
  • @Ziarno 这是一个特例

标签: github github-actions


【解决方案1】:

最简单的选择是克隆目标 repo,将文件复制到目标 repo,使用 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

【讨论】:

  • 您可能需要将个人访问令牌存储到 GitHub 机密存储区,以防 GITHUB_TOKEN 没有正确的权限。
  • 查看令牌权限:help.github.com/en/actions/…
  • rm target 在这种情况下做了什么? target 不是目录吗?
  • 是的,看看这个,我想我们在这里缺少一个 -rf ......只是确保有一个干净的目录可以克隆。
  • 另一个有用的补充是修改git commit 行以处理没有任何变化的情况。如果不是,则该操作将在这种情况下失败。 git diff-index --quiet HEAD || git commit 。创意来源:github.com/cpina 另外,上面的网址是正确的吗? //.: 是什么?
猜你喜欢
  • 2012-10-05
  • 2013-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多