1
+ #! /bin/bash
2
+ set -eou pipefail
3
+ IFS=$' \n\t '
4
+
5
+ # shellcheck disable=SC2155
6
+ readonly SELF_DIRNAME=" $( dirname -- " $0 " ) "
7
+ readonly BASE_DIR=" ${SELF_DIRNAME} /.."
8
+
9
+ # TODO: Parameterize or make case-insensitive when this is an action
10
+ readonly CANONICAL_FILE=" README.MD"
11
+ readonly GIT_USER=
" [email protected] "
12
+ readonly GIT_NAME=" Pantheon Automation"
13
+
14
+ readonly RELEASE_BRANCH=" release"
15
+ readonly DEVELOP_BRANCH=" alt-main"
16
+
17
+ main () {
18
+ local CANONICAL_VERSION
19
+ CANONICAL_VERSION=" $( grep ' Stable tag:' < " ${CANONICAL_FILE} " | awk ' {print $3}' ) "
20
+
21
+ git checkout " ${RELEASE_BRANCH} "
22
+ git pull origin " ${RELEASE_BRANCH} "
23
+ git checkout " ${DEVELOP_BRANCH} "
24
+ git pull origin " ${DEVELOP_BRANCH} "
25
+ git rebase " ${RELEASE_BRANCH} "
26
+
27
+ IFS=' .' read -ra parts <<< " $CANONICAL_VERSION"
28
+ patch=" ${parts[2]} "
29
+ patch=$(( patch + 1 ))
30
+ NEW_DEV_VERSION=" ${parts[0]} .${parts[1]} .$patch -dev"
31
+ echo " $NEW_DEV_VERSION "
32
+
33
+ echo " Updating ${CANONICAL_VERSION} to ${NEW_DEV_VERSION} "
34
+ # Iterate through each file in the top-level directory
35
+ for file in " $BASE_DIR " /* ; do
36
+ if [ -f " $file " ]; then
37
+ echo " ${file} "
38
+ if [[ " $file " = " $BASE_DIR /package-lock.json" ]]; then
39
+ # skip package-lock and let `npm i` do it.
40
+ echo " skipping sed of package lock"
41
+ continue
42
+ fi
43
+ (
44
+ shopt -s nocasematch # make the "if readme" case insensitive
45
+ if [[ " ${file} " == " $BASE_DIR /readme.txt" ]]; then
46
+ echo " adding new heading"
47
+ new_heading=" ### ${NEW_DEV_VERSION} "
48
+ awk -v heading=" $new_heading " ' /## Changelog/ { print; print ""; print heading; print ""; next } 1' " $file " > tmp.md
49
+ mv tmp.md " $file "
50
+ git add " $file "
51
+ continue
52
+ elif [[ " ${file} " == " $BASE_DIR /readme.md" ]]; then
53
+ echo " adding new heading"
54
+ new_heading=" = ${NEW_DEV_VERSION} ="
55
+ awk -v heading=" $new_heading " ' /== Changelog ==/ { print; print ""; print heading; print ""; next } 1' " $file " > tmp.md
56
+ mv tmp.md " $file "
57
+ git add " $file "
58
+ continue
59
+ fi
60
+ )
61
+ # Use `sed` to perform the search and replace operation in each file
62
+ sed -i.tmp -e " s/${CANONICAL_VERSION} /${NEW_DEV_VERSION} /g" " $file " && rm " $file .tmp"
63
+ if [[ " $file " == " $BASE_DIR /package.json" ]]; then
64
+ # TODO: This seems unsafe as we might update dependencies as well.
65
+ # Is it safe to just sed package-lock instead? That also seems wrong.
66
+ echo " running 'npm i --package-lock-only' to update package-lock.json"
67
+ npm i --package-lock-only
68
+ git add " $BASE_DIR /package-lock.json"
69
+ fi
70
+
71
+ git add " $file "
72
+ fi
73
+ done
74
+ # Who am I?
75
+ git config --global user.email " ${GIT_USER} "
76
+ git config --global user.name " ${GIT_NAME} "
77
+
78
+ git commit -m " Prepare ${NEW_DEV_VERSION} "
79
+ # git push origin "${DEVELOP_BRANCH}"
80
+ }
81
+
82
+ main " $@ "
0 commit comments