|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -echo "Welcome to the guided process of updating the Guides search index" |
4 |
| -echo "We will now be running a mix of automated (🤖) and manual (👩💻) steps. Please read the prompts carefully." |
5 |
| - |
6 |
| -# Keep track of the branch the script user is on for later reversal. |
7 |
| -STARTING_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
8 |
| -# Generate a new branch name for the release by adding a pseudorandom suffix. |
9 |
| -TEMP_BRANCH="create-new-guides-version-$(( $RANDOM % 1000 ))" |
10 |
| - |
11 |
| -# Here we are stash any changes the script user might have to avoid losing them. |
12 |
| -echo |
13 |
| -echo "🤖 Staging local changes" |
14 |
| -git add . |
15 |
| -git stash push -m $TEMP_BRANCH |
16 |
| -echo " DONE" |
17 |
| - |
18 |
| -# Ask the user what the remote name is. |
19 |
| -# `${REMOTE:-origin}` means that it defaults to `origin` if the script user did not provide a nanme. |
20 |
| -echo |
21 |
| -echo "🤖 Updating master branch from remote" |
22 |
| -read -p "Remote name (origin): " REMOTE |
23 |
| -REMOTE_NAME=${REMOTE:-origin} |
24 |
| -git fetch $REMOTE_NAME master |
25 |
| -git checkout FETCH_HEAD -b $TEMP_BRANCH |
26 |
| -echo " DONE" |
27 |
| - |
28 |
| -# Pause the execution of the script while the user does a manual task. |
29 |
| -# The read flags do the following: |
30 |
| -# `-n 1` tells `read` to only read one character. |
31 |
| -# `-s` prevents `read` from echoing the input. |
32 |
| -# `-r` doesn't allow backslashes as escape characters. |
33 |
| -# `-p "…"` specifies what `read` prompts the user. |
34 |
| -echo |
35 |
| -echo "👩💻 Merge any pending PRs for the current release https://github.com/ember-learn/guides-source/pulls" |
36 |
| -read -n 1 -s -r -p "Press any key to continue" |
37 |
| - |
38 |
| -# Grabs the different version components from the guides/versions.yml file. |
39 |
| -# `cut` can be a bit confusing at first because it's one-indexed. The flags are: |
40 |
| -# `-d "."` specifies `.` as the delimiter. |
41 |
| -# `-f N` specifies which of the delimited sections to keep |
42 |
| -# `cut -c 2-` gets rid of the "v" prefix by selecting from the second character onwards. |
43 |
| -CURRENT_VERSION=$(grep "currentVersion" guides/versions.yml | sed "s/currentVersion.*\(v.*\)\"/\1/") |
44 |
| -MAJOR_VERSION=$(echo $CURRENT_VERSION | cut -d "." -f 1 | cut -c 2-) |
45 |
| -MINOR_VERSION=$(echo $CURRENT_VERSION | cut -d "." -f 2) |
46 |
| -PATCH_VERSION=$(echo $CURRENT_VERSION | cut -d "." -f 3) |
47 |
| -NEXT_VERSION=$MAJOR_VERSION.$(($MINOR_VERSION+1)).$PATCH_VERSION |
48 |
| - |
49 |
| -# Copy the current release guides into the appropriate version-numbered folder. |
50 |
| -# `-r` is for recursive, so all directory content is copied. |
51 |
| -echo "🤖 Removing any directories for $CURRENT_VERSION" |
52 |
| -rm -rf guides/$CURRENT_VERSION |
53 |
| -echo "🤖 Copying release to $CURRENT_VERSION" |
54 |
| -cp -r guides/release guides/$CURRENT_VERSION |
55 |
| -echo " DONE" |
56 |
| - |
57 |
| -# Uses sed to replace the current version number in-place. |
58 |
| -# We remove the backup file so it is not committed with the new guides content and versions.yml changes. |
59 |
| -# |
60 |
| -# 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. |
61 |
| -# The regular expression is matching and capturing (using parens) everything until the "v" so we can use it in the replacement as `\1`. |
62 |
| -# Then we interpolate the new version and replace the closing double quote. |
63 |
| -# We also add the relevant version to the list by using sed's i command. |
64 |
| -echo "🤖 Updating /guides/versions.yml" |
65 |
| -sed -i .bak "s/\(currentVersion:.*v\).*/\1$(echo $NEXT_VERSION)\"/" guides/versions.yml |
66 |
| -sed -i .bak -e "/currentVersion/i \\ |
67 |
| -\ \ - \"v$(echo $NEXT_VERSION)\"" guides/versions.yml |
68 |
| -rm guides/versions.yml.bak |
69 |
| -echo " DONE" |
70 |
| - |
71 |
| -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." |
72 |
| -read -r EMBER_DATA_CURRENT_VERSION |
73 |
| - |
74 |
| -# Update version numbers in links |
75 |
| -echo "🤖 Updating version number for links in /guides/$CURRENT_VERSION/**/*.md" |
76 |
| -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 |
77 |
| -echo " DONE" |
78 |
| - |
79 |
| -echo |
80 |
| -echo "🤖 Committing changes and publishing branch to remote" |
81 |
| -git add . |
82 |
| -git commit -m "v$(echo $NEXT_VERSION)" |
83 |
| -git push -u origin $TEMP_BRANCH |
84 |
| -echo " DONE" |
85 |
| - |
86 |
| -echo |
87 |
| -echo "👩💻 Create pull request for $($TEMP_BRANCH): https://github.com/ember-learn/guides-source/compare/master...$TEMP_BRANCH" |
88 |
| -read -n 1 -s -r -p "Press any key to continue" |
89 |
| - |
90 |
| -echo |
91 |
| -echo "🤖 Restoring previous branch." |
92 |
| -echo "You might see an error if you didn't have a stash." |
93 |
| -git reset --hard |
94 |
| -git switch $STARTING_BRANCH |
95 |
| -git stash list | grep $TEMP_BRANCH | grep -Eo '^[^:]+' | git stash pop - |
96 |
| -git branch -D $TEMP_BRANCH |
97 |
| -git stash pop "$(git stash list | grep $TEMP_BRANCH | grep -Eo '^[^:]+')" |
| 3 | +echo "THIS SCRIPT HAS BEEN DEPRECATED" |
| 4 | +echo "if you want to be guided through the release of a new guides version you can run npx ember-learn-release-tool" |
| 5 | +echo "source code for the tool is available here https://github.com/ember-learn/ember-learn-release-tool" |
0 commit comments