diff --git a/package.json b/package.json index 642c61d5..80764c15 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,9 @@ "url": "https://github.com/vector-im/matrix-bot-sdk/issues" }, "homepage": "https://github.com/vector-im/matrix-bot-sdk#readme", + "publishConfig": { + "access": "public" + }, "scripts": { "prepublishOnly": "yarn build", "docs": "jsdoc -c jsdoc.json -P package.json -u docs/tutorials", diff --git a/scripts/prepare-patch-branch b/scripts/prepare-patch-branch new file mode 100755 index 00000000..07e9e675 --- /dev/null +++ b/scripts/prepare-patch-branch @@ -0,0 +1,40 @@ +#!/bin/bash +set -e + +if [[ $# -lt 1 ]]; then + echo 'Please provide a title for your patch branch' >&2 + exit 1 +fi +PATCH_TITLE=$1 + +for REMOTE in $(git remote); do + URL=$(git remote get-url $REMOTE) + if [[ $URL =~ "turt2live" ]]; then + UPSTREAM_REPO=$REMOTE + elif [[ $URL =~ "vector-im" ]]; then + FORK_REPO=$REMOTE + fi +done + +function echoAndDo { + echo "$*" + $* +} + +if [[ -z $UPSTREAM_REPO ]]; then + echo -n 'Adding remote for upstream repo: ' + UPSTREAM_REPO=turt2live + echoAndDo git remote add $UPSTREAM_REPO git@github.com:turt2live/matrix-bot-sdk.git +fi + +if [[ -z $FORK_REPO ]]; then + echo -n 'Adding remote for fork repo: ' + FORK_REPO=vector-im + echoAndDo git remote add $FORK_REPO git@github.com:vector-im/matrix-bot-sdk.git +fi + +git fetch $UPSTREAM_REPO +git fetch $FORK_REPO +git checkout -b $PATCH_TITLE $(git merge-base $UPSTREAM_REPO/main $FORK_REPO/element-main) + +echo "Branch '$PATCH_TITLE' is now ready. Push changes to this branch when preparing a PR, and aim to merge it to both upstream and the fork." diff --git a/scripts/tag-release b/scripts/tag-release new file mode 100755 index 00000000..c9161c63 --- /dev/null +++ b/scripts/tag-release @@ -0,0 +1,49 @@ +#!/bin/bash +set -e + +if [[ -n $(git status --porcelain) ]]; then + echo 'Working dir is dirty, aborting' >&2 + exit 1 +fi + +git fetch --all +git checkout element-release +git reset --hard element-main + +PREID=element + +# The latest upstream release tag reachable from the current commit +PREV_UPST_TAG=$(git log --decorate=short --decorate-refs=refs/tags/ --simplify-by-decoration --oneline | awk '/ \(tag: / && !/beta|element/ {sub(/)$/, "", $3); print $3; exit}') + +# The commit hash of the retrieved tag (not of the tag itself) +PREV_UPST_TAG_HASH=$(git rev-parse ${PREV_UPST_TAG}~0) + +# The immediate child commit of the release commit, +# to consider the 'Revert version back to "develop"' commits +PREV_UPST_NXT_HASH=$(git rev-list ${PREV_UPST_TAG}..main | tail -n 1) + +# Check if the current branch is a direct merge of the previous upstream release +for MERGE_PARENT in $(git show -s | awk '/^Merge: / {print $2; print $3; exit}'); do + if [[ $PREV_UPST_TAG_HASH =~ ^$MERGE_PARENT || $PREV_UPST_NXT_HASH =~ ^$MERGE_PARENT ]]; then + RELEASE_MERGE=1 + break + fi +done + +if [[ $RELEASE_MERGE -eq 1 ]]; then + THIS_TAG="${PREV_UPST_TAG}-${PREID}" + THIS_VER=${THIS_TAG#v} +else + THIS_VER=$(npx semver --preid ${PREID} -i prerelease ${PREV_UPST_TAG#v}) + while [[ -n $(git tag -l "v${THIS_VER}") ]]; do + THIS_VER=$(npx semver --preid ${PREID} -i prerelease $THIS_VER) + done + THIS_TAG="v${THIS_VER}" +fi + +sed -i 's/\("version": "\).*\("\)/\1'$THIS_VER'\2/' package.json +git add package.json +git commit -m $THIS_TAG +git tag -sm $THIS_TAG{,} + +echo "Tag '$THIS_TAG' is now ready and may be pushed"