How to checkout specific submodule branch in GitHub action?

Viewed 376

I have a Github workflow file with a checkout action that looks something like this:

name: Build project

on:
  workflow_dispatch:
    # Allows for manual build trigger

jobs:
  buildForAllSupportedPlatforms:
    name: Build for ${{ matrix.targetPlatform }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
          submodules: true

This does the logical thing, it checks out the submodules with something like submodule update --init --force. Here's my question - How do I make all the submodules check out on the master branch?

2 Answers

Figured out something that works - Just add another step after uses: actions/checkout@v2:

      - name: Checkout master on all submodules
        run: |
          git submodule foreach git checkout master
          git submodule foreach git pull origin master

Try this

    - name: Checkout submodule
      uses: actions/checkout@v2
      with:
        token: '${{ secrets.GITHUB_PAT }}'
        repository: myOrg/myRepo
        path: path/to/submodule
        ref: 'master'
Related