-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathpublish.sh
More file actions
executable file
·62 lines (52 loc) · 2.24 KB
/
publish.sh
File metadata and controls
executable file
·62 lines (52 loc) · 2.24 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
#!/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
# Usage: yarn release:publish [branch=release]
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 switch -c "$BRANCH" "$VERSION_SHA"
git push origin HEAD
if which gh >/dev/null; then
# Use GitHub CLI to create a PR and wait for CI checks to pass
gh pr create -t "chore: release $VERSION" -B "$RELEASE_BRANCH" -b ''
# Clean up locally
git switch "$BASE_BRANCH"
git branch -D "$BRANCH"
# Wait for CI to complete
. "$(dirname "$0")/wait-for-pr.sh" "$BRANCH"
if ! gh pr checks --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" 1>/dev/null 2>/dev/null; do
sleep 15
done
gh release view "v$VERSION" --web
else
# GitHub CLI not installed - clean up and prompt for manual branch creation
git switch "$BASE_BRANCH"
git branch -D "$BRANCH"
echo "Open a PR: https://github.com/salesforce/lwc/pull/new/$BRANCH"
fi