Skip to content

Commit

Permalink
ci: rework build.sh & release.sh generator
Browse files Browse the repository at this point in the history
- don't depend on TRAVIS environment variables
- depend on CI flag to add release variables
- chmod +x
  • Loading branch information
mcspr committed Apr 8, 2020
1 parent 945652f commit 492a359
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
5 changes: 4 additions & 1 deletion code/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ build_webui() {
build_release() {
echo "--------------------------------------------------------------"
echo "Building release images..."
python scripts/generate_release_sh.py --ignore secure-client $version > release.sh
python scripts/generate_release_sh.py \
--ignore secure-client \
--version $version \
--destination $destination/espurna-$version > release.sh
bash release.sh
echo "--------------------------------------------------------------"
}
Expand Down
8 changes: 4 additions & 4 deletions code/scripts/espurna_utils/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

def copy_release(target, source, env):
# target filename and subdir for release files
name = env["ESPURNA_NAME"]
version = env["ESPURNA_VERSION"]
name = env["ESPURNA_RELEASE_NAME"]
version = env["ESPURNA_RELEASE_VERSION"]
destdir = env["ESPURNA_RELEASE_DESTINATION"]

if not name or not version:
if not name or not version or not destdir:
raise ValueError("Cannot set up release without release variables present")

destdir = os.path.join(env.subst("$PROJECT_DIR"), "..", "firmware", version)
if not os.path.exists(destdir):
os.makedirs(destdir)

Expand Down
27 changes: 23 additions & 4 deletions code/scripts/generate_release_sh.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#!/usr/bin/env python
#
# Copyright (C) 2020 by Maxim Prokhorov <prokhorov dot max at outlook dot com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import argparse
import re
Expand Down Expand Up @@ -79,7 +96,7 @@ def generate_lines(builds, ignore):
flags.append('PLATFORMIO_BUILD_FLAGS="{}"'.format(build.build_flags))
if build.src_build_flags:
flags.append('ESPURNA_FLAGS="{}"'.format(build.src_build_flags))
flags.append('ESPURNA_NAME="{env}"'.format(env=build.env))
flags.append('ESPURNA_RELEASE_NAME="{env}"'.format(env=build.env))

cmd = ["env"]
cmd.extend(flags)
Expand Down Expand Up @@ -110,7 +127,8 @@ def every(seq, nth, total):
raise ValueError("* Not in CI *")

parser = argparse.ArgumentParser()
parser.add_argument("version")
parser.add_argument("--version", required=True)
parser.add_argument("--destination", required=True)
parser.add_argument("--ignore", action="append")
args = parser.parse_args()

Expand All @@ -127,8 +145,9 @@ def every(seq, nth, total):

print("#!/bin/bash")
print("set -e -x")
print('export ESPURNA_VERSION="{}"'.format(args.version))
print('trap "ls -l ${TRAVIS_BUILD_DIR}/firmware/${ESPURNA_VERSION}" EXIT')
print('export ESPURNA_RELEASE_VERSION="{}"'.format(args.version))
print('export ESPURNA_RELEASE_DESTINATION="{}"'.format(args.destination))
print('trap "ls -l ${ESPURNA_RELEASE_DESTINATION}" EXIT')
print(
'echo "Selected thread #{} out of {}"'.format(
builder_thread + 1, builder_total_threads
Expand Down
6 changes: 5 additions & 1 deletion code/scripts/pio_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

Import("env", "projenv")

import os
CI = any([os.environ.get("TRAVIS"), os.environ.get("CI")])

# Always show warnings for project code
projenv.ProcessUnFlags("-w")

Expand All @@ -31,7 +34,8 @@
ldscripts_inject_libpath(env)

# two-step update hint when using 1MB boards
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_printsize)
if not CI:
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_printsize)

# disable postmortem printing to the uart. another one is in eboot, but this is what causes the most harm
if "DISABLE_POSTMORTEM_STACKDUMP" in env["CPPFLAGS"]:
Expand Down
16 changes: 11 additions & 5 deletions code/scripts/pio_pre.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from SCons.Script import ARGUMENTS


TRAVIS = os.environ.get("TRAVIS")
CI = any([os.environ.get("TRAVIS"), os.environ.get("CI")])
PIO_PLATFORM = env.PioPlatform()
CONFIG = env.GetProjectConfig()
VERBOSE = "1" == ARGUMENTS.get("PIOVERBOSE", "0")
Expand Down Expand Up @@ -97,8 +97,6 @@ def ensure_platform_updated():
# handle build flags through os environment.
# using env instead of ini to avoid platformio ini changing hash on every change
env.Append(
ESPURNA_VERSION=os.environ.get("ESPURNA_VERSION", ""),
ESPURNA_NAME=os.environ.get("ESPURNA_NAME", ""),
ESPURNA_BOARD=os.environ.get("ESPURNA_BOARD", ""),
ESPURNA_AUTH=os.environ.get("ESPURNA_AUTH", ""),
ESPURNA_FLAGS=os.environ.get("ESPURNA_FLAGS", "")
Expand All @@ -112,8 +110,16 @@ def ensure_platform_updated():
else:
env.Replace(UPLOAD_PROTOCOL="esptool")

# handle `-t release` parameters
if CI:
env.Append(
ESPURNA_RELEASE_NAME=os.environ.get("ESPURNA_RELEASE_NAME", ""),
ESPURNA_RELEASE_VERSION=os.environ.get("ESPURNA_RELEASE_VERSION", ""),
ESPURNA_RELEASE_DESTINATION=os.environ.get("ESPURNA_RELEASE_DESTINATION", "")
)

# updates arduino core git to the latest master commit
if TRAVIS:
if CI:
package_overrides = env.GetProjectOption("platform_packages")
for package in package_overrides:
if "https://github.com/esp8266/Arduino.git" in package:
Expand All @@ -122,7 +128,7 @@ def ensure_platform_updated():

# to speed-up build process, install libraries in either global or local shared storage
if os.environ.get("ESPURNA_PIO_SHARED_LIBRARIES"):
if TRAVIS:
if CI:
storage = None
log("using global library storage")
else:
Expand Down

0 comments on commit 492a359

Please sign in to comment.