|
| 1 | +<h1 align="center"> |
| 2 | + update-git-submodules ( |
| 3 | + <a href="https://github.com/sgoudham/update-git-submodules/actions/workflows/build.yml"><img src="https://github.com/sgoudham/update-git-submodules/actions/workflows/build.yml/badge.svg"></a> ) |
| 4 | +</h1> |
| 5 | + |
| 6 | +This GitHub Action updates one or more git submodules in a repository to the |
| 7 | +latest tag. The primary use case for this action is to be used across the |
| 8 | +[Catppuccin](https://github.com/catppuccin) GitHub organisation, allowing |
| 9 | +repositories to update their submodules to the latest git tag instead of the |
| 10 | +latest commit. |
| 11 | + |
| 12 | +### What it does |
| 13 | + |
| 14 | +- It automatically parses `.gitmodules` and updates one or more submodules to the |
| 15 | + latest git tag. |
| 16 | +- It allows the user to specify which submodules to update. |
| 17 | + |
| 18 | +### What it doesn't do |
| 19 | + |
| 20 | +- It **does not** commit or push these changes back to the repository. Please |
| 21 | + see the "[Scenarios](#scenarios)" section for examples on how to do this. |
| 22 | +- It **does not** update submodules to the latest commit as I focused on tags for |
| 23 | + the initial release. I'd personally recommend using |
| 24 | + [Renovate](https://docs.renovatebot.com/modules/manager/git-submodules/) or |
| 25 | + equivalent if you'd like submodules to be updated to the latest commit. I will |
| 26 | + most likely add this functionality in the future. |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +<!-- x-release-please-start-version --> |
| 31 | + |
| 32 | +```yaml |
| 33 | +- uses: sgoudham/[email protected] |
| 34 | + with: |
| 35 | + # The path to the '.gitmodules' file. |
| 36 | + # |
| 37 | + # Defaults to '.gitmodules' in the root of the repository. |
| 38 | + gitmodulesPath: "" |
| 39 | + |
| 40 | + # The git submodule(s) to update, the path should be the |
| 41 | + # same as the one specified in the '.gitmodules' file. |
| 42 | + # |
| 43 | + # Defaults to all submodules in the '.gitmodules' file. |
| 44 | + submodules: "" |
| 45 | +``` |
| 46 | +
|
| 47 | +## Outputs |
| 48 | +
|
| 49 | +### Static Outputs |
| 50 | +
|
| 51 | +- `json`: A JSON array containing all the submodules that were updated. |
| 52 | +- `matrix`: A JSON array containing all the submodules that were updated, |
| 53 | + intended for use in a GitHub Actions matrix strategy. |
| 54 | +- `prBody`: A Markdown string containing a formatted table of all the submodules |
| 55 | + that were updated, intended for use in a pull request body. |
| 56 | + |
| 57 | +### Dynamic Outputs |
| 58 | + |
| 59 | +As well as the static outputs, this action will also output the following variables: |
| 60 | + |
| 61 | +- `path`: The path to the submodule that was updated. |
| 62 | +- `url`: The GitHub URL of the submodule that was updated. |
| 63 | +- `previousTag`: The tag of the submodule before it was updated. |
| 64 | +- `latestTag`: The tag that the submodule was updated to. |
| 65 | +- `prBody`: A Markdown string intended for use in a pull request body. |
| 66 | + |
| 67 | +These dynamic outputs will be prefixed with the submodule name (and the |
| 68 | +submodule path if the name is different to the path) followed by two hyphens |
| 69 | +(`--`). |
| 70 | + |
| 71 | +For example, if the submodule is named `vscode-icons` and the path is |
| 72 | +`ports/vscode-icons`, the dynamic outputs will be: |
| 73 | + |
| 74 | +- `vscode-icons--path` |
| 75 | +- `vscode-icons--url` |
| 76 | +- `vscode-icons--previousTag` |
| 77 | +- `vscode-icons--latestTag` |
| 78 | +- `vscode-icons--prBody` |
| 79 | +- `ports/vscode-icons--path` |
| 80 | +- `ports/vscode-icons--url` |
| 81 | +- `ports/vscode-icons--previousTag` |
| 82 | +- `ports/vscode-icons--latestTag` |
| 83 | +- `ports/vscode-icons--prBody` |
| 84 | + |
| 85 | +## Scenarios |
| 86 | + |
| 87 | +1. [Update one submodule and create one pull request](#update-one-submodule-and-create-one-pull-request) |
| 88 | +2. [Update multiple submodules and create one pull request](#update-multiple-submodules-and-create-one-pull-request) |
| 89 | +3. [Update multiple submodules and create multiple pull requests](#update-multiple-submodules-and-create-multiple-pull-requests) |
| 90 | + |
| 91 | +### Update one submodule and create one pull request |
| 92 | + |
| 93 | +`.gitmodules` |
| 94 | + |
| 95 | +```ini |
| 96 | +[submodule "vscode-icons"] |
| 97 | + path = ports/vscode-icons |
| 98 | + url = https://github.com/catppuccin/vscode-icons.git |
| 99 | +``` |
| 100 | + |
| 101 | +`workflow.yml` |
| 102 | + |
| 103 | +```yaml |
| 104 | +steps: |
| 105 | + - name: Checkout Repository |
| 106 | + uses: actions/checkout@v4 |
| 107 | + with: |
| 108 | + submodules: "recursive" |
| 109 | + fetch-depth: 0 |
| 110 | +
|
| 111 | + - name: Update Submodules |
| 112 | + id: submodules |
| 113 | + uses: "sgoudham/[email protected]" |
| 114 | +
|
| 115 | + - name: Create PR |
| 116 | + uses: peter-evans/create-pull-request@v6 |
| 117 | + if: ${{ steps.submodules.outputs['vscode-icons--latestTag'] }} |
| 118 | + with: |
| 119 | + commit-message: "feat: update catppuccin/vscode-icons to ${{ steps.submodules.outputs['vscode-icons--latestTag'] }}" |
| 120 | + branch: "feat/update-vscode-icons-${{ steps.submodules.outputs['vscode-icons--latestTag'] }}" |
| 121 | + title: "feat: update catppuccin/vscode-icons submodule to ${{ steps.submodules.outputs['vscode-icons--latestTag'] }}" |
| 122 | + body: ${{ steps.submodules.outputs.prBody }} |
| 123 | +``` |
| 124 | + |
| 125 | +### Update multiple submodules and create one pull request |
| 126 | + |
| 127 | +```yaml |
| 128 | +steps: |
| 129 | + - name: Checkout Repository |
| 130 | + uses: actions/checkout@v4 |
| 131 | + with: |
| 132 | + submodules: "recursive" |
| 133 | + fetch-depth: 0 |
| 134 | +
|
| 135 | + - name: Update Submodules |
| 136 | + id: submodules |
| 137 | + uses: "sgoudham/[email protected]" |
| 138 | +
|
| 139 | + - name: Create PR |
| 140 | + uses: peter-evans/create-pull-request@v6 |
| 141 | + with: |
| 142 | + commit-message: "feat: update all submodules" |
| 143 | + branch: "feat/update-all-submodules" |
| 144 | + title: "feat: update all submodules" |
| 145 | + body: ${{ steps.submodules.outputs.prBody }} |
| 146 | +``` |
| 147 | + |
| 148 | +### Update multiple submodules and create multiple pull requests |
| 149 | + |
| 150 | +`.gitmodules` |
| 151 | + |
| 152 | +```ini |
| 153 | +[submodule "ports/nvim"] |
| 154 | + path = ports/nvim |
| 155 | + url = https://github.com/catppuccin/nvim.git |
| 156 | +[submodule "ports/mdBook"] |
| 157 | + path = ports/mdBook |
| 158 | + url = https://github.com/catppuccin/mdBook.git |
| 159 | +[submodule "ports/vscode-icons"] |
| 160 | + path = ports/vscode-icons |
| 161 | + url = https://github.com/catppuccin/vscode-icons.git |
| 162 | +``` |
| 163 | + |
| 164 | +`workflow.yml` |
| 165 | + |
| 166 | +```yaml |
| 167 | +jobs: |
| 168 | + update-submodule: |
| 169 | + runs-on: ubuntu-latest |
| 170 | + strategy: |
| 171 | + matrix: |
| 172 | + submodule: [ports/nvim, ports/mdBook] |
| 173 | + steps: |
| 174 | + - name: Checkout Repository |
| 175 | + uses: actions/checkout@v4 |
| 176 | + with: |
| 177 | + submodules: "recursive" |
| 178 | + fetch-depth: 0 |
| 179 | +
|
| 180 | + - name: Update Submodules |
| 181 | + id: submodules |
| 182 | + uses: "sgoudham/[email protected]" |
| 183 | + with: |
| 184 | + submodules: ${{ matrix.submodule }} |
| 185 | +
|
| 186 | + - name: Create PR |
| 187 | + uses: peter-evans/create-pull-request@v6 |
| 188 | + if: ${{ steps.submodules.outputs[format('{0}--latestTag', matrix.submodule)] }} |
| 189 | + with: |
| 190 | + commit-message: "feat: update ${{ matrix.submodule }} to ${{ steps.submodules.outputs[format('{0}--latestTag', matrix.submodule)] }}" |
| 191 | + branch: "feat/update-${{ matrix.submodule }}-${{ steps.submodules.outputs[format('{0}--latestTag', matrix.submodule)] }}" |
| 192 | + title: "feat: update ${{ matrix.submodule }} submodule to ${{ steps.submodules.outputs[format('{0}--latestTag', matrix.submodule)] }}" |
| 193 | + body: ${{ steps.submodules.outputs.prBody }} |
| 194 | +``` |
| 195 | + |
| 196 | +<details> |
| 197 | +<summary>Drop me down to view a version where multiple pull requests are created in the same job (not recommended!)</summary> |
| 198 | + |
| 199 | +```yaml |
| 200 | +jobs: |
| 201 | + update-submodules: |
| 202 | + runs-on: ubuntu-latest |
| 203 | + env: |
| 204 | + nvim: "ports/nvim" |
| 205 | + mdBook: "ports/mdBook" |
| 206 | +
|
| 207 | + steps: |
| 208 | + - name: Checkout Repository |
| 209 | + uses: actions/checkout@v4 |
| 210 | + with: |
| 211 | + submodules: "recursive" |
| 212 | + fetch-depth: 0 |
| 213 | +
|
| 214 | + - name: Update Submodules |
| 215 | + id: submodules |
| 216 | + uses: "sgoudham/[email protected]" |
| 217 | + with: |
| 218 | + submodules: | |
| 219 | + ${{ env.nvim }} |
| 220 | + ${{ env.mdBook }} |
| 221 | +
|
| 222 | + - name: Parse Submodule Outputs |
| 223 | + id: tags |
| 224 | + run: | |
| 225 | + echo "nvimTag=${{ steps.submodules.outputs[format('{0}--latestTag', env.nvim)] }}" >> "$GITHUB_OUTPUT" |
| 226 | + echo 'nvimPrBody<<EOF' >> $GITHUB_OUTPUT |
| 227 | + echo "${{ steps.submodules.outputs[format('{0}--prBody', env.nvim)] }}" >> "$GITHUB_OUTPUT" |
| 228 | + echo 'EOF' >> $GITHUB_OUTPUT |
| 229 | +
|
| 230 | + echo "mdBookTag=${{ steps.submodules.outputs[format('{0}--latestTag', env.mdBook)] }}" >> "$GITHUB_OUTPUT" |
| 231 | + echo 'mdBookPrBody<<EOF' >> $GITHUB_OUTPUT |
| 232 | + echo "${{ steps.submodules.outputs[format('{0}--prBody', env.mdBook)] }}" >> "$GITHUB_OUTPUT" |
| 233 | + echo 'EOF' >> $GITHUB_OUTPUT |
| 234 | +
|
| 235 | + - name: PR for Neovim |
| 236 | + uses: peter-evans/create-pull-request@v6 |
| 237 | + if: ${{ steps.tags.outputs.nvimTag }} |
| 238 | + with: |
| 239 | + add-paths: ${{ env.nvim }} |
| 240 | + commit-message: "feat: update catppuccin/nvim to ${{ steps.tags.outputs.nvimTag }}" |
| 241 | + branch: "feat/update-catppuccin-nvim-${{ steps.tags.outputs.nvimTag }}" |
| 242 | + title: "feat: update catppuccin/nvim submodule to ${{ steps.tags.outputs.nvimTag }}" |
| 243 | + body: ${{ steps.tags.outputs.nvimPrBody }} |
| 244 | +
|
| 245 | + - name: PR for mdBook |
| 246 | + uses: peter-evans/create-pull-request@v6 |
| 247 | + if: ${{ steps.tags.outputs.mdBookTag }} |
| 248 | + with: |
| 249 | + add-paths: ${{ env.mdBook }} |
| 250 | + commit-message: "feat: update catppuccin/mdBook to ${{ steps.tags.outputs.mdBookTag }}" |
| 251 | + branch: "feat/update-catppuccin-mdBook-${{ steps.tags.outputs.mdBookTag }}" |
| 252 | + title: "feat: update catppuccin/mdBook submodule to ${{ steps.tags.outputs.mdBookTag }}" |
| 253 | + body: ${{ steps.tags.outputs.mdBookPrBody }} |
| 254 | +``` |
| 255 | + |
| 256 | +</details> |
| 257 | + |
| 258 | +<!-- x-release-please-end --> |
| 259 | + |
| 260 | +## License |
| 261 | + |
| 262 | +[MIT](./LICENSE) |
0 commit comments