【问题标题】:Automatically copy a file from one GitHub repository to another via Codehip通过 Codehip 自动将文件从一个 GitHub 存储库复制到另一个
【发布时间】:2017-12-05 20:47:11
【问题描述】:

我有两个存储库:S1S2

如果文件被更改或创建,我想自动将文件从 S1 推送到 S2

例如:

我在S1 中将translation.en.json 推送到/translations/translation.en.jsontranslation.en.json 应该会自动推送到/dashboard/translation.en.json 中的S2

当我将某些内容推送到 S1 中的 master 分支时,将运行 codeship 构建。

我想在codeship 步骤中编写一个脚本,可以自动推送。

我试过这样的:

#!/bin/bash
set -e
mkdir -p _translations/dashboard/
cd _translations
git fetch --unshallow || true
git fetch origin "+refs/heads/*:refs/remotes/origin/*"
git push git@github.com:company/translations.git "${CI_COMMIT_ID}:master"

【问题讨论】:

  • 我根据您的问题编写了一个可能的工作流程,但是由于您提到您尝试了上述脚本,因此了解哪些有效,哪些无效会很有帮助。此外,您也可以随时通过helpdesk.codeship.com 与 Codeship 支持(我是其中的一员)联系。

标签: github webhooks codeship


【解决方案1】:

我们有一个基于脚本的部署,用于推送到 https://github.com/codeship/scripts/blob/master/deployments/git_push.sh 上的不同 git 存储库

您可以通过设置所需的环境变量并添加curl 命令来添加脚本部署,从而将其添加到您的部署管道中,例如

export REMOTE_REPOSITORY="git@github.com:company/s2.git"
export REMOTE_BRANCH="master"
\curl -sSL https://raw.githubusercontent.com/codeship/scripts/master/deployments/git_push.sh | bash -s

您还需要确保 Codeship 项目 SSH 密钥(可通过项目设置获得)被允许推送到第二个存储库。请参阅https://documentation.codeship.com/general/projects/access-to-other-repositories-fails-during-build/ 了解如何配置。

但是,这会将S1 的完整内容推送到另一个存储库。如果您只想推送特定文件(或一组文件),我建议克隆第二个存储库,将文件复制过来,然后提交并推送。示例脚本可能如下所示:

cd "${HOME}"
git clone git@github.com:company/s2.git
# "${HOME}/clone" is the default checkout path on Codeship
cp ./clone/translation.en.json ./s2/
cd ./s2
git commit -a "Automatic commit, based on "company/s1@${CI_COMMIT_ID}"
git push origin master

请注意,此脚本未经测试,绝对需要根据您的特定需求进行调整。有关身份验证和访问第二个存储库的说明也适用于此用例。

【讨论】:

    猜你喜欢
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 2012-10-05
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 2013-10-01
    相关资源
    最近更新 更多