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

Add scripts to aid PRs & releases #18

Merged
merged 2 commits into from
Jun 29, 2023
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions scripts/prepare-patch-branch
Original file line number Diff line number Diff line change
@@ -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 {
AndrewFerr marked this conversation as resolved.
Show resolved Hide resolved
echo "$*"
$*
}

if [[ -z $UPSTREAM_REPO ]]; then
echo -n 'Adding remote for upstream repo: '
UPSTREAM_REPO=turt2live
echoAndDo git remote add $UPSTREAM_REPO [email protected]: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 [email protected]: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."
49 changes: 49 additions & 0 deletions scripts/tag-release
Original file line number Diff line number Diff line change
@@ -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{,}
AndrewFerr marked this conversation as resolved.
Show resolved Hide resolved

echo "Tag '$THIS_TAG' is now ready and may be pushed"