Search code examples
gitgithubcontinuous-integrationgithub-actionsgit-submodules

GitHub CI not pulling latest submodule revision


I'm experiencing a very strange issue. I will share the code and repos since everything is open source.

I have a submodule defined in .gitmodules as shown here:

[submodule "packages/sdk/lib/contracts"]
    path = packages/sdk/lib/contracts
    url = https://github.com/ionicprotocol/contracts
    branch = development

https://github.com/ionicprotocol/monorepo/blob/development/.gitmodules#L4

In my GitHub CI, I am failing recent jobs because the submodule revision that's checked out is an old revision:

'packages/sdk/lib/contracts'
  Cloning into '/home/runner/work/monorepo/monorepo/packages/sdk/lib/contracts'...
  From https://github.com/ionicprotocol/contracts
   * branch            f34adca4d882b65310e21b8b9df01df32026ac09 -> FETCH_HEAD

https://github.com/ionicprotocol/monorepo/actions/runs/9189715243/job/25272345929?pr=374

The latest commit is 2493935081b4bdfe64d1ecd12f2f5141284347fe.

I can see locally when I run git submodule it's showing the latest commit.

I cannot figure out where this old commit would be stored, and GitHub CI is not set up to cache anything AFAICT.

Everything worked locally once I ran git pull --recurse-submodules.

Any help would be appreciated!


Solution

  • I cloned the repository with the command

    git clone --recurse-submodules https://github.com/ionicprotocol/monorepo.git
    

    The checked out branch is the default development:

    $ cd monorepo
    $ git branch
    * development
    

    Let's see what submodule's commit the superproject stores in the HEAD:

    $ git rev-parse development:packages/sdk/lib/contracts
    f34adca4d882b65310e21b8b9df01df32026ac09
    

    The command can be simplified for the current commit:

    $ git rev-parse @:packages/sdk/lib/contracts
    f34adca4d882b65310e21b8b9df01df32026ac09
    

    Exactly what CI sees.

    If you want to update the submodule to the latest commit at remote you also need to update the superproject:

    $ cd packages/sdk/lib/contracts
    $ git switch development
    $ git show --format=%H
    2493935081b4bdfe64d1ecd12f2f5141284347fe
    
    $ cd ../../../.. # back to the superproject
    $ git add packages/sdk/lib/contracts
    $ git commit -m 'Update submodule `contracts`'
    $ git push
    

    Another variant:

    $ git submodule update --remote
    $ git commit -m 'Update submodule `contracts`'
    $ git push
    

    See the docs.