-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathrelease.sh
More file actions
169 lines (147 loc) · 4.55 KB
/
release.sh
File metadata and controls
169 lines (147 loc) · 4.55 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
export FORCE_COLOR=true
#######################################################################
# PUBLISH PFELEMENTS TO NPM! #
#######################################################################
PRERELEASE_PREFIX="prerelease"
OLD_VERSION=""
NEW_VERSION=""
TAG_NAME=""
RELEASE_BRANCH=""
# abort script if any command fails
set -e
trap ctrl_c INT
ctrl_c() {
echo "ctrl-c detected"
exit 1
}
log() {
echo "[RELEASE] $1"
}
checkDir() {
log "verifying CWD is monorepo root"
if [[ -f ./package.json ]]; then
if grep '"@patternfly/patternfly-elements"' package.json >/dev/null; then
log "CWD is monorepo root"
return
fi
fi
echo "Error: release must be run from the repository's root directory."
exit 1
}
cleanWorkspace() {
log "verifying clean workspace"
[[ "$(git status --untracked-files=no --porcelain | wc -l | sed 's/ //g')" == 0 ]] || ( log "error: Release cannot continue because you have local changes. Please commit or stash your changes and try again." && exit 1 )
}
checkoutMain() {
log "checkout main branch & pull"
git checkout main || exit 1
git pull origin main || exit 1
}
bumpVersion() {
log "bumping version"
OLD_VERSION=$(node -e "console.log(require('./lerna.json').version)")
./node_modules/.bin/lerna version --include-merged-tags --no-git-tag-version --no-push --preid="$PRERELEASE_PREFIX" || exit 1
NEW_VERSION=$(node -e "console.log(require('./lerna.json').version)")
}
createBranch() {
log "creating release branch with new version numbers"
TAG_NAME="v$NEW_VERSION"
RELEASE_BRANCH="release/$TAG_NAME"
git checkout -b $RELEASE_BRANCH || exit 1
}
npmInstall() {
log "installing NPM dependencies"
npm ci || exit 1
}
npmBuild() {
log "build the repository"
npm run build || exit 1
}
commitIgnoredFiles() {
log "committing compiled bundles to release branch"
git add elements/*/dist/ -f || exit 1
git commit -am "v$NEW_VERSION" || exit 1
}
gitTag() {
log "creating a git tag"
# create an annotated tag (lerna only picks up on annotated tags)
git tag -a -m "$TAG_NAME" $TAG_NAME || exit 1
}
removeIgnoredFiles() {
log "removing the compiled bundles from release branch (they should only exist in the tag)"
# for e in elements/*; do find $e -maxdepth 1 \( -not -name "gulpfile.js" -not -name "rollup.config.js" \) \( -name "*.js" -or -name "*.css" -or -name "*.map" \) -exec git rm -f {} \; ;done
git rm -rf elements/*/dist
git commit -am "remove bundles after $NEW_VERSION tag" || exit 1
}
pushToOrigin() {
log "pushing release branch to origin"
git push origin $RELEASE_BRANCH -u || exit 1
log "pushing tags to origin"
git push --tags || exit 1
}
resetMain() {
log "resetting main branch to origin/main"
git checkout main || exit 1
git reset --hard origin/main || exit 1
}
npmPublish() {
log "publishing newly versioned elements to NPM"
git checkout $TAG_NAME || exit 1
npm run lerna publish from-git || exit 1
git checkout .
}
handlePR() {
if command -v hub > /dev/null; then
log "Hub installation found, creating a PR."
git checkout $RELEASE_BRANCH
hub pull-request --browse --message "version bumps from $RELEASE_BRANCH"
else
log
log "FINAL STEP:"
log "Follow this link to create a pull request, merging the release branch ($RELEASE_BRANCH) into main."
log
log " https://github.com/patternfly/patternfly-elements/compare/$RELEASE_BRANCH?expand=1"
log
log "Note, if you install Hub (https://hub.github.com/) then this step will be automated in the future."
fi
}
goodbye() {
log "Returning you to the main branch."
git checkout main
}
# Only let user run this from repo root
checkDir
# Fail for uncommitted changes
cleanWorkspace
# check out the main branch
checkoutMain
# Set a lerna version, without tagging or pushing, using a prerelease id
bumpVersion
# Create a new "release branch" based on the changes made (versions) in last step
# Set TAG_NAME to `v${version}`
createBranch
# Only now run the install (?!?!?!)
npmInstall
# Run the build scripts
npmBuild
# Commit the dist files to the release branch
commitIgnoredFiles
# Tag the release branch with TAG_NAME
gitTag
# Remove the dist files from release branch
# But they still exist on the tag
removeIgnoredFiles
# Push the release branch (no build artifacts)
# and the tags (has build artifacts)
# to the origin
pushToOrigin
# reset hard to main
resetMain
# checkout TAG_NAME and run lerna publish
npmPublish
# Open a PR to merge release branch into main
# Even though the packages are already published
handlePR
# Checkout main
goodbye