Skip to content

Commit 5806dd8

Browse files
committed
build(git): update sync scripts
1 parent b1ddf8d commit 5806dd8

File tree

5 files changed

+53
-102
lines changed

5 files changed

+53
-102
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
"format:check": "prettier --check .",
2121
"phpcs": "./drupal/vendor/bin/phpcs -p -s --colors --standard=modules/next/phpcs.xml modules/next",
2222
"test:next": "SIMPLETEST_DB=sqlite://localhost/:memory: ./drupal/vendor/bin/phpunit -c ./drupal/web/core modules/next",
23-
"sync:modules": "./scripts/sync-modules.sh \"modules/*\"",
24-
"sync:examples": "./scripts/sync-examples.sh \"examples/example-*\"",
25-
"sync:starters": "./scripts/sync-starters.sh \"starters/*\"",
23+
"sync:modules": "./scripts/sync-repo.sh 1.0.x git@git.drupal.org:project/ \"modules/*\"",
24+
"sync:examples": "./scripts/sync-repo.sh main https://github.com/chapter-three/next- \"examples/example-*\"",
25+
"sync:starters": "./scripts/sync-repo.sh canary https://github.com/chapter-three/next-drupal- \"starters/*\"",
26+
"sync:starters:release": "./scripts/sync-repo.sh canary,main https://github.com/chapter-three/next-drupal- \"starters/*\"",
2627
"seed": "NUM_NODES=200 node ./scripts/seed",
2728
"cy:open": "turbo run cy:open --parallel",
2829
"test": "yarn workspace next-drupal test && yarn workspace next-drupal-query test",

scripts/sync-examples.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

scripts/sync-modules.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

scripts/sync-repo.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# Script to sync packages to read-only git clones
4+
#
5+
# This handles file deletions, additions, and changes seamlessly
6+
7+
set -e # bail on errors
8+
9+
BRANCHES=$1
10+
REPO=$2
11+
GLOB=$3
12+
13+
# Allow BRANCHES to be a comma-seperated list.
14+
BRANCH=$(echo $BRANCHES | cut -d "," -f 1)
15+
TRACKING_BRANCH=$(echo $BRANCHES | cut -d "," -f 2)
16+
17+
BASE=$(pwd)
18+
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
19+
20+
for folder in $GLOB; do
21+
[ -d "$folder" ] || continue
22+
cd $BASE
23+
24+
NAME=${folder##*/}
25+
CLONE_DIR="__${NAME}__clone__"
26+
27+
# Note: redirect output to dev/null to avoid any possibility of leaking token
28+
git clone --quiet --depth 1 --branch ${BRANCH} ${REPO}${NAME}.git $CLONE_DIR > /dev/null
29+
cd $CLONE_DIR
30+
31+
# Delete all files (to handle deletions in monorepo)
32+
find . | grep -v ".git" | grep -v "^\.*$" | xargs rm -rf
33+
34+
# Copy new files to the clone
35+
cp -r $BASE/$folder/. .
36+
37+
if [ -n "$(git status --porcelain)" ]; then
38+
git add .
39+
git commit -m "$COMMIT_MESSAGE"
40+
git push origin ${BRANCH}
41+
fi
42+
43+
if [ "$TRACKING_BRANCH" != "$BRANCH" ]; then
44+
git push origin ${BRANCH}:${TRACKING_BRANCH}
45+
fi
46+
47+
cd $BASE
48+
rm -rf $CLONE_DIR
49+
done

scripts/sync-starters.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)