-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathpublish.sh
More file actions
executable file
·67 lines (55 loc) · 2.36 KB
/
publish.sh
File metadata and controls
executable file
·67 lines (55 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
# Find the commit on master that last changed the root package.json version,
# then submit a PR to merge that commit onto the release branch and release via nucleus
# Optionally set WORK_ITEM env var to include in commit/PR title
# Usage: yarn release:publish [branch=release]
# Example: WORK_ITEM=W-1234567 yarn release:publish
set -e
BRANCH="release-publish-$(date -u +'%Y-%m-%d-%H_%M')"
BASE_BRANCH='master'
RELEASE_BRANCH="${1:-release}"
# Avoid accidentally committing unrelated files
if [[ -n $(git status --porcelain) ]]; then
echo -e '\033[1mPlease stash your work before continuing.\n\033[0m'
git status
exit 1
fi
git switch "$BASE_BRANCH"
git pull
# The last commit that changed the root package.json version
# (in case new commits were merged onto the base branch since then that aren't ready for release)
VERSION_SHA=$(git blame -- package.json | grep '"version":' | cut -d' ' -f1)
VERSION=$(jq -r .version package.json)
# Create a new branch with the changes to release
git branch "$BRANCH" "$VERSION_SHA"
git push -u origin "$BRANCH"
git branch -D "$BRANCH"
if ! which gh >/dev/null; then
# GitHub CLI not installed - clean up and prompt for manual branch creation
echo "Open a PR: https://github.com/salesforce/lwc/pull/new/$BRANCH"
exit 0
fi
PR_TITLE="chore: release $VERSION"
if [ -n "$WORK_ITEM" ]; then
PR_TITLE+=" @$WORK_ITEM"
fi
# Use GitHub CLI to create a PR and wait for CI checks to pass
gh pr create -t "$PR_TITLE" -b '' -B "$RELEASE_BRANCH" -H "$BRANCH"
# Wait for CI to complete
sleep 3 # Give GitHub time to kick off CI
. "$(dirname "$0")/wait-for-pr.sh" "$BRANCH"
if ! gh pr checks "$BRANCH" --fail-fast --watch; then
echo 'CI failed. Cannot continue with release.'
gh pr view "$BRANCH" --web
exit 1
fi
sleep 10 # Give nucleus time to start the release job
RELEASE_JOB=$(gh pr checks "$BRANCH" --json name,link -q '.[]|select(.name=="continuous-integration/nucleus/release").link')
echo "Nucleus release started: $RELEASE_JOB"
# Wait for GitHub release to be created by Nucleus, then open it
echo 'The GitHub release notes must be added manually. You can exit the script now and open GitHub on your own, or wait until the release is created and the script will open the page for you.'
sleep 300 # Nucleus job usually takes ~5 minutes
while ! gh release view "v$VERSION" >/dev/null; do
sleep 15
done
gh release view "v$VERSION" --web