【问题标题】:Github action to push build folder to a different repoGithub 操作将构建文件夹推送到不同的 repo
【发布时间】:2023-01-24 14:32:42
【问题描述】:

我有 2 个回购协议,带有源代码的回购协议 A 和将构建文件夹发布到网络的回购协议 B。

我为此目的采取了行动,但我收到错误消息:

git clone --single-branch --branch main ***github.com/blockcodelabs/B.git /tmp/tmp.NCbLCG<BR>
Cloning into '/tmp/tmp.NCbLCG'...<BR>
remote: Invalid username or password.<BR>
fatal: Authentication failed for 'https://github.com/blockcodelabs/B.git/'<BR>

该操作在 Repo A 上设置,而 Repo B 有 secret.ACCESS_TOKEN:

name: Push File(or Dir) to another repository

on:
  push:
    branches: [master]

jobs:
  copy-file:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Push to another repo
      uses: dmnemec/copy_file_to_another_repo_action@main
      env:
        ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} 
      with:
        source_file: 'build'
        destination_repo: 'blockcodelabs/B'
        destination_folder: 'build'
        user_email: 'email'
        user_name: 'username'
        commit_message: 'Automatic Build To B'

*更新 - 在错误点上添加了图片,以获取更多详细信息。

【问题讨论】:

    标签: git github ssh repository cicd


    【解决方案1】:

    检查错误发生在 GitHub 操作中的哪一点:

    • 在actions/checkout@v2这一步? (在这种情况下,应该在那里使用访问令牌)
    • 在dmnemec/copy_file_to_another_repo_action@main这一步

    在这两种情况下,使用的 URL 都是 HTTPS,而不是 SSH。

    dmnemec/copy_file_to_another_repo_action entrypoint.sh#L28 显示:

    git clone --single-branch --branch $INPUT_DESTINATION_BRANCH 
    "https://x-access-token:$API_TOKEN_GITHUB@$INPUT_GIT_SERVER/$INPUT_DESTINATION_REPO.git" "$CLONE_DIR"
    

    这意味着您需要使用您的秘密设置 API_TOKEN_GITHUB,以便 git 克隆成功。

    env:
            API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
    

    即:API_TOKEN_GITHUB,而不是ACCESS_TOKEN。


    正如rempsyc在“API_TOKEN_GITHUB not recognized with copy_file_to_another_repo_action GitHub workflow”中指出的那样:

    我的问题是我在目标仓库而不是源仓库中创建了秘密。
    交换这两个解决了这个问题。

    所以要注意在哪里你已经创造了秘密。

    【讨论】:

    • 它发生在 dmnemec/copy_file_to_another_repo_action@main 步骤。
    • 添加了屏幕截图以获取更好的详细信息。
    • @LGarcia 好的,谢谢你的更新。我已经相应地更新了我的答案。
    • 我更新了变量但仍然出现相同的错误。它的个人访问令牌是正确的类型吗?
    • @LGarcia 首先通过回显检查secrets.API_TOKEN_GITHUB 是否有值(以及预期的值,即ghp_...。如果是这样,请检查scope of the token。也许更广泛的范围会有所帮助。
    猜你喜欢
    • 2020-11-17
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 2022-01-27
    • 1970-01-01
    • 2021-05-18
    相关资源
    最近更新 更多