From 8ca7c5407de63531b92ee08a4c7b05384143b31c Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 7 Dec 2023 15:43:11 +0700 Subject: [PATCH 1/7] ci integration --- Jenkinsfile | 19 +++++++++++++++++++ gen_release.py | 16 ++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..971e5f9 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,19 @@ +pipeline { + agent any + + stages { + stage('Build') { + steps { + sh 'export PLATFORMIO_PATH=/root/.platformio/penv/bin/platformio' + sh 'python gen_release.py' + } + } + stage('Publish') { + steps { + sh 'mkdir -p artifacts' + sh 'cp -r release/ artifacts/' + archiveArtifacts artifacts: 'artifacts/**/*', fingerprint: true + } + } + } +} diff --git a/gen_release.py b/gen_release.py index 5e91300..0791e79 100644 --- a/gen_release.py +++ b/gen_release.py @@ -22,8 +22,16 @@ firmware_folder = os.path.join(current_dir, 'firmware') # Define the path to the release folder release_folder = os.path.join(current_dir, 'release') -# Add the path to the PlatformIO executable to the system PATH -platformio_path = os.path.expanduser('~/.platformio/penv/Scripts') +# Get the platformio path from environment variable +platformio_path = os.environ.get('PLATFORMIO_PATH') +# If the environment variable is not set, use the default path +if platformio_path is None: + if platform.system() == 'Darwin': + platformio_path = os.path.expanduser('~/.platformio/penv/bin/platformio') + elif platform.system() == 'Windows': + platformio_path = os.path.expanduser('~/.platformio/penv/Scripts/platformio.exe') + elif platform.system() == 'Linux': + platformio_path = os.path.expanduser('~/.platformio/penv/bin/platformio') if os.path.exists(release_folder): # If the release folder exists, delete it @@ -79,11 +87,11 @@ for environment in environments: # if argument is not supplied, build all environments listed in platformio.ini if len(sys.argv) == 1: - subprocess.run([f'{platformio_path}/platformio.exe', 'run','-c',f'{firmware_folder}/platformio.ini'], cwd=current_dir) + subprocess.run([f'{platformio_path}', 'run','-c',f'{firmware_folder}/platformio.ini'], cwd=current_dir) for environment in environments: if(len(sys.argv) > 1): - subprocess.run([f'{platformio_path}/platformio.exe', 'run', '-e', environment,'-c',f'{firmware_folder}/platformio.ini'], cwd=current_dir) + subprocess.run([f'{platformio_path}', 'run', '-e', environment,'-c',f'{firmware_folder}/platformio.ini'], cwd=current_dir) # Iterate over the subfolders in the firmware folder for subfolder in os.listdir(firmware_folder): From 2b728b55c5023aaf4fcae0eb13a70e3e9eba4e79 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 7 Dec 2023 15:45:02 +0700 Subject: [PATCH 2/7] Update Jenkinsfile --- Jenkinsfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 971e5f9..3c70497 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,6 +2,11 @@ pipeline { agent any stages { + stage('Clone') { + steps { + git branch: 'main', url: 'https://git.siwatsystem.com/ise-senior-iot/iot-firmware.git' + } + } stage('Build') { steps { sh 'export PLATFORMIO_PATH=/root/.platformio/penv/bin/platformio' From 816d31ad5f82307e99cc66e8407b1a0486b2c90b Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 7 Dec 2023 15:46:36 +0700 Subject: [PATCH 3/7] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3c70497..54ce469 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ pipeline { stage('Build') { steps { sh 'export PLATFORMIO_PATH=/root/.platformio/penv/bin/platformio' - sh 'python gen_release.py' + sh 'python3 gen_release.py' } } stage('Publish') { From 5f5176969f64b457bb3b4f1913bc76300310e743 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 7 Dec 2023 15:47:42 +0700 Subject: [PATCH 4/7] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 54ce469..9ef0dd4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ pipeline { stage('Build') { steps { sh 'export PLATFORMIO_PATH=/root/.platformio/penv/bin/platformio' - sh 'python3 gen_release.py' + sh '/usr/bin/python3 gen_release.py' } } stage('Publish') { From 1988bc953e07c3df38a2e2494120640a27cb0b05 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 7 Dec 2023 15:52:14 +0700 Subject: [PATCH 5/7] Update gen_release.py --- gen_release.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gen_release.py b/gen_release.py index 0791e79..24fa03b 100644 --- a/gen_release.py +++ b/gen_release.py @@ -19,6 +19,10 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) # Define the path to the firmware folder firmware_folder = os.path.join(current_dir, 'firmware') +# Create the firmware folder if it does not exist +if not os.path.exists(firmware_folder): + os.makedirs(firmware_folder) + # Define the path to the release folder release_folder = os.path.join(current_dir, 'release') From bc85bcf6015312b83a0272ab9e215c1cf1baf540 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 7 Dec 2023 16:02:28 +0700 Subject: [PATCH 6/7] Update Jenkinsfile --- Jenkinsfile | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9ef0dd4..dcf9353 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,22 +2,18 @@ pipeline { agent any stages { - stage('Clone') { - steps { - git branch: 'main', url: 'https://git.siwatsystem.com/ise-senior-iot/iot-firmware.git' - } - } stage('Build') { steps { + git branch: 'main', url: 'https://git.siwatsystem.com/ise-senior-iot/iot-firmware.git' sh 'export PLATFORMIO_PATH=/root/.platformio/penv/bin/platformio' sh '/usr/bin/python3 gen_release.py' + stash includes: 'release/**/*', name: 'release_binaries' } } stage('Publish') { steps { - sh 'mkdir -p artifacts' - sh 'cp -r release/ artifacts/' - archiveArtifacts artifacts: 'artifacts/**/*', fingerprint: true + unstash 'release_binaries' + archiveArtifacts artifacts: 'release/**/*', fingerprint: true } } } From 24871d2316e2dfa14874a12c00f9f16a6c675d7c Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 7 Dec 2023 16:09:42 +0700 Subject: [PATCH 7/7] Update platformio.ini --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index b32f365..da29e98 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -build_dir = .\firmware +build_dir = firmware [env:full] platform = espressif32