Skip to content

Adding SDK Recursive Build Tool #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
81 changes: 81 additions & 0 deletions .github/workflows/recursiveBuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: SDK Recursive Build

on:
workflow_dispatch:
inputs:
build_type:
type: choice
description: Build all or only changed files
options:
- Only changed files
- All files
necto_type:
type: choice
description: Live or Development NECTO build
options:
- Development
- Live
pull_request:
branches:
- master

jobs:
recursiveBuild:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install aiohttp
pip install aiofiles
pip install requests
pip install py7zr
pip install elasticsearch==7.13.4
sudo apt-get update
sudo apt-get install p7zip-full
sudo apt-get install libopus-dev
sudo apt-get install libevent-dev
sudo apt-get install freeglut3-dev
sudo apt-get install libminizip-dev
sudo apt-get install libxcb-shape0-dev
sudo apt-get install libxcb-icccm4-dev
sudo apt-get install libxcb-cursor-dev
sudo apt-get install libxcb-keysyms1-dev
sudo apt-get install libxkbcommon-x11-dev

- name: Install NECTO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the workflow so that NECTO is installed after checking for changed files.

In other words install it only if there is a need to run the automated builds.

I assume you will need to split the recursive_build into two scripts.

run: |
if [[ "${{ github.event.inputs.necto_type }}" == 'Live' ]]; then
export NECTO_DOWNLOAD_URL=${{ secrets.NECTO_LIVE_DOWNLOAD_URL }}
else
export NECTO_DOWNLOAD_URL=${{ secrets.NECTO_DEV_DOWNLOAD_URL }}
fi
python -u scripts/install_necto.py

- name: Run Recursive Build
run: |
if [[ "${{ github.event.inputs.build_type }}" == 'All files' ]]; then
export BUILD_ALL=1
echo "Building all files."
else
export BUILD_ALL=0
echo "Building only changed files."
fi
python -u scripts/recursive_build.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the option to skip the build entirely. Maybe a script parameter which checks a commit message variable or branch name.


- name: Archive test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: /home/runner/test_results
82 changes: 82 additions & 0 deletions scripts/install_necto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import os
import shutil
import subprocess
import urllib.request

# Runs a shell command and prints the output.
def run_command(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
for line in process.stdout:
print(line.strip())
process.wait()
return process.returncode

def main():
original_working_dir = os.getcwd()
print(f"Original working directory: {original_working_dir}")

os.chdir('/home/runner/')
print(f"Script executed from: {os.getcwd()}")
print("Current folder contents")
for file in os.listdir(os.getcwd()):
print(file)

url = os.getenv('NECTO_DOWNLOAD_URL')
if 'live' in url:
print("Step 1: Downloading Live NECTOStudio version")
else:
print("Step 1: Downloading Development NECTOStudio version")
urllib.request.urlretrieve(url, "NECTOInstaller.zip")

print("Step 2: Extract installer")
run_command("7za x NECTOInstaller.zip")

print("Step 3: Install NECTO")
run_command("./NECTOInstaller installer --install-packages necto_installer necto_application database /home/runner/MikroElektronika /home/runner/.MIKROE/NECTOStudio7")

print("Step 4: Move installer to MIKROE if it's generated in root")
if os.path.isfile("/home/runner/MikroElektronika/installer_tmp"):
shutil.move("/home/runner/MikroElektronika/installer_tmp", "/home/runner/MikroElektronika/installer")

print("Step 5: Move instance_uuid.txt to MIKROE if it's generated in root")
if os.path.isfile("/home/runner/instance_uuid.txt"):
shutil.move("/home/runner/instance_uuid.txt", "/home/runner/MikroElektronika/instance_uuid.txt")

print("Step 6: Read hash from instance_uuid.txt")
with open("/home/runner/MikroElektronika/instance_uuid.txt", "r") as f:
line = f.readline().strip()

print("Step 7: Copy NECTOStudio.conf to current directory")
shutil.copy("/home/runner/.config/MikroElektronika/NECTOStudio.conf", "/home/runner/NECTOStudio.conf")

print("Step 8: Add the read hash to it")
with open("/home/runner/NECTOStudio.conf", "r+") as f:
content = f.read()
f.seek(0, 0)
f.write(f"[{line}]\n" + content)

print("Step 9: Copy it back to .config/MikroElektronika")
shutil.copy("/home/runner/NECTOStudio.conf", "/home/runner/.config/MikroElektronika/NECTOStudio.conf")

print("Step 10: Move installed_packages.json to MIKROE if it's generated in root")
if os.path.isfile("/home/runner/installed_packages.json"):
shutil.move("/home/runner/installed_packages.json", "/home/runner/MikroElektronika/installed_packages.json")

print("Step 11: Remove NECTOInstaller.zip")
os.remove("/home/runner/NECTOInstaller.zip")

print("Step 12: Remove NECTOInstaller")
os.remove("/home/runner/NECTOInstaller")

print("Step 13: Remove NECTOStudio.conf")
os.remove("/home/runner/NECTOStudio.conf")

print("Current folder contents")
for file in os.listdir(os.getcwd()):
print(file)

os.chdir(original_working_dir)
print(f"Returned to original working directory: {os.getcwd()}")

if __name__ == "__main__":
main()
Loading
Loading