【问题标题】:github actions: update submodules from upstream with rebasegithub 操作:使用 rebase 从上游更新子模块
【发布时间】:2021-12-20 19:41:14
【问题描述】:

我想更新我的存储库子模块,推送到它们各自的分支,然后将更改提交到我的主存储库并推送它。

这是我的 github 操作 yml:

---
name: Auto Update Submodules
# yamllint disable-line rule:truthy
on:
  push:
  # schedule:
  #   # Run every Wednesday at 4 AM.
  #   - cron: "0 4 * * WED"
jobs:
  auto-update:
    runs-on: ubuntu-latest
    steps:
      # Create private key to access private repos.
      - uses: webfactory/ssh-agent@v0.5.3
        with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
      - uses: actions/checkout@v2
        with:
          ref: '15.0'
          submodules: true
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
          persist-credentials: true
      - name: Update submodules from origin
        run: |
          git submodule update --recursive --remote --merge --init --rebase
      - name: Update from upstream and commit
        run: |
          git config --global user.name 'bot'
          git config --global user.email 'bot@users.noreply.github.com'
          cd src/odoo
          git checkout 15.0
          git remote add upstream git@github.com:odoo/odoo.git
          git fetch upstream 15.0
          git rebase upstream/15.0
          git push
          cd ../enterprise
          git checkout 15.0
          git remote add upstream git@github.com:odoo/enterprise.git
          git fetch upstream 15.0
          git rebase upstream/15.0
          git push
          cd ../..
          git add .
          git commit -m "[SUB] odoo/enterprise" || echo "No changes to commit"
          git push origin 15.0

这是触发动作时得到的结果:

  git submodule update --recursive --remote --merge --init --rebase
  shell: /usr/bin/bash -e {0}
  env:
    SSH_AUTH_SOCK: /tmp/ssh-VxFJiDzXtsoG/agent.2130
    SSH_AGENT_PID: 2131
Rebasing (1/1)
warning: Cannot merge binary files: stock_barcode/static/img/barcodes_demo.pdf (HEAD vs. 944ae3a4 ([I18N] Update translation terms from Transifex))
CONFLICT (add/add): Merge conflict in worksheet/i18n/sv.po
Auto-merging worksheet/i18n/sv.po
CONFLICT (add/add): Merge conflict in worksheet/i18n/de.po
Auto-merging worksheet/i18n/de.po
CONFLICT (add/add): Merge conflict in website_twitter_wall/i18n/zh_TW.po
Auto-merging website_twitter_wall/i18n/zh_TW.po
CONFLICT (add/add): Merge conflict in website_twitter_wall/i18n/vi.po
Auto-merging website_twitter_wall/i18n/vi.po
CONFLICT (add/add): Merge conflict in website_twitter_wall/i18n/th.po
Auto-merging website_twitter_wall/i18n/th.po
...
...
Error: Process completed with exit code 2.

如果我只从上游获取更改并使用它提交到主存储库,它会更新它。但随后进一步的工作流程中断,因为它找不到那些提交(直接来自上游存储库)。

我尝试从本地上游(从我的 PC)更新我的子模块,它工作正常。没有冲突,没有错误,(甚至不需要强制推送,因为我没有任何自定义更改):

git fetch upstream 15.0
git rebase upstream/15.0
git push

src/odoosrc/enterprise 是子模块的路径。

我对 github 操作的行为不同做错了什么?

会不会是因为它只获得了浅拷贝而导致事情中断?

【问题讨论】:

  • 我没有仔细看这个,但git submodule update --remote --merge --rebase 肯定是错误的:--merge--rebase 是这里的独家选项。我认为最后一个覆盖,所以你得到 --rebase 行为,但我不想指望这一点。
  • (同时:是的,这可能是这里有问题的浅层克隆。鉴于你自己的答案,我现在已经略过,你可以通过完全删除 --merge --rebase 来做到这一点,可能。)跨度>
  • 实际上,起初我试图在没有明确子模块更新的情况下进行更新,但我遇到了同样的问题。
  • 是的,我认为你是对的,我应该使用 rebase 或 merge,但不能同时使用。

标签: git github-actions git-submodules


【解决方案1】:

通过单独更新子模块(作为普通存储库)然后从子模块中获取推送的更改来解决它:

---
name: Auto Update Submodules
# yamllint disable-line rule:truthy
on:
  push:
  # schedule:
  #   # Run every Wednesday at 4 AM.
  #   - cron: "0 4 * * WED"
jobs:
  auto-update:
    runs-on: ubuntu-latest
    steps:
      # Create private key to access private repos.
      - uses: webfactory/ssh-agent@v0.5.3
        with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
      - uses: actions/checkout@v2
        with:
          repository: my/odoo
          ref: '15.0'
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
      # Sync submodules (separately).
      - name: Sync odoo repo
        run: |
          git remote add upstream git@github.com:odoo/odoo.git
          git fetch upstream 15.0
          git rebase upstream/15.0
          git push
      - uses: actions/checkout@v2
        with:
          repository: my/enterprise
          ref: '15.0'
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
      - name: Sync enterprise repo
        run: |
          git remote add upstream git@github.com:odoo/enterprise.git
          git fetch upstream 15.0
          git rebase upstream/15.0
          git push
      # Update synced submodules on main repo.
      - uses: actions/checkout@v2
        with:
          ref: '15.0'
          submodules: true
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
      - name: Update submodules from origin
        run: |
          git submodule update --recursive --remote --merge --init --rebase
      - name: Commit updated submodules.
        run: |
          git config --global user.name 'bot'
          git config --global user.email 'bot@users.noreply.github.com'
          git add .
          git commit -m "[SUB] odoo/enterprise" || echo "No changes to commit"
          git push origin 15.0

【讨论】:

    猜你喜欢
    • 2022-01-04
    • 2021-06-17
    • 2021-04-16
    • 2021-03-12
    • 1970-01-01
    • 1970-01-01
    • 2011-10-11
    • 1970-01-01
    • 2018-03-03
    相关资源
    最近更新 更多