forked from espressif/arduino-esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-release.sh
executable file
·348 lines (272 loc) · 11.1 KB
/
build-release.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/bash
############################################################
# $1 - download link
# $2 - JSON output file
function downloadAndMergePackageJSON()
{
echo " --- Package JSON definition merge BEGIN ---"
jsonLink=$1
jsonOut=$2
curlAuthToken=$3
outDirectory=$4
echo "Remote package JSON: $jsonLink (source)"
echo "Current package JSON: $jsonOut (target)"
old_json=$outDirectory/oldJson.json
merged_json=$outDirectory/mergedJson.json
#DEBUG
#echo " Local tmp for remote JSON: $old_json"
#echo " Merge output JSON: $merged_json"
echo "Downloading JSON package definition: $jsonLink ..."
# Authentication through HTTP headers might fail on redirection due to bug in cURL (https://curl.haxx.se/docs/adv_2018-b3bf.html - headers are resent to the target location including the original authentication)
# Notes:
# - eg AmazonAWS fails with Bad Request due to having maximum 1 authentication mechanism per a request, might be general issue
# - it's a first-class credential leakage
# - the fix is available in cURL 7.58.0+, however, TravisCI is not yet updated (May 29, 2018) - see https://docs.travis-ci.com/user/build-environment-updates
# - TravisCI workaround: updating build environment through .travis.yml (ie install required version of cURL using apt-get, see https://docs.travis-ci.com/user/installing-dependencies/)
# - previous point not used on purpose (build time increase, possible failure corrupts whole build, etc) but it's good to know there's a way out of hell
# - local workaround: authentication through 'access_token' as GET parameter works smoothly, however, HTTP headers are preferred
#curl --verbose -sH "Authorization: token $curlAuthToken" -L -o "$old_json" "$jsonLink"
curl -L -o "$old_json" "$jsonLink?access_token=$curlAuthToken"
#curl -L -o "$old_json" "$jsonLink"
echo "Merging $old_json into $jsonOut ..."
echo
set +e
stdbuf -oL python package/merge_packages.py "$jsonOut" "$old_json" > "$merged_json"
set -e #supposed to be ON by default
echo
set -v
if [ ! -s $merged_json ]; then
rm -f "$merged_json"
echo "Nothing to merge ($merged_json empty), $jsonOut unchanged"
else
rm -f "$jsonOut"
mv "$merged_json" "$jsonOut"
echo "Data successfully merged to $jsonOut"
fi
rm -f "$old_json"
set +v
echo " --- Package JSON definition merge END ---"
}
############################################################
#Cmdline options
# -a: GitHub API access token
# -d: output directory to store the (pre)release filedir set
set -e
echo
echo "==================================================================="
echo "RELEASE PACKAGE PUBLISHING ARRANGEMENTS (GitHub/Arduino compliance)"
echo "==================================================================="
echo
# cURL authentication token
while getopts ":a:,:d:" opt; do
case $opt in
a)
curlAuth=$OPTARG
echo "ACCESS TOKEN: $curlAuth" >&2
;;
d)
releaseDir=$OPTARG
echo "RELEASE OUTPUT DIRECTORY: $releaseDir" >&2
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# where we at?
if [ -z "$TRAVIS_BUILD_DIR" ]; then
echo "Non-TravisCI environment"
cd "$( dirname ${BASH_SOURCE[0]} )"/..
bTravisRun=0
else
echo "TravisCI run"
cd $TRAVIS_BUILD_DIR
bTravisRun=1
fi
# no tag, no love
if [ -z "$TRAVIS_TAG" ] && [ $bTravisRun -eq 1 ]; then
echo "Non-tagged builds not supported in Travis CI environment, exiting"
exit 0
fi
currentDir=`pwd`
echo "Current working directory: $currentDir"
srcdir=$currentDir
if [ -z "$releaseDir" ]; then
releaseDir=release
fi
echo "Release output directory: $releaseDir"
# get current branch name and commit hash
branch_name=""
verx=""
extent=""
if [ -z "$TRAVIS_TAG" ]; then
branch_name=`git rev-parse --abbrev-ref HEAD 2>/dev/null`
ver=`sed -n -E 's/version=([0-9.]+)/\1/p' platform.txt`
verx=`git rev-parse --short=8 HEAD 2>/dev/null`
else
ver=$TRAVIS_TAG
fi
# Package name (case-insensitive)
shopt -s nocasematch
if [ ! -z "$branch_name" ] && [ "$branch_name" != "master" ]; then
extent="-$branch_name-$verx"
fi
package_name=esp32-$ver$extent
shopt -u nocasematch
echo "Version: $ver"
echo "Branch name: $branch_name"
echo "Git revision (8B): $verx"
echo "Extension: $extent"
echo "Travis CI tag: $TRAVIS_TAG"
echo "Package name: $package_name"
# Set REMOTE_URL environment variable to the address where the package will be
# available for download. This gets written into package json file.
if [ -z "$REMOTE_URL" ]; then
REMOTE_URL="http://localhost:8000"
echo "REMOTE_URL not defined, using default"
fi
echo "Remote: $REMOTE_URL"
# Create directory for the package
outdir=$releaseDir/$package_name
echo "Temporary output directory: $outdir"
rm -rf $releaseDir
mkdir -p $outdir
# Copy package required stuff:
# <package root>
cp -f $srcdir/boards.txt $outdir/
cp -f $srcdir/platform.txt $outdir/
cp -f $srcdir/programmers.txt $outdir/
# <complete dirs>
# cores/
# libraries/
# variants/
cp -Rf $srcdir/cores $outdir/
cp -Rf $srcdir/libraries $outdir/
cp -Rf $srcdir/variants $outdir/
# <dir & files>
# tools/partitions/
mkdir -p $outdir/tools/partitions
cp -f $srcdir/tools/partitions/boot_app0.bin $outdir/tools/partitions
cp -f $srcdir/tools/partitions/default.csv $outdir/tools/partitions
cp -f $srcdir/tools/partitions/minimal.csv $outdir/tools/partitions
cp -f $srcdir/tools/partitions/min_spiffs.csv $outdir/tools/partitions
cp -f $srcdir/tools/partitions/no_ota.csv $outdir/tools/partitions
# tools/sdk/
cp -Rf $srcdir/tools/sdk $outdir/tools/
# tools/
cp -f $srcdir/tools/espota.exe $outdir/tools/
cp -f $srcdir/tools/espota.py $outdir/tools/
cp -f $srcdir/tools/esptool.py $outdir/tools/
cp -f $srcdir/tools/gen_esp32part.py $outdir/tools/
cp -f $srcdir/tools/gen_esp32part.exe $outdir/tools/
find $outdir -name '*.DS_Store' -exec rm -f {} \;
# Do some replacements in platform.txt file, which are required because IDE
# handles tool paths differently when package is installed in hardware folder
cat $srcdir/platform.txt | \
sed 's/runtime.tools.xtensa-esp32-elf-gcc.path={runtime.platform.path}\/tools\/xtensa-esp32-elf//g' | \
sed 's/tools.esptool.path={runtime.platform.path}\/tools\/esptool/tools.esptool.path=\{runtime.tools.esptool.path\}/g' \
> $outdir/platform.txt
# Put core version and short hash of git version into core_version.h
ver_define=`echo $plain_ver | tr "[:lower:].\055" "[:upper:]_"`
echo Ver define: $ver_define
echo \#define ARDUINO_ESP32_GIT_VER 0x`git rev-parse --short=8 HEAD 2>/dev/null` >$outdir/cores/esp32/core_version.h
echo \#define ARDUINO_ESP32_GIT_DESC `git describe --tags 2>/dev/null` >>$outdir/cores/esp32/core_version.h
echo \#define ARDUINO_ESP32_RELEASE_$ver_define >>$outdir/cores/esp32/core_version.h
echo \#define ARDUINO_ESP32_RELEASE \"$ver_define\" >>$outdir/cores/esp32/core_version.h
# Store submodules' current versions
git submodule status > $releaseDir/submodules.txt
# remove all .git* files
find $outdir -name '*.git*' -type f -delete
# Zip the package
package_name_zip=$package_name.zip
echo "----------------------------------------------------------"
echo "Making $package_name ZIP archive..."
echo
pushd $releaseDir >/dev/null
zip -qr $package_name_zip $package_name
echo "----------------------------------------------------------"
echo "Making $package_name JSON definition file(s)..."
echo
# Calculate SHA sum and size
sha=`shasum -a 256 $package_name_zip | cut -f 1 -d ' '`
size=`/bin/ls -l $package_name_zip | awk '{print $5}'`
echo Size: $size
echo SHA-256: $sha
popd >/dev/null
PACKAGE_JSON_DEV="package_esp32_dev_index.json"
PACKAGE_JSON_REL="package_esp32_index.json"
# figure out the package type (release / pre-release)
shopt -s nocasematch
if [[ $TRAVIS_TAG == *-RC* ]]; then
bIsPrerelease=1
package_name_json=$PACKAGE_JSON_DEV
echo "Package type: PRE-RELEASE, JSON def.file: $PACKAGE_JSON_DEV"
else
bIsPrerelease=0
package_name_json=$PACKAGE_JSON_REL
echo "Package type: RELEASE, JSON def.files: $PACKAGE_JSON_REL, $PACKAGE_JSON_DEV"
fi
shopt -u nocasematch
# Generate JSON package definition
echo
echo "----------------------------------------------------------"
echo "Preparing current package definition ($package_name_json)..."
# JSON contents
jq_arg=".packages[0].platforms[0].version = \"$ver\" | \
.packages[0].platforms[0].url = \"$REMOTE_URL/$package_name_zip\" |\
.packages[0].platforms[0].archiveFileName = \"$package_name_zip\""
jq_arg="$jq_arg |\
.packages[0].platforms[0].size = \"$size\" |\
.packages[0].platforms[0].checksum = \"SHA-256:$sha\""
# Cleanup temporary work dir
rm -rf $outdir
# Get previous release name
echo
echo "----------------------------------------------------------"
echo "Getting previous releases versions..."
releasesJson=$releaseDir/releases.json
curl -sH "Authorization: token $curlAuth" https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases > $releasesJson
# Previous final release (prerelase == false)
prev_release=$(jq -r '. | map(select(.draft == false and .prerelease == false)) | sort_by(.created_at | - fromdateiso8601) | .[0].tag_name' ${releasesJson})
# Previous release (possibly a pre-release)
prev_any_release=$(jq -r '. | map(select(.draft == false)) | sort_by(.created_at | - fromdateiso8601) | .[0].tag_name' ${releasesJson})
# Previous pre-release
prev_pre_release=$(jq -r '. | map(select(.draft == false and .prerelease == true)) | sort_by(.created_at | - fromdateiso8601) | .[0].tag_name' ${releasesJson})
rm -f "$releasesJson"
echo "Previous release: $prev_release"
echo "Previous (pre-?)release: $prev_any_release"
echo "Previous pre-release: $prev_pre_release"
# always get DEV version of JSON (included in both RC/REL)
echo
echo "----------------------------------------------------------"
echo "Generating $PACKAGE_JSON_DEV..."
echo
cat $srcdir/package/package_esp32_index.template.json | jq "$jq_arg" > $releaseDir/$PACKAGE_JSON_DEV
if [ ! -z "$prev_any_release" ] && [ "$prev_any_release" != "null" ]; then
downloadAndMergePackageJSON "https://github.com/$TRAVIS_REPO_SLUG/releases/download/${prev_any_release}/${PACKAGE_JSON_DEV}" "$releaseDir/${PACKAGE_JSON_DEV}" "${curlAuth}" "$releaseDir"
# Release notes: GIT log comments (prev_any_release, current_release>
git log --oneline $prev_any_release.. > $releaseDir/commits.txt
fi
# for RELEASE run update REL JSON as well
if [ $bIsPrerelease -eq 0 ]; then
echo
echo "----------------------------------------------------------"
echo "Generating $PACKAGE_JSON_REL..."
echo
cat $srcdir/package/package_esp32_index.template.json | jq "$jq_arg" > $releaseDir/$PACKAGE_JSON_REL
if [ ! -z "$prev_release" ] && [ "$prev_release" != "null" ]; then
downloadAndMergePackageJSON "https://github.com/$TRAVIS_REPO_SLUG/releases/download/${prev_release}/${PACKAGE_JSON_REL}" "$releaseDir/${PACKAGE_JSON_REL}" "${curlAuth}" "$releaseDir"
# Release notes: GIT log comments (prev_release, current_release>
git log --oneline $prev_release.. > $releaseDir/commits.txt
fi
fi
echo
echo "=============================================================="
echo "Package '$package_name' ready for publishing, script finished."
echo "=============================================================="
echo