-
Notifications
You must be signed in to change notification settings - Fork 74
/
new-release.sh
executable file
·193 lines (152 loc) · 4.88 KB
/
new-release.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env bash
set -euxo pipefail
ErrorReleaseExists=2
ErrorReleaseArgMissing=3
ErrorReleaseTagExists=4
AppName=RnDiffApp
AppBaseBranch=app-base
ReleasesFile=RELEASES
ReadmeFile=README.md
ReadmeTable=README_TABLE.md
ReadmeTableBig=README_TABLE_BIG.md
NumberOfReleases=12 # the number of releases on the table
IgnorePaths=("README.md")
function guardMissingArg () {
if [ "$#" -ne 1 ]; then
echo "Release argument missing."
exit "$ErrorReleaseArgMissing"
fi
}
function guardExisting () {
if grep -qFx "$newRelease" "$ReleasesFile"; then
echo "Release $newRelease already exists!"
exit "$ErrorReleaseExists"
fi
if [ $(git tag -l "version/$newRelease") ]; then
echo "Release tag version/$newRelease already exists!"
exit "$ErrorReleaseTagExists"
fi
}
function prepare () {
# This git config setting, in combination with the `.gitattributes` file, tells the scripts to not pay attention to some files that don't need to be in the diffs, like the root `.gitignore` of this repo (not the RnDiffApp project).
git config --local diff.nodiff.command true
git pull
npm install
}
function generateNewReleaseBranch () {
# go to the base app branch
git worktree add wt-app "$AppBaseBranch"
cd wt-app
# clear any existing stuff
rm -rf "$AppName"
git pull
# make a new branch
branchName=release/"$newRelease"
git branch -D "$branchName" || true
git checkout -b "$branchName"
# generate app and remove generated git repo
# if we're generating the template for an -rc release, let's grab cli@next
if [[ $newRelease == *-rc* ]]; then
npx @react-native-community/cli@next init "$AppName" --version "$newRelease" --skip-install
else
npx @react-native-community/cli@latest init "$AppName" --version "$newRelease" --skip-install
fi
# clean up before committing for diffing
rm -rf "$AppName"/.git
# commit and push branch
git add "$AppName"
git commit -m "Release $newRelease"
git push origin --delete "$branchName" || git push origin "$branchName"
git tag "version/$newRelease" # @react-native-community/cli needs this
git push --set-upstream origin "$branchName" --tags
# go back to master
cd ..
rm -rf wt-app
git worktree prune
}
function addReleaseToList () {
echo "$newRelease" >> "$ReleasesFile"
if command -v tac; then
# take each line ->dedup-> sort them -> reverse them -> save them
cat "$ReleasesFile" | uniq | xargs npx --silent semver | tac > tmpfile
else
# take each line ->dedup-> sort them -> reverse them -> save them
cat "$ReleasesFile" | uniq | xargs npx --silent semver | tail -r > tmpfile
fi
mv tmpfile "$ReleasesFile"
}
function generateDiffs () {
if [ ! -d wt-diffs ]; then
git worktree add wt-diffs diffs
fi
cd wt-diffs
git pull
cd ..
IFS=$'\n' GLOBIGNORE='*' command eval 'releases=($(cat "$ReleasesFile"))'
for existingRelease in "${releases[@]}"
do
if [ "$existingRelease" == "$newRelease" ]; then
continue
fi
if ./scripts/compare-releases.js "$existingRelease" "$newRelease"; then
continue
fi
ignoreArgs=()
for path in "${IgnorePaths[@]}"; do
ignoreArgs+=(":!$path")
done
git diff --binary -w -M15% origin/release/"$existingRelease"..origin/release/"$newRelease" \
-- . "${ignoreArgs[@]}" > wt-diffs/diffs/"$existingRelease".."$newRelease".diff
done
cd wt-diffs
git add .
git commit -m "Add release $newRelease diffs" || true
git push
cd ..
}
function pushMaster () {
git add .
git commit -m "Add release $newRelease"
git push
}
function generateTable () {
head -n "$NumberOfReleases" "$ReleasesFile" | ./scripts/generate-table.js > "$ReadmeTable"
}
function generateBigTable () {
cat "$ReleasesFile" | ./scripts/generate-table.js --big > "$ReadmeTableBig"
}
ReadmeHeader=README_HEADER.md
ReadmeFooter=README_FOOTER.md
function breakUpReadme () {
perl -p0e 's/(.*## Diff table[^\n]*\n\n)(.*)/$1/smg' "$ReadmeFile" > "$ReadmeHeader"
perl -p0e 's/(.*)(\n## To see.*)/$2/smg' "$ReadmeFile" > "$ReadmeFooter"
}
function makeUpReadme () {
cat "$ReadmeHeader" "$ReadmeTable" "$ReadmeFooter" > "$ReadmeFile"
}
function generateReadme () {
breakUpReadme
makeUpReadme
}
function generateGHPages () {
cp docs/_index.html docs/index.html
npx markdown "$ReadmeTableBig" >> docs/index.html
}
function cleanUp () {
rm -rf "$ReadmeHeader" "$ReadmeFooter" "$ReadmeTable" "$ReadmeTableBig"
rm -rf wt-app
git worktree prune
}
guardMissingArg $*
newRelease=${1#v}
guardExisting
prepare
generateNewReleaseBranch
addReleaseToList
generateDiffs
generateTable
generateReadme
generateBigTable
generateGHPages
cleanUp
pushMaster