-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-step-v1.sh
executable file
·189 lines (166 loc) · 5.95 KB
/
build-step-v1.sh
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env bash
# Exit on error
set -e
# Show commands as they are executed
set -x
# Verify that the server has its timezone set to UTC
date | grep -P ' UTC(\s|$)'
cd "$(dirname "$0")"
. config.sh
PUSH_URL="https://ClassyBot:${GITHUB_API_TOKEN}@github.com/ClassyBot/ClassicPress-v1-nightly"
pushd ClassicPress-v1-nightly/
git reset --hard
git fetch origin
git fetch origin --tags
git checkout origin/migration -B migration
git checkout origin/master -B master
popd
pushd ClassicPress-v1/
# Reset everything
rm -rf build/ build-migration/
git reset --hard
git fetch origin
git checkout origin/develop -B develop
rm -rf node_modules/
# Store the commit URL of the development repo
DEV_COMMIT_URL="https://github.com/ClassicPress/ClassicPress-v1/commit/$(git rev-parse HEAD)"
# Set up node version
set +x
echo 'loading nvm and node'
. ~/.nvm/nvm.sh --no-use
nvm use || nvm install
set -x
# Install dependencies and generate a nightly build
npm install
CLASSICPRESS_NIGHTLY=true ./node_modules/.bin/grunt build
# Prepare the migration build in its own subfolder
# 'build/' -> 'build-migration/wordpress/'
cp -ar build/ wordpress/
mkdir build-migration/
mv wordpress/ build-migration/
# Commit, push, and upload the migration build
# Due to the special folder structure of this build, we have to build a zip
# and upload it via GitHub's releases API, rather than letting GitHub build
# the zip based on the tag.
pushd build-migration/
# Update the version string
perl -pi -we 's/\+nightly\./+migration./' wordpress/wp-includes/version.php
BUILD_TAG=$(grep '^\$cp_version' wordpress/wp-includes/version.php | cut -d"'" -f2)
# Set up the git repository
cp -ar ../../ClassicPress-v1-nightly/.git/ .
# Check out `migration` without touching the working tree
git symbolic-ref HEAD refs/heads/migration
# Create the commit and the tag
git add --all .
GIT_COMMITTER_NAME='ClassyBot' GIT_COMMITTER_EMAIL='[email protected]' \
git commit --author 'ClassyBot <[email protected]>' \
-m "Nightly migration build $BUILD_TAG"
GIT_COMMITTER_NAME='ClassyBot' GIT_COMMITTER_EMAIL='[email protected]' \
GIT_AUTHOR_NAME='ClassyBot' GIT_AUTHOR_EMAIL='[email protected]' \
git tag "$BUILD_TAG" -m "Nightly migration build tag $BUILD_TAG"
# Push the commit and the tag
set +x
echo "+ git push origin migration"
git push "$PUSH_URL" migration
echo "+ git push origin $BUILD_TAG"
git push "$PUSH_URL" "$BUILD_TAG"
set -x
# Build the zip file
BUILD_FILENAME="ClassicPress-nightly-$(echo "$BUILD_TAG" | tr '+' '-').zip"
zip "$BUILD_FILENAME" -9 -r wordpress/
# Create the release using the GitHub API
BUILD_COMMIT=$(git rev-parse HEAD)
RESPONSE_CODE=$(curl \
-X POST \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token $GITHUB_API_TOKEN" \
-H "Content-Type: application/json" \
--data "{
\"tag_name\": \"$BUILD_TAG\",
\"target_commitish\": \"$BUILD_COMMIT\",
\"body\": \"Nightly migration build $BUILD_TAG. You probably don't need this, it's just for use by the migration plugin.\\n\\nSource commit: $DEV_COMMIT_URL\"
}" \
--output release.json \
--write-out '%{http_code}' \
https://api.github.com/repos/ClassyBot/ClassicPress-v1-nightly/releases \
)
if [ "$RESPONSE_CODE" -ne 201 ]; then
echo "Failed to create release: HTTP $RESPONSE_CODE"
cat release.json
exit 1
fi
echo 'Created GitHub release'
# Upload the zip using the GitHub API
UPLOAD_URL=$(cat release.json | grep '"upload_url"' | cut -d'"' -f4 | cut -d'{' -f1)
RESPONSE_CODE=$(curl \
-X POST \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token $GITHUB_API_TOKEN" \
-H "Content-Type: application/zip" \
--data-binary "@$BUILD_FILENAME" \
--output upload.json \
--write-out '%{http_code}' \
"${UPLOAD_URL}?name=$BUILD_FILENAME"
)
if [ "$RESPONSE_CODE" -ne 201 ]; then
echo "Failed to upload zip: HTTP $RESPONSE_CODE"
cat upload.json
exit 1
fi
echo 'Uploaded zip to GitHub'
popd
# Commit and push the nightly build
# Do this *after* finishing the migration build, so that the nightly build
# will show as the latest release on GitHub. (GitHub's ordering of releases
# is buggy, though.)
pushd build/
# Get the version string from the build
BUILD_TAG=$(grep '^\$cp_version' wp-includes/version.php | cut -d"'" -f2)
# Set up the git repository
cp -ar ../../ClassicPress-v1-nightly/.git/ .
# Create the commit and the tag
git add --all .
GIT_COMMITTER_NAME='ClassyBot' GIT_COMMITTER_EMAIL='[email protected]' \
git commit --author 'ClassyBot <[email protected]>' \
-m "Nightly build $BUILD_TAG"
GIT_COMMITTER_NAME='ClassyBot' GIT_COMMITTER_EMAIL='[email protected]' \
GIT_AUTHOR_NAME='ClassyBot' GIT_AUTHOR_EMAIL='[email protected]' \
git tag "$BUILD_TAG" -m "Nightly build tag $BUILD_TAG"
# Push the commit and the tag
set +x
echo "+ git push origin master"
git push "$PUSH_URL" master
echo "+ git push origin $BUILD_TAG"
git push "$PUSH_URL" "$BUILD_TAG"
set -x
# Add a GitHub release for the nightly build
BUILD_COMMIT=$(git rev-parse HEAD)
RESPONSE_CODE=$(curl \
-X POST \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token $GITHUB_API_TOKEN" \
-H "Content-Type: application/json" \
--data "{
\"tag_name\": \"$BUILD_TAG\",
\"target_commitish\": \"$BUILD_COMMIT\",
\"body\": \"Nightly build $BUILD_TAG. Use the source code zip.\\n\\nSource commit: $DEV_COMMIT_URL\"
}" \
--output release.json \
--write-out '%{http_code}' \
https://api.github.com/repos/ClassyBot/ClassicPress-v1-nightly/releases \
)
if [ "$RESPONSE_CODE" -ne 201 ]; then
echo "Failed to create release: HTTP $RESPONSE_CODE"
cat release.json
exit 1
fi
echo 'Created GitHub release'
popd
popd
pushd ClassicPress-v1-nightly/
git reset --hard
git fetch origin
git fetch origin --tags
git checkout origin/migration -B migration
git checkout origin/master -B master
popd