Skip to content

Commit

Permalink
Merge pull request #35 from replit/dstewart/chore/set-metadata-script
Browse files Browse the repository at this point in the history
Adding a helpful script to automate some of the tedium around doing updates
  • Loading branch information
blast-hardcheese authored Mar 18, 2024
2 parents 4334e90 + 74543f8 commit fe6c3e4
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions scripts/set-metadata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# set-metadata.sh
# A script to help reduce easily avoidable merge conflicts during upgrades.
#
# Usage, presuming we are currently on our release 2.0.8,
# tracking upstream 1.1.353 with the intent to bump to 1.1.354:
#
# $ scripts/set-metadata.sh them 1.1.353 # Revert to the last checkpoint
# $ npm install # Regenerate lockfile
# $ git merge --no-edit 1.1.354 # Sync to desired tag
# $ scripts/set-metadata.sh us 2.0.9 # Reset metadata to next release
# $ npm install # Regenerate lockfile

die() {
echo "$@" >&2
exit 1
}

modify_packages() {
target="packages/pyright/package.json"
while [ -n "$1" ]; do
case "$1" in
--name)
name="$2"; shift 2 || die 'Missing name'
;;
--displayName)
displayName="$2"; shift 2 || die 'Missing displayName'
;;
--description)
description="$2"; shift 2 || die 'Missing description'
;;
--version)
version="$2"; shift 2 || die 'Missing version'
;;
--author)
author="$2"; shift 2 || die 'Missing author'
;;
--contributors)
contributors_json="$2"; shift 2 || die 'Missing contributors'
;;
--publisher)
publisher="$2"; shift 2 || die 'Missing publisher'
;;
*)
die 'Unknown arguments: $@'
break
;;
esac
done

contents="$(
jq --indent 4 \
--arg name "$name" \
--arg displayName "$displayName" \
--arg description "$description" \
--arg version "$version" \
--arg author "$author" \
--argjson contributors "$contributors_json" \
--arg publisher "$publisher" \
'.
| .name |= $name
| .displayName |= $displayName
| .description |= $description
| .version |= $version
| .author |= (.name |= $author)
| .contributors |= (if $contributors == null then empty else $contributors end)
| .publisher |= $publisher
' \
< "$target"
)"
echo "$contents" > "$target"
}

main() {
direction="$1"; shift || die 'Missing direction'
version="$1"; shift || die 'Missing version'
if [ "$direction" = them ]; then
modify_packages \
--name "pyright" \
--displayName "Pyright" \
--description "Type checker for the Python language" \
--version "$version" \
--author "Microsoft Corporation" \
--contributors 'null' \
--publisher "Microsoft Corporation"
elif [ "$direction" = us ]; then
modify_packages \
--name "@replit/pyright-extended" \
--displayName "pyright-extended" \
--description "Extending pyright with yapf + ruff" \
--version "$version" \
--author "Replit" \
--contributors '[{"name":"Microsoft"}]' \
--publisher "Replit"
fi
}

main "$@"

0 comments on commit fe6c3e4

Please sign in to comment.