-
-
Notifications
You must be signed in to change notification settings - Fork 508
/
Copy pathcreate-new-minor-version
executable file
·97 lines (84 loc) · 4.4 KB
/
create-new-minor-version
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
echo "Welcome to the guided process of updating the Guides search index"
echo "We will now be running a mix of automated (🤖) and manual (👩💻) steps. Please read the prompts carefully."
# Keep track of the branch the script user is on for later reversal.
STARTING_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Generate a new branch name for the release by adding a pseudorandom suffix.
TEMP_BRANCH="create-new-guides-version-$(( $RANDOM % 1000 ))"
# Here we are stash any changes the script user might have to avoid losing them.
echo
echo "🤖 Staging local changes"
git add .
git stash push -m $TEMP_BRANCH
echo " DONE"
# Ask the user what the remote name is.
# `${REMOTE:-origin}` means that it defaults to `origin` if the script user did not provide a nanme.
echo
echo "🤖 Updating master branch from remote"
read -p "Remote name (origin): " REMOTE
REMOTE_NAME=${REMOTE:-origin}
git fetch $REMOTE_NAME master
git checkout FETCH_HEAD -b $TEMP_BRANCH
echo " DONE"
# Pause the execution of the script while the user does a manual task.
# The read flags do the following:
# `-n 1` tells `read` to only read one character.
# `-s` prevents `read` from echoing the input.
# `-r` doesn't allow backslashes as escape characters.
# `-p "…"` specifies what `read` prompts the user.
echo
echo "👩💻 Merge any pending PRs for the current release https://github.com/ember-learn/guides-source/pulls"
read -n 1 -s -r -p "Press any key to continue"
# Grabs the different version components from the guides/versions.yml file.
# `cut` can be a bit confusing at first because it's one-indexed. The flags are:
# `-d "."` specifies `.` as the delimiter.
# `-f N` specifies which of the delimited sections to keep
# `cut -c 2-` gets rid of the "v" prefix by selecting from the second character onwards.
CURRENT_VERSION=$(grep "currentVersion" guides/versions.yml | sed "s/currentVersion.*\(v.*\)\"/\1/")
MAJOR_VERSION=$(echo $CURRENT_VERSION | cut -d "." -f 1 | cut -c 2-)
MINOR_VERSION=$(echo $CURRENT_VERSION | cut -d "." -f 2)
PATCH_VERSION=$(echo $CURRENT_VERSION | cut -d "." -f 3)
NEXT_VERSION=$MAJOR_VERSION.$(($MINOR_VERSION+1)).$PATCH_VERSION
# Copy the current release guides into the appropriate version-numbered folder.
# `-r` is for recursive, so all directory content is copied.
echo "🤖 Removing any directories for $CURRENT_VERSION"
rm -rf guides/$CURRENT_VERSION
echo "🤖 Copying release to $CURRENT_VERSION"
cp -r guides/release guides/$CURRENT_VERSION
echo " DONE"
# Uses sed to replace the current version number in-place.
# We remove the backup file so it is not committed with the new guides content and versions.yml changes.
#
# In the `sed` command, `-i .bak` specifies the extension for the backup file. Since this is a versioned repository, the backup file isn't vital.
# The regular expression is matching and capturing (using parens) everything until the "v" so we can use it in the replacement as `\1`.
# Then we interpolate the new version and replace the closing double quote.
# We also add the relevant version to the list by using sed's i command.
echo "🤖 Updating /guides/versions.yml"
sed -i .bak "s/\(currentVersion:.*v\).*/\1$(echo $NEXT_VERSION)\"/" guides/versions.yml
sed -i .bak -e "/currentVersion/i \\
\ \ - \"v$(echo $NEXT_VERSION)\"" guides/versions.yml
rm guides/versions.yml.bak
echo " DONE"
echo "What version of EmberData is being released (e.g. 5.3.0)? Double check this as it might not be the same version as Ember."
read -r EMBER_DATA_CURRENT_VERSION
# Update version numbers in links
echo "🤖 Updating version number for links in /guides/$CURRENT_VERSION/**/*.md"
node scripts/update-version-links guides/$CURRENT_VERSION $(echo $CURRENT_VERSION | cut -d "v" -f2) $(echo $EMBER_DATA_CURRENT_VERSION | cut -d "v" -f2) --silent
echo " DONE"
echo
echo "🤖 Committing changes and publishing branch to remote"
git add .
git commit -m "v$(echo $NEXT_VERSION)"
git push -u origin $TEMP_BRANCH
echo " DONE"
echo
echo "👩💻 Create pull request for $($TEMP_BRANCH): https://github.com/ember-learn/guides-source/compare/master...$TEMP_BRANCH"
read -n 1 -s -r -p "Press any key to continue"
echo
echo "🤖 Restoring previous branch."
echo "You might see an error if you didn't have a stash."
git reset --hard
git switch $STARTING_BRANCH
git stash list | grep $TEMP_BRANCH | grep -Eo '^[^:]+' | git stash pop -
git branch -D $TEMP_BRANCH
git stash pop "$(git stash list | grep $TEMP_BRANCH | grep -Eo '^[^:]+')"