gpt4 book ai didi

git - 使用 GitHub Actions 自动更新 repo 的子模块

转载 作者:行者123 更新时间:2023-12-04 11:07:40 59 4
gpt4 key购买 nike

标题说明了一切。我尝试使用一堆不同的 git 命令,例如 git submodule update --remote --mergegit submodule foreach git pull origin master它在我的计算机上运行良好,但在 GitHub 操作上运行时却不行。
我尝试添加 git status到工作流,状态只显示“与源/主服务器保持最新,没有可提交的内容”或类似的东西。

最佳答案

如果您需要通过 GitHub 操作自动更新对子模块的引用:
在您的父存储库中创建一个将同步引用的新工作流:

name: 'Submodules Sync'

on:
# Allows you to run this workflow manually from the Actions tab or through HTTP API
workflow_dispatch:

jobs:
sync:
name: 'Submodules Sync'
runs-on: ubuntu-latest

# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash

steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.CI_TOKEN }}
submodules: true

# Update references
- name: Git Sumbodule Update
run: |
git pull --recurse-submodules
git submodule update --remote --recursive

- name: Commit update
run: |
git config --global user.name 'Git bot'
git config --global user.email 'bot@noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git commit -am "Auto updated submodule references" && git push || echo "No changes to commit"
在哪里
  • CI_TOKEN 是 GitHub 中的安全 token 变量,具有对父存储库的“读写”访问权限和对子模块存储库的“读取”访问权限。

  • 在子(子模块)GitHub 操作中通知父级更改。
    name: 'Submodule Notify Parent'

    on:
    push:
    branches:
    - main

    # Allows you to run this workflow manually from the Actions tab
    workflow_dispatch:

    jobs:
    notify:
    name: 'Submodule Notify Parent'
    runs-on: ubuntu-latest

    # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
    defaults:
    run:
    shell: bash

    steps:
    - name: Github REST API Call
    env:
    CI_TOKEN: ${{ secrets.CI_TOKEN }}
    PARENT_REPO: <my_organization/my-app>
    PARENT_BRANCH: develop
    WORKFLOW_ID: <9999999>
    run: |
    curl -fL --retry 3 -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${{ env.CI_TOKEN }}" https://api.github.com/repos/${{ env.PARENT_REPO }}/actions/workflows/${{ env.WORKFLOW_ID }}/dispatches -d '{"ref":"${{ env.PARENT_BRANCH }}"}'
    在哪里
  • PARENT_REPO - Github 中父存储库的名称(如果没有组织,则为 my_org/my_app 或仅 my_app)。
  • WORKFLOW_ID - 通过 rest API 调用的父 Wofklow ID。要找到它,请使用您的 CI_TOKEN 运行 curl :
    curl -X GET -H "Authorization: token $CI_TOKEN" https://api.github.com/repos/$PARENT_REPO/actions/workflows

  • 为每个子模块重复创建工作流。

    附言对我来说它工作得非常稳定。如果有的话,请使用上述逻辑添加有关现有 github 操作的信息。

    关于git - 使用 GitHub Actions 自动更新 repo 的子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64407333/

    59 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com