Skip to content

Commit 88470bd

Browse files
authored
feat!: update to latest commit by default (#8)
Submodules are now updated to the latest commit by default. A new input 'strategy' that controls if submodules should be updated to the latest commit or tag. It can either be 'commit' or 'tag', and defaulted to 'commit'. feat: add output `updated` A new output which always returns 'true' to indicate which submodules have been updated.
1 parent fb5cbfe commit 88470bd

File tree

16 files changed

+5486
-660
lines changed

16 files changed

+5486
-660
lines changed

README.md

Lines changed: 99 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,20 @@
44
</h1>
55

66
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.
7+
latest commit or tag. The primary use case for this action is to be used across
8+
[Catppuccin](https://github.com/catppuccin), allowing repositories to update
9+
their submodules to the latest git tag instead of the latest commit.
1110

1211
### What it does
1312

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.
13+
- It automatically parses the `.gitmodules` file to find submodules.
14+
- It updates one or more submodules to the latest commit or git tag.
15+
- It allows the user to filter which submodules to update.
1716

1817
### What it doesn't do
1918

2019
- 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.
20+
see the "[Creating Pull Requests](#creating-pull-requests)" section for examples on how to do this.
2721

2822
## Usage
2923

@@ -37,6 +31,11 @@ latest commit.
3731
# Defaults to '.gitmodules' in the root of the repository.
3832
gitmodulesPath: ""
3933

34+
# The strategy to use when updating the submodules. Can be either 'commit' or 'tag'.
35+
#
36+
# Defaults to 'commit'.
37+
strategy: ""
38+
4039
# The git submodule(s) to update, the path should be the
4140
# same as the one specified in the '.gitmodules' file.
4241
#
@@ -51,54 +50,91 @@ latest commit.
5150
- `json`: A JSON array containing all the submodules that were updated.
5251
- `matrix`: A JSON array containing all the submodules that were updated,
5352
intended for use in a GitHub Actions matrix strategy.
54-
- `prBody`: A Markdown string containing a formatted table of all the submodules
53+
- `prBody`: A multi-line Markdown string containing a formatted table of all the submodules
5554
that were updated, intended for use in a pull request body.
5655

5756
### Dynamic Outputs
5857

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-
58+
As well as the static outputs, this action will also output the following
59+
variables for each submodule that was updated:
60+
61+
- `${prefix}--updated`: Always set to `true` to indicate that the submodule was updated.
62+
- `${prefix}--path`: The path to the submodule that was updated.
63+
- `${prefix}--url`: The GitHub URL of the submodule that was updated.
64+
- `${prefix}--previousShortCommitSha`: The short commit SHA of the submodule
65+
before it was updated.
66+
- `${prefix}--previousCommitSha`: The commit SHA of the submodule before it
67+
was updated.
68+
- `${prefix}--latestShortCommitSha`: The short commit SHA of the submodule
69+
after it was updated.
70+
- `${prefix}--latestCommitSha`: The commit SHA of the submodule after it was
71+
updated.
72+
- `${prefix}--previousTag`: The tag of the submodule before it was updated. **May not exist if the submodule does not have any tags.**
73+
- `${prefix}--latestTag`: The tag that the submodule was updated to. **Only available when the strategy is set to 'tag'.**
74+
- `${prefix}--prBody`: A multi-line Markdown string intended for use in a pull request body.
75+
76+
The `${prefix}` is the submodule name or the submodule path if the name is
77+
different to the path. For example, if the submodule is named `vscode-icons` and
78+
the path is `ports/vscode-icons`, the dynamic outputs will be:
79+
80+
- `vscode-icons--updated`
7481
- `vscode-icons--path`
7582
- `vscode-icons--url`
83+
- `vscode-icons--previousShortCommitSha`
84+
- `vscode-icons--previousCommitSha`
85+
- `vscode-icons--latestShortCommitSha`
86+
- `vscode-icons--latestCommitSha`
7687
- `vscode-icons--previousTag`
7788
- `vscode-icons--latestTag`
7889
- `vscode-icons--prBody`
90+
- `ports/vscode-icons--updated`
7991
- `ports/vscode-icons--path`
8092
- `ports/vscode-icons--url`
93+
- `ports/vscode-icons--previousShortCommitSha`
94+
- `ports/vscode-icons--previousCommitSha`
95+
- `ports/vscode-icons--latestShortCommitSha`
96+
- `ports/vscode-icons--latestCommitSha`
8197
- `ports/vscode-icons--previousTag`
8298
- `ports/vscode-icons--latestTag`
8399
- `ports/vscode-icons--prBody`
84100

85-
## Scenarios
101+
## Examples
86102

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)
103+
### Update all submodules to the latest commit
104+
105+
```yaml
106+
- name: Update Submodules
107+
id: submodules
108+
uses: sgoudham/[email protected]
109+
```
110+
111+
### Update all submodules to the latest tag
90112

91-
### Update one submodule and create one pull request
113+
```yaml
114+
- name: Update Submodules
115+
id: submodules
116+
uses: sgoudham/[email protected]
117+
with:
118+
strategy: "tag"
119+
```
92120

93-
`.gitmodules`
121+
### Update single submodule
94122

95-
```ini
96-
[submodule "vscode-icons"]
97-
path = ports/vscode-icons
98-
url = https://github.com/catppuccin/vscode-icons.git
123+
```yaml
124+
- name: Update Submodule
125+
id: submodules
126+
uses: sgoudham/[email protected]
127+
with:
128+
submodules: ports/vscode-icons
99129
```
100130

101-
`workflow.yml`
131+
## Creating Pull Requests
132+
133+
1. [Update single submodule and create pull request](#update-single-submodule-and-create-pull-request)
134+
2. [Update multiple submodules and create one pull request](#update-multiple-submodules-and-create-one-pull-request)
135+
3. [Update multiple submodules and create multiple pull requests](#update-multiple-submodules-and-create-multiple-pull-requests)
136+
137+
### Update single submodule and create pull request
102138

103139
```yaml
104140
steps:
@@ -110,15 +146,15 @@ steps:
110146
111147
- name: Update Submodules
112148
id: submodules
113-
uses: "sgoudham/[email protected]"
149+
uses: sgoudham/[email protected]
114150
115151
- name: Create PR
116152
uses: peter-evans/create-pull-request@v6
117-
if: ${{ steps.submodules.outputs['vscode-icons--latestTag'] }}
153+
if: ${{ steps.submodules.outputs['vscode-icons--updated'] }}
118154
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'] }}"
155+
commit-message: "feat: update catppuccin/vscode-icons to ${{ steps.submodules.outputs['vscode-icons--latestShortCommitSha'] }}"
156+
branch: "feat/update-vscode-icons-${{ steps.submodules.outputs['vscode-icons--latestShortCommitSha'] }}"
157+
title: "feat: update catppuccin/vscode-icons submodule to ${{ steps.submodules.outputs['vscode-icons--latestShortCommitSha'] }}"
122158
body: ${{ steps.submodules.outputs.prBody }}
123159
```
124160

@@ -134,7 +170,7 @@ steps:
134170
135171
- name: Update Submodules
136172
id: submodules
137-
uses: "sgoudham/[email protected]"
173+
uses: sgoudham/[email protected]
138174
139175
- name: Create PR
140176
uses: peter-evans/create-pull-request@v6
@@ -147,20 +183,6 @@ steps:
147183

148184
### Update multiple submodules and create multiple pull requests
149185

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-
164186
`workflow.yml`
165187

166188
```yaml
@@ -169,7 +191,17 @@ jobs:
169191
runs-on: ubuntu-latest
170192
strategy:
171193
matrix:
172-
submodule: [ports/nvim, ports/mdBook]
194+
submodule: [ports/nvim, ports/mdBook, ports/vscode-icons]
195+
include:
196+
- submodule: ports/nvim # Update to the latest tag
197+
strategy: "tag"
198+
latest: "latestTag"
199+
- submodule: ports/mdBook # Update to the latest commit
200+
strategy: "commit"
201+
latest: "latestShortCommitSha"
202+
- submodule: ports/vscode-icons # Update to the latest commit
203+
strategy: "commit"
204+
latest: "latestShortCommitSha"
173205
steps:
174206
- name: Checkout Repository
175207
uses: actions/checkout@v4
@@ -179,82 +211,21 @@ jobs:
179211
180212
- name: Update Submodules
181213
id: submodules
182-
uses: "sgoudham/[email protected]"
214+
uses: sgoudham/[email protected]
183215
with:
184216
submodules: ${{ matrix.submodule }}
217+
strategy: ${{ matrix.strategy }}
185218
186219
- name: Create PR
187220
uses: peter-evans/create-pull-request@v6
188-
if: ${{ steps.submodules.outputs[format('{0}--latestTag', matrix.submodule)] }}
221+
if: ${{ steps.submodules.outputs[format('{0}--updated', matrix.submodule)] }}
189222
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)] }}"
223+
commit-message: "feat: update ${{ matrix.submodule }} to ${{ steps.submodules.outputs[format('{0}--{1}', matrix.submodule, matrix.latest)] }}"
224+
branch: "feat/update-${{ matrix.submodule }}-${{ steps.submodules.outputs[format('{0}--{1}', matrix.submodule, matrix.latest)] }}"
225+
title: "feat: update ${{ matrix.submodule }} submodule to ${{ steps.submodules.outputs[format('{0}--{1}', matrix.submodule, matrix.latest)] }}"
193226
body: ${{ steps.submodules.outputs.prBody }}
194227
```
195228

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-
258229
<!-- x-release-please-end -->
259230

260231
## License

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
name: "update-git-submodules"
2-
description: "Update git submodule(s) to their latest tag"
2+
description: "Update git submodule(s) to their latest commit or tag"
33
author: "sgoudham"
44

55
inputs:
66
gitmodulesPath:
77
description: "The path to the '.gitmodules' file. Defaults to '.gitmodules' in the root of the repository."
88
required: false
99
default: ".gitmodules"
10+
strategy:
11+
description: "The strategy to use when updating the submodules, can be either 'commit' or 'tag'. Defaults to 'commit'"
12+
required: false
13+
default: "commit"
1014
submodules:
1115
description: "The submodules to update. Defaults to all submodules in the '.gitmodules' file."
1216
required: false

0 commit comments

Comments
 (0)