-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmove.sh
executable file
·127 lines (105 loc) · 3.28 KB
/
move.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
set -eu
scriptdir=$(cd $(dirname $0) && pwd)
target_repo=$scriptdir
# Delete the source packages
FOR_REAL=false
# --quick: do copy, but don't delete
full=true
if [[ ${1:-} == "--quick" ]]; then
full=false
fi
if [[ ! -d ../aws-cdk ]]; then
echo "Not all directories are in the right locations!" >&2
exit 1
fi
if $full; then
git clean -qfdx packages
mkdir -p packages/@aws-cdk
fi
move() {
source_root="$1"
source_dir="$2"
target_dir=$target_repo/$3
echo "Moving $source_dir => $target_dir"
$scriptdir/move-produce-file-list.sh $source_root $source_dir >> move-paths.txt
echo "rm -rf $source_root/$source_dir" >> move-delete-original.sh
if [[ "$3" != "$2" ]]; then
echo "mv $2 $3" >> move-rename-package.sh
echo "git add $3" >> move-rename-package.sh
fi
}
move_from_cdk() {
move "../aws-cdk" "$1" "packages/$2"
}
apply_moves() {
echo '------------------------------------------------------'
echo ' APPLY MOVES'
echo '------------------------------------------------------'
branch=testing-branch
(
cd $1
git checkout -b $branch origin/main || git checkout $branch
git reset --hard origin/main
git filter-repo --paths-from-file $scriptdir/move-paths.txt --refs $branch
git remote add target $target_repo || git remote set-url target $target_repo
git push target $branch --force
)
(
cd $target_repo
git merge $branch -m "chore: move original sources over" --allow-unrelated-histories
)
}
apply_renames() {
echo '------------------------------------------------------'
echo ' APPLY RENAMES'
echo '------------------------------------------------------'
(
cd $target_repo
/bin/bash $scriptdir/move-rename-packages.sh
git commit -am 'chore: rename packages to new locations'
)
}
apply_tags() {
echo '------------------------------------------------------'
echo ' APPLY TAGS FROM NPM VERSIONS'
echo '------------------------------------------------------'
(
cd $target_repo
# Get some versions from NPM and apply their versions as tags
# Set non-NPM packages to version 0.1.0 so projen doesn't fall into the "first release" workflow
merge_base=$(git merge-base HEAD main)
packages="$(cd packages && ls | grep -v @) $(cd packages && echo @*/*)"
for package in $packages; do
version=$(cd $TMPDIR && npm view $package version 2>/dev/null) || {
version=0.1.0
}
echo "${package}@v${version}"
git tag -f "${package}@v${version}" $merge_base
done
)
}
apply_deletes() {
echo '------------------------------------------------------'
echo ' APPLY DELETES'
echo '------------------------------------------------------'
(
cd $1
/bin/bash $scriptdir/move-delete-original.sh
git commit -am 'chore: move packages out'
)
}
# RESET
rm -f move-paths.txt
rm -f move-delete-original.sh
rm -f move-rename-packages.sh
touch move-rename-packages.sh
# COLLECT MOVES
move_from_cdk packages/@aws-cdk-testing/cli-integ @aws-cdk-testing/cli-integ
# APPLY_MOVES
apply_moves ../aws-cdk
apply_renames
if $FOR_REAL; then
apply_deletes ../aws-cdk
fi
apply_tags