Skip to content

Commit

Permalink
ci: smarten script
Browse files Browse the repository at this point in the history
  • Loading branch information
smeijer committed Dec 20, 2024
1 parent 2380d8f commit ea3e0c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"changeset": "./scripts/changeset.sh",
"changeset:postversion": "tsx scripts/update-version.ts",
"codegen": "tsx scripts/liblab-gen.ts",
"build:docs": "tsx scripts/liblab-docs.ts"
},
Expand Down
37 changes: 18 additions & 19 deletions scripts/changeset.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#!/usr/bin/env bash

# make sure the script runs relative to the repo root
set -euo pipefail && cd "$(dirname "${BASH_SOURCE[0]}")/.."
# Ensure script runs relative to the repo root
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."

# some helpers and error handling:
info() { printf "%s\n" "$*" >&1; }
error() { printf "%s\n" "$*" >&2; }
trap 'echo Changeset interrupted >&2; exit 2' INT TERM
# Trap signals for graceful exit
trap 'echo "Script interrupted" >&2; exit 2' INT TERM

# pass all arguments to changeset
./node_modules/.bin/changeset "$@"
# Run changeset with passed arguments
npx changeset "$@"
exitCode=$?

changeset_exit=$?
if [ ${changeset_exit} -gt 0 ];
then
error "Changeset finished with error"
exit ${changeset_exit}
if [ $exitCode -ne 0 ]; then
echo "Changeset finished with error" >&2
exit $exitCode
fi

# if first argument was `version` also run the `update-version.ts` script
args=("$@")
info "args: ${args[@]}"
if [ $# -gt 0 ] && [ ${args[0]} = "version" ]
then
yarn tsx scripts/update-version.ts
# Handle "post" scripts if arguments are provided
if [ $# -gt 0 ]; then
command="$1"
shift # Remove the first argument from $@
script="changeset:post${command}"
echo "Running post script: ${script}"
npm run "${script}" --if-present -- "$@"
fi

0 comments on commit ea3e0c1

Please sign in to comment.