Skip to content

Commit 18c067b

Browse files
committed
Make the synced repository configurable
The reusable `submodules-sync` workflow assumed its `dev-tools` submodule is a direct submodule of the repository whose submodules should be synced, and always acted on the repo one level up (`cd "$(git rev-parse --show-toplevel)/.."`). That breaks when `dev-tools` is nested more than one level deep — e.g. when a repository vendors another repository (which itself carries `dev-tools`) as a submodule. In that case the workflow enumerates and syncs the *inner* repository's submodules instead of the caller's. Add an optional `submodule_sync_root` input, piped through to `per-submodule-build-matrix.sh` as `SUBMODULE_SYNC_ROOT`, naming the repository directory to act on relative to the checkout root. When it is unset the workflow keeps its previous behavior, so existing callers are unaffected; a caller whose `dev-tools` is nested can pass e.g. "." to sync its own top-level submodules.
1 parent 9e5e864 commit 18c067b

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

.github/workflows/scripts/per-submodule-build-matrix.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
# We'll print some debug information along the way.
44
echo "Started in working directory '$(pwd)'..."
55

6-
# Assumption: this script is being run from _inside_ a submodule, but is
7-
# supposed to act on the repo that _contains_ that submodule. Change our working
8-
# directory accordingly.
9-
cd "$(git rev-parse --show-toplevel)/.."
6+
# Move to the repository whose submodules we want to sync. By default this
7+
# script assumes it runs from _inside_ a submodule and acts on the repo that
8+
# directly _contains_ that submodule (one level up). When the submodule is
9+
# nested more than one level deep, the caller can set `SUBMODULE_SYNC_ROOT` to
10+
# the target repository's directory (relative to the checkout root) to act on
11+
# that repository instead.
12+
if [ -n "${SUBMODULE_SYNC_ROOT:-}" ]; then
13+
cd "${GITHUB_WORKSPACE}/${SUBMODULE_SYNC_ROOT}"
14+
else
15+
cd "$(git rev-parse --show-toplevel)/.."
16+
fi
1017

1118
gitmodules_path="$(git rev-parse --show-toplevel)/.gitmodules"
1219
echo "Assumed relevant '.gitmodules' file is '$gitmodules_path'"

.github/workflows/submodules-sync.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,23 @@ on:
3030
devtools_directory:
3131
required: true
3232
type: string
33+
submodule_sync_root:
34+
description: >-
35+
Directory of the repository whose submodules to sync, relative to
36+
the checkout root. Defaults (empty) to the repository that directly
37+
contains the `dev-tools` submodule. Set it (for example to ".") when
38+
`dev-tools` is nested more than one level deep and the sync should
39+
act on an ancestor repository instead.
40+
required: false
41+
type: string
42+
default: ""
3343
secrets:
3444
private_repo_access_as_rebot_token:
3545
required: true
3646

3747
env:
3848
SCRIPTS_DIRECTORY: ${{ inputs.devtools_directory }}/.github/workflows/scripts
49+
SUBMODULE_SYNC_ROOT: ${{ inputs.submodule_sync_root }}
3950

4051
jobs:
4152
# Since we want to create one PR per each submodule on submodule change

0 commit comments

Comments
 (0)