-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrelease.sh
executable file
·201 lines (167 loc) · 5.57 KB
/
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
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
set -ex
REPO_DIR=$(dirname "$0")
cd $REPO_DIR
VERSION=$1
if [[ -z "$VERSION" ]]; then
echo "Please provide a version number"
exit 1
fi
PART=$2
if [[ -z "$PART" ]]; then
PART=all
elif [[ $PART != 'website' && $PART != 'package' && $PART != 'crate' ]]; then
echo "2nd argument must be 'website', 'package' or 'crate'"
exit 1
fi
# Check dependencies
if ! type llvm-lipo-14 >/dev/null 2>&1; then
echo "'llvm-lipo-14' not installed"
exit 1
fi
if ! type cross >/dev/null 2>&1; then
echo "'cross' not installed"
exit 1
fi
if ! type gh >/dev/null 2>&1; then
echo "'gh' not installed"
exit 1
fi
# Make sure we've got git setup right
CURRENT_BRANCH=$(git branch --show-current)
if [ "$CURRENT_BRANCH" != 'master' ]; then
echo "Need to be on master branch"
exit 1
fi
WEB_PATH=$(git worktree list | grep -F "gh-pages" | awk '{print $1}')
if [[ -z "$WEB_PATH" ]]; then
echo "Creating gh-pages worktree"
git worktree add gh-pages gh-pages
WEB_PATH="gh-pages"
fi
echo "All checks passed"
cargo set-version "$VERSION"
if [[ $PART == 'all' || $PART == 'package' ]]; then
rm -rf target/sublime-package
mkdir target/sublime-package
ARTIFACTS=()
# Compile CLI for all platforms
TARGETS=(
"x86_64-unknown-linux-gnu"
"aarch64-unknown-linux-gnu"
"x86_64-apple-darwin"
"aarch64-apple-darwin"
"x86_64-pc-windows-msvc"
"i686-pc-windows-msvc"
)
for TARGET in "${TARGETS[@]}"; do
cross build --target $TARGET --release
if [[ "$TARGET" == *windows* ]]; then
cp target/$TARGET/release/sbnf.exe target/sublime-package/sbnf-$TARGET.exe
zip -FS -Dj "target/sbnf-$TARGET.zip" target/$TARGET/release/sbnf.exe
ARTIFACTS+=("target/sbnf-$TARGET.zip")
elif [[ "$TARGET" == *linux* ]]; then
cp target/$TARGET/release/sbnf target/sublime-package/sbnf-$TARGET
tar -cJf "target/sbnf-$TARGET.tar.xz" -C target/$TARGET/release sbnf
ARTIFACTS+=("target/sbnf-$TARGET.tar.xz")
elif [[ "$TARGET" == *apple* ]]; then
zip -FS -Dj "target/sbnf-$TARGET.zip" target/$TARGET/release/sbnf
ARTIFACTS+=("target/sbnf-$TARGET.zip")
fi
done
# Make universal binary for macOS
mkdir -p target/universal-apple-darwin
llvm-lipo-14 -create -output target/universal-apple-darwin/sbnf \
target/x86_64-apple-darwin/release/sbnf target/aarch64-apple-darwin/release/sbnf
cp target/universal-apple-darwin/sbnf target/sublime-package/sbnf-universal-apple-darwin
zip -FS -Dj "target/sbnf-universal-apple-darwin.zip" target/universal-apple-darwin/sbnf
ARTIFACTS+=("target/sbnf-universal-apple-darwin.zip")
# Compile SBNF syntax
cargo run --release -- sbnf/sbnf.sbnf -o target/sublime-package/sbnf.sublime-syntax
# Copy other files
SYNTAX_SOURCES=(
"package_control/sbnf-linux-universal.sh"
"package_control/sbnf-windows-universal.bat"
"package_control/sbnf.sublime-build"
"sbnf/Comments.tmPreferences"
"sbnf/sbnf.sublime-completions"
"sbnf/sbnf.sublime-settings"
"sbnf/sbnf.sublime-settings"
"sbnf/Symbol Index.tmPreferences"
)
for F in "${SYNTAX_SOURCES[@]}"; do
cp "$F" target/sublime-package/
done
touch target/sublime-package/.no-sublime-package
cd target/sublime-package
zip -FS -r ../SBNF.sublime-package * .[!.]*
cd -
ARTIFACTS+=("target/SBNF.sublime-package")
cat >package_control/packages.json <<EOF
{
"schema_version": "3.0.0",
"packages": [
{
"name": "SBNF",
"description": "A BNF-style language for writing sublime-syntax files",
"author": "Benjamin Schaaf",
"homepage": "https://github.com/BenjaminSchaaf/sbnf",
"readme": "https://raw.githubusercontent.com/BenjaminSchaaf/sbnf/master/README.md",
"releases": [
{
"sublime_text": ">4077",
"version": "$VERSION",
"url": "https://github.com/BenjaminSchaaf/sbnf/releases/download/$VERSION/SBNF.sublime-package",
"date": "$(date -u "+%Y-%m-%d %H:%M:%S")"
}
]
}
]
}
EOF
fi
if [[ $PART == 'all' || $PART == 'website' ]]; then
# Build website
python3 wasm/build-playground.py --release "$WEB_PATH"
fi
# Prepare Release
if [[ $PART == 'all' || $PART == 'crate' || $PART == 'package' ]]; then
git add package_control/packages.json
git add Cargo.toml
git add Cargo.lock
git add cli/Cargo.toml
git add wasm/Cargo.toml
git status
git commit -m "Release $VERSION"
git tag "$VERSION"
fi
if [[ $PART == 'all' || $PART == 'website' ]]; then
cd "$WEB_PATH"
git add -A
git status
git commit -m "Release $VERSION"
cd -
fi
# Do release after confirmation
echo "Release Prepared"
read -p "Do you want to continue? (y/Y): " CONFIRMATION
if [[ $CONFIRMATION == 'y' || $CONFIRMATION == 'Y' ]]; then
if [[ $PART == 'all' || $PART == 'package' ]]; then
git push origin "$VERSION"
gh release create "$VERSION" "${ARTIFACTS[@]}"
# Push master after release to make sure packages.json is always valid
git push origin master
fi
if [[ $PART == 'all' || $PART == 'crate' ]]; then
cargo publish -p sbnf
cargo publish -p sbnfc
fi
if [[ $PART == 'all' || $PART == 'website' ]]; then
cd "$WEB_PATH"
git push
cd -
fi
else
echo "Cancelled. Cleanup is left to you"
exit 1
fi