Skip to content

Commit

Permalink
Release v2
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminSchaaf committed Oct 9, 2023
1 parent 330b23e commit 01b364f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 39 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
110 changes: 71 additions & 39 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ if ! type cross >/dev/null 2>&1; then
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
Expand All @@ -45,13 +50,6 @@ if [[ -z "$WEB_PATH" ]]; then
WEB_PATH="gh-pages"
fi

RELEASE_PATH=$(git worktree list | grep -F "package" | awk '{print $1}')
if [[ -z "$RELEASE_PATH" ]]; then
echo "Creating package worktree"
git worktree add package package
RELEASE_PATH="package"
fi

echo "All checks passed"

cargo set-version "$VERSION"
Expand All @@ -60,6 +58,8 @@ 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"
Expand All @@ -74,62 +74,93 @@ if [[ $PART == 'all' || $PART == 'package' ]]; then

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
llvm-lipo-14 -create -output target/sublime-package/sbnf-universal-apple-darwin \
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=(
"Comments.tmPreferences"
"sbnf.sublime-completions"
"sbnf.sublime-settings"
"sbnf-linux-universal.sh"
"sbnf-windows-universal.bat"
"sbnf.sublime-settings"
"Symbol Index.tmPreferences"
"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 "sbnf/$F" target/sublime-package/
cp "$F" target/sublime-package/
done
cp sbnf/sbnf.sublime-build-release target/sublime-package/sbnf.sublime-build
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

if [[ $PART == 'all' || $PART == 'package' ]]; then
# Copy package to release worktree
rsync -a --delete --exclude=.git target/sublime-package/ "$RELEASE_PATH"
fi

# Prepare Release
if [[ $PART == 'all' || $PART == 'crate' ]]; then
git status
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 commit -m "Release $VERSION"
fi

if [[ $PART == 'all' || $PART == 'package' ]]; then
cd "$RELEASE_PATH"
git add -A
git status
git commit -m "Release $VERSION"
git tag "$VERSION"
cd -
fi

if [[ $PART == 'all' || $PART == 'website' ]]; then
Expand All @@ -145,19 +176,20 @@ 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
git push
cargo publish -p sbnf
cargo publish -p sbnfc
fi

if [[ $PART == 'all' || $PART == 'package' ]]; then
cd "$RELEASE_PATH"
git push
git push origin "$VERSION"
cd -
fi

if [[ $PART == 'all' || $PART == 'website' ]]; then
cd "$WEB_PATH"
git push
Expand Down

0 comments on commit 01b364f

Please sign in to comment.