Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More build script fixes and tweaks #9

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions build-release.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,37 +1,57 @@
#!/bin/sh
#!/usr/bin/env bash

branch_name="$(git symbolic-ref --short -q HEAD)"
version="v$(jq -r .version package.json)"
set -euf -o pipefail

set +u
repo="$1"
set -u

# Uncomment the following line to help when debugging
# set -x

# Make sure all dependencies exist
which curl
which git
which jq
which npm
which sed

if [ -z "$repo" ]; then
branch_name="$(git symbolic-ref --short -q HEAD)"
_version_without_v="$(jq -r .version package.json)"
# A quick sanity check to make sure
# that _version_without_v is not
# empty.
version="v${_version_without_v:?}"

if [ -z "${repo}" ]; then
echo "ERROR: must specify repository"
echo "Usage: ./bin/build-release.sh orgname/reponame"
exit 1
fi

echo "=== debug info ==="
echo "branch: $branch_name"
echo "version: $version"
echo "repo: $repo"
echo "branch: ${branch_name:?}"
echo "version: ${version:?}"
echo "repo: ${repo:?}"
echo "ostype: ${OSTYPE:?}"
echo "=================="
echo ""

# Check that the version doesn't exist yet
version_exists="$(curl -s https://api.github.com/repos/"$repo"/tags -H "Accept: application/vnd.github.v3.full+json" | jq -r '.[] | select(.name == "'"$version"'") | .name')"
if [ -n "$version_exists" ]; then
echo "ERROR: version $version already exists"
if [ -n "${version_exists}" ]; then # We intentionall don't do `:?` here, because we know `version_exists` might be empty
echo "ERROR: version ${version:?} already exists"
exit 1
fi

git checkout -b releases/"$version"
git checkout -b releases/"${version:?}"

npm install
npm run build
npm test
npm run pack


if [[ "${OSTYPE:}" == "darwin"* ]]; then
if [[ "${OSTYPE:?}" == "darwin"* ]]; then
sed -i '' 's/dist/!dist/g' .gitignore
else
sed -i 's/dist/!dist/g' .gitignore
Expand All @@ -43,7 +63,10 @@ git commit -a -m "Add production dependencies & build"
major_minor="$(sed 's/\.[^.]*$//' <<< "$version")"
major="$(sed 's/\.[^.]*$//' <<< "$major_minor")"

git tag "$version"
git tag -f "$major_minor"
git tag -f "$major"
# For this tag, we intentionally do NOT force tag:
git tag "${version:?}"

# For the remaining tags, we need to force tag:
git tag -f "${major_minor:?}"
git tag -f "${major:?}"
git tag -f "latest"