From 492a35926fcbd62b4b01059f033216f7d64ff48f Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Wed, 8 Apr 2020 17:24:59 +0300 Subject: [PATCH] ci: rework build.sh & release.sh generator - don't depend on TRAVIS environment variables - depend on CI flag to add release variables - chmod +x --- code/build.sh | 5 ++++- code/scripts/espurna_utils/release.py | 8 ++++---- code/scripts/generate_release_sh.py | 27 +++++++++++++++++++++++---- code/scripts/pio_main.py | 6 +++++- code/scripts/pio_pre.py | 16 +++++++++++----- 5 files changed, 47 insertions(+), 15 deletions(-) mode change 100644 => 100755 code/scripts/generate_release_sh.py diff --git a/code/build.sh b/code/build.sh index 1a29215f..733d2a04 100755 --- a/code/build.sh +++ b/code/build.sh @@ -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 "--------------------------------------------------------------" } diff --git a/code/scripts/espurna_utils/release.py b/code/scripts/espurna_utils/release.py index 2148cf33..9ffd9842 100644 --- a/code/scripts/espurna_utils/release.py +++ b/code/scripts/espurna_utils/release.py @@ -3,13 +3,13 @@ import shutil 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) diff --git a/code/scripts/generate_release_sh.py b/code/scripts/generate_release_sh.py old mode 100644 new mode 100755 index d64dac1f..baed6aad --- a/code/scripts/generate_release_sh.py +++ b/code/scripts/generate_release_sh.py @@ -1,3 +1,20 @@ +#!/usr/bin/env python +# +# Copyright (C) 2020 by Maxim Prokhorov +# +# 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 . + import os import argparse import re @@ -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) @@ -110,7 +127,8 @@ if __name__ == "__main__": 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() @@ -127,8 +145,9 @@ if __name__ == "__main__": 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 diff --git a/code/scripts/pio_main.py b/code/scripts/pio_main.py index 329fb97b..0661d15b 100644 --- a/code/scripts/pio_main.py +++ b/code/scripts/pio_main.py @@ -22,6 +22,9 @@ from espurna_utils import ( Import("env", "projenv") +import os +CI = any([os.environ.get("TRAVIS"), os.environ.get("CI")]) + # Always show warnings for project code projenv.ProcessUnFlags("-w") @@ -31,7 +34,8 @@ remove_float_support(env) 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"]: diff --git a/code/scripts/pio_pre.py b/code/scripts/pio_pre.py index 7864089f..e280bba0 100644 --- a/code/scripts/pio_pre.py +++ b/code/scripts/pio_pre.py @@ -20,7 +20,7 @@ import sys 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") @@ -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", "") @@ -112,8 +110,16 @@ if ESPURNA_OTA_PORT: 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: @@ -122,7 +128,7 @@ if TRAVIS: # 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: