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

task/MOB4 publish script #37

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions payment_sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build": "npm run build:js && npm run build:types && npm pack",
"build:js": "babel src --out-dir dist --extensions \".ts,.tsx\" --copy-files",
"build:types": "tsc --emitDeclarationOnly && tsc-alias",
"release": "./scripts/publish.sh",
"test": "jest",
"lint": "eslint ."
},
Expand Down
114 changes: 114 additions & 0 deletions payment_sdk/scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

RELEASE_TYPE=${1:-}

echo_help() {
cat << EOF
USAGE:
./scripts/publish <release_type>
ARGS:
<release_type>
A Semantic Versioning release type used to bump the version number. Either "patch", "minor", or "major".
EOF
}

create_github_release() {
local current_version=$(node -p "require('./package.json').version")
local release_notes="v$current_version

Please see the [CHANGELOG.md](https://github.com/degica/mobile-sdk_react-native/blob/master/CHANGELOG.md) for details on this release."

if which hub | grep -q "not found"; then
create_github_release_fallback "$release_notes"
else
echo "Creating GitHub release for tag: v$current_version"
echo ""
echo -n " "
hub release create -em "$release_notes" "v$current_version"
fi
}

create_github_release_fallback() {
local release_notes=$1
cat << EOF
Remember to create a release on GitHub at https://github.com/degica/mobile-sdk_react-native/releases/new with the following notes:
$release_notes
EOF
}

# Show help if no arguments passed
if [ $# -eq 0 ]; then
echo "Error! Missing release type argument"
echo ""
echo_help
exit 1
fi

# Show help message if -h, --help, or help passed
case $1 in
-h | --help | help)
echo_help
exit 0
;;
esac

# Validate passed release type
case $RELEASE_TYPE in
patch | minor | major)
;;
*)
echo "Error! Invalid release type supplied"
echo ""
echo_help
exit 1
;;
esac

# Make sure our working dir is the repo root directory
cd "$(git rev-parse --show-toplevel)"

echo "Fetching git remotes"
git fetch

GIT_STATUS=$(git status)
if ! grep -q 'On branch master' <<< "$GIT_STATUS"; then
echo "Error! Must be on master branch to publish"
exit 1
fi

if ! grep -q "Your branch is up to date with 'origin/master'." <<< "$GIT_STATUS"; then
echo "Error! Must be up to date with origin/master to publish"
exit 1
fi

if ! grep -q 'working tree clean' <<< "$GIT_STATUS"; then
echo "Error! Cannot publish with dirty working tree"
exit 1
fi

echo "Installing dependencies"
npm ci

echo "Running tests"
npm run test

echo "Building the project"
npm run build

echo "Bumping package.json $RELEASE_TYPE version and tagging commit"
npm version $RELEASE_TYPE

echo "Publishing release to npm"
npm publish --access=public

echo "Pushing git commit and tag"
git push --follow-tags

echo "Publish successful!"
echo ""

create_github_release

echo "Done!"
Loading