0

I want to update my repository submodules, push to their respective forks and then commit changes to my main repo and push it.

Here is my github action 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

This is what I get when action is triggered:

  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.

If I only fetch changes from upstream and use that to commit on main repo, it does update it. But then further workflow breaks, because it can't find those commits (which are coming directly from upstream repos).

I tried to update my submodules from upstream locally (from my PC) and it works fine. No conflicts, no errors, with (don't even need to force push it, because I don't have any custom changes):

git fetch upstream 15.0
git rebase upstream/15.0
git push

src/odoo and src/enterprise are paths to submodules.

What am I doing wrong with github actions that it behaves differently?

Could it be that it gets only shallow copy and things break because of it?

Andrius
  • 19,658
  • 37
  • 143
  • 243
  • I haven't looked closely at this, but `git submodule update --remote --merge --rebase` is definitely wrong: `--merge` and `--rebase` are exclusive options here. I think the last one overrides, so that you're getting `--rebase` behavior, but I would not want to count on that. – torek Nov 07 '21 at 21:52
  • (Meanwhile: yes, it's probably the shallow clone at issue here. Given your own answer, which I have now skimmed, you could have done this by dropping `--merge --rebase` entirely, probably.) – torek Nov 07 '21 at 21:55
  • Actually at first I was trying to update without explicit submodule update as in my question, but I had same problem. – Andrius Nov 07 '21 at 21:58
  • And yes, I think you are right, I should use rebase or merge, but not both. – Andrius Nov 07 '21 at 22:04

1 Answers1

0

Solved it by updating submodules separately (as normal repositories) and then fetching pushed changes from submodules:

---
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
Andrius
  • 19,658
  • 37
  • 143
  • 243