标题说明了一切。我尝试使用一堆不同的 git 命令,例如git submodule update --remote --merge和git submodule foreach git pull origin master,它们在我的计算机上运行良好,但在 GitHub 操作上运行时却没有。我尝试添加git status到工作流程中,状态仅显示“与原点/主控保持同步,无需提交”或类似内容。
Akn*_*sis 20
如今更好的选择是利用 Dependabot 自动为子模块创建 PR。
每天检查子模块是否已更新的示例:在.github/dependabot.yml
version: 2
updates:
- package-ecosystem: gitsubmodule
schedule:
interval: "daily"
directory: /
Run Code Online (Sandbox Code Playgroud)
Dro*_*let 17
您可以通过子模块存储库中的单个操作来实现此目的:
name: Send submodule updates to parent repo
on:
push:
branches:
- main
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
repository: org/parent_repository
token: ${{ secrets.PRIVATE_TOKEN_GITHUB }}
submodules: true
- name: Pull & update submodules recursively
run: |
git submodule update --init --recursive
git submodule update --recursive --remote
- name: Commit
run: |
git config user.email "actions@github.com"
git config user.name "GitHub Actions - update submodules"
git add --all
git commit -m "Update submodules" || echo "No changes to commit"
git push
Run Code Online (Sandbox Code Playgroud)
你需要:
org/parent_repository为例)。PRIVATE_TOKEN_GITHUB(在上面示例中的名称下)通过此操作,main子模块存储库中分支的每次推送都将导致在父存储库中拉取更新的提交。
您递归地拉取和更新子模块,然后提交到存储库。
name: Update submodules
# Controls when the action will run.
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
# This workflow contains a single job called "update"
update:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Pull & update submodules recursively
run: |
git submodule update --init --recursive
git submodule update --recursive --remote
- name: Commit & push changes
run: |
git config --global user.name ${{ secrets.USER_NAME }}
git config --global user.email ${{ secrets.USER_EMAIL }}
git commit -am "Update submodules"
git push
Run Code Online (Sandbox Code Playgroud)
因为我很懒,所以我没有像我那样使用 Github 秘密${{ secrets.USER_NAME }},只是硬编码我的 git 凭据,但我认为你可能关心安全性。
在您的父存储库中创建一个将同步引用的新工作流:
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"
Run Code Online (Sandbox Code Playgroud)
在哪里
在子(子模块)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 }}"}'
Run Code Online (Sandbox Code Playgroud)
在哪里
CI_TOKEN:
curl -X GET -H "Authorization: token $CI_TOKEN" https://api.github.com/repos/$PARENT_REPO/actions/workflows
Run Code Online (Sandbox Code Playgroud)
为每个子模块重复工作流创建。
PS 对我来说它的工作非常稳定。如果有的话,请使用上述逻辑添加有关现有 github 操作的信息。
您可以将您的 GitHub Action 源代码与类似的源代码进行比较submodule-branch-check,后者确实至少生成了一个git submodule update.
检查是否update --remote足以从其自己的远程源拉取。