Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,28 @@ jobs:
- uses: webfactory/ssh-agent@fc49353b67b2b7c1e0e6a600572d01a69f2672dd
with:
ssh-private-key: ${{ secrets[matrix.sshKey] }}

- name: Split monorepo
run: |
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The set -euxo pipefail flags should be explained with a comment, as the combination of these flags (especially -x for debug output) may produce verbose logs in CI and -u for undefined variables could cause unexpected failures if variables are intentionally unset.

Suggested change
run: |
run: |
# Enable strict error handling and verbose output:
# -e: exit on error
# -u: treat unset variables as errors (may cause failures if variables are intentionally unset)
# -x: print commands as they are executed (can produce verbose logs in CI)
# -o pipefail: fail pipelines if any command fails

Copilot uses AI. Check for mistakes.
set -euxo pipefail

ssh-add -l
docker build -t monorepo-tools ./bin
docker run -v $PWD:/monorepo -w /monorepo -v $SSH_AUTH_SOCK:/ssh-agent -v ~/.ssh/known_hosts:/root/.ssh/known_hosts -e SSH_AUTH_SOCK=/ssh-agent monorepo-tools bin/split-repo.sh . ${{ matrix.repo }} ${{ matrix.path }} ${{ matrix.name }}/ ${{ matrix.lastTag}}

# Resolve absolute paths on the host
WORKTREE="$PWD"
GITDIR="$(git rev-parse --git-dir)"
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This bash pattern matching syntax [[ "${GITDIR}" != /* ]] is checking if GITDIR is not an absolute path, but it would be clearer to add a comment explaining this logic since it's not immediately obvious what /* pattern matching does.

Suggested change
GITDIR="$(git rev-parse --git-dir)"
GITDIR="$(git rev-parse --git-dir)"
# If GITDIR is not an absolute path (does not start with '/'), prepend WORKTREE to make it absolute

Copilot uses AI. Check for mistakes.
[[ "${GITDIR}" != /* ]] && GITDIR="$WORKTREE/${GITDIR}"

echo "WORKTREE=${WORKTREE}"
echo "GITDIR=${GITDIR}"

# Run with identical absolute paths inside the container
docker run --rm \
-v "${WORKTREE}:${WORKTREE}" \
-v "${GITDIR}:${GITDIR}" \
-w "${WORKTREE}" \
-v "$SSH_AUTH_SOCK:/ssh-agent" \
-v "$HOME/.ssh/known_hosts:/root/.ssh/known_hosts" \
-e SSH_AUTH_SOCK=/ssh-agent \
monorepo-tools \
bin/split-repo.sh . "${{ matrix.repo }}" "${{ matrix.path }}" "${{ matrix.name }}/" "${{ matrix.lastTag }}"
3 changes: 2 additions & 1 deletion bin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ RUN echo "deb http://deb.debian.org/debian bookworm-backports main contrib non-f
python3-packaging \
&& mkdir -p ~/.ssh || true \
&& chmod 700 ~/.ssh/ \
&& ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
&& ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts \
&& git config --system --add safe.directory '*'
17 changes: 12 additions & 5 deletions bin/split-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ LIB_PATH="${3}"
TAG_PREFIX="${4}"
LAST_TAG_IN_SINGLEREPO="${5}"

# We require the source to be a local path because we use --mirror flag. The --mirror flag is needed on the other hand
# to copy all refs when doing a local clone.
if [[ ! -d "${SOURCE_REPO_PATH}/.git" ]]; then
echo ">> Splitting repo"
echo "Source repo: ${SOURCE_REPO_PATH}"
echo "Target repo: ${TARGET_REPO_URL}"
echo "Library path: ${LIB_PATH}"
echo "Tag prefix: ${TAG_PREFIX}"
echo "Last tag in singlerepo: ${LAST_TAG_IN_SINGLEREPO}"

if ! git -C "${SOURCE_REPO_PATH}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "Source repo '${SOURCE_REPO_PATH}' is not a valid GIT repository"
exit 1
fi
echo "Work tree: $(git -C "${SOURCE_REPO_PATH}" rev-parse --show-toplevel || true)"
echo "Git dir: $(git -C "${SOURCE_REPO_PATH}" rev-parse --git-dir || true)"

TMP_DIR=`mktemp -d`
WORK_DIR=`pwd`
Expand All @@ -37,8 +44,8 @@ clean_up () {
trap clean_up EXIT

echo ">> Cloning source repo '${SOURCE_REPO_PATH}'"
cd $TMP_DIR
git clone --no-local --mirror "${SOURCE_REPO_PATH}" $TMP_DIR
REAL_GIT_DIR="$(git -C "${SOURCE_REPO_PATH}" rev-parse --git-dir)"
git clone --no-local --mirror "${REAL_GIT_DIR}" "$TMP_DIR"

echo ">> Rebuild repo"
LIB_PATH="${LIB_PATH%/}/" # ensure trailing slash
Expand Down