Unverified Commit 6fe21d90 authored by Giuseppe Carboni's avatar Giuseppe Carboni Committed by GitHub
Browse files

Implemented continuous integration (#897)

* First continuous integration attempt

* Firse continuous integration attempt

* Added push to ci workflow

* Another attempt

* Third attempt

* Fourth attempt

* First parallel attempt

* Second parallel attempt

* Fix #891, continuous integration completed

This commit fixes the failing build of Medicina branch
parent c853c4a4
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
#!/usr/bin/env python
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
from googleapiclient.discovery import build
from googleapiclient.http import MediaIoBaseDownload
import os
import io

TOKEN_FILE = 'token.json'
VM_FILE_PATH = '/home/runner/discos_manager.ova'
ARCHIVE_FILE_PATH = '/home/runner/vagrant.tar.gz'
SCOPES = ['https://www.googleapis.com/auth/drive.readonly']

# Create the token file from the GH Secret
with open(TOKEN_FILE, 'w') as tokenfile:
    tokenfile.write(os.environ.get('GOOGLE_DRIVE_TOKEN'))

# Authenticate with the token and eventually update it
creds = Credentials.from_authorized_user_file(TOKEN_FILE, SCOPES)
if creds.expired and creds.refresh_token:
    creds.refresh(Request())

# Download the VM
creds = Credentials.from_authorized_user_file(TOKEN_FILE, SCOPES)
if creds.expired and creds.refresh_token:
    creds.refresh(Request())

service = build('drive', 'v3', credentials=creds)

downloader = MediaIoBaseDownload(
    io.FileIO(ARCHIVE_FILE_PATH, 'wb'),
    service.files().get_media(
        fileId=os.environ.get('PROVISIONED_ARCHIVE_GDRIVE_ID')
    )
)
done = False
while not done:
    _, done = downloader.next_chunk()

downloader = MediaIoBaseDownload(
    io.FileIO(VM_FILE_PATH, 'wb'),
    service.files().get_media(
        fileId=os.environ.get('PROVISIONED_VM_GDRIVE_ID'),
    ),
    chunksize=5*1024*1024
)
done = False
while not done:
    _, done = downloader.next_chunk()

# Finally update the token file
with open(TOKEN_FILE, 'w') as tokenfile:
    tokenfile.write(creds.to_json())
+4 −0
Original line number Diff line number Diff line
google-auth
google-auth-oauthlib
google-auth-httplib2
google-api-python-client
+31 −0
Original line number Diff line number Diff line
#!/usr/bin/env python
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
import os

TOKEN_FILE = 'token.json'
VM_FILE_PATH = '/home/runner/discos_manager.ova'
SCOPES = [
    'https://www.googleapis.com/auth/drive',
    'https://www.googleapis.com/auth/drive.file'
]

# Authenticate with the token and eventually update it
creds = Credentials.from_authorized_user_file(TOKEN_FILE, SCOPES)
if creds.expired and creds.refresh_token:
    creds.refresh(Request())

# Prepare the files to be uploaded
service = build('drive', 'v3', credentials=creds)
vm_media = MediaFileUpload(VM_FILE_PATH, resumable=True)
service.files().update(
    fileId=os.environ.get('DEPLOYED_VM_GDRIVE_ID'),
    media_body=vm_media,
    fields='id'
).execute()

# Finally update the token file
with open(TOKEN_FILE, 'w') as tokenfile:
    tokenfile.write(creds.to_json())
+70 −0
Original line number Diff line number Diff line
name: DISCOS deployment and build

on:
  push:
  workflow_dispatch:

jobs:
  deploy-discos:
    env:
      REPOSITORY_TOKEN: "${{ secrets.DEPENDENCIES_TOKEN }}"
      GH_TOKEN: "${{ secrets.GH_WORKFLOWS_TOKEN }}"
      GOOGLE_DRIVE_TOKEN: "${{ secrets.GOOGLE_DRIVE_TOKEN }}"
      PROVISIONED_VM_GDRIVE_ID: "${{ secrets.PROVISIONED_VM_GDRIVE_ID }}"
      PROVISIONED_ARCHIVE_GDRIVE_ID: "${{ secrets.PROVISIONED_ARCHIVE_GDRIVE_ID }}"
    strategy:
      fail-fast: false
      matrix:
        station: ['SRT', 'Medicina', 'Noto']
    runs-on: ubuntu-22.04
    steps:
      - name: Free up space
        uses: jlumbroso/free-disk-space@main
        with:
          tool-cache: true
      - name: Install Vagrant
        run: |
          wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
          echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
          sudo apt update && sudo apt install vagrant
      - name: Install VirtualBox
        run: |
          wget https://download.virtualbox.org/virtualbox/7.0.14/virtualbox-7.0_7.0.14-161095~Ubuntu~jammy_amd64.deb
          sudo apt install ./virtualbox-7.0_7.0.14-161095~Ubuntu~jammy_amd64.deb
      - name: Clone the repository
        uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3'
          check-latest: true
      - name: Download the provisioned virtual machine from Google Drive
        run: |
          pip install -r .github/utils/gdrive_requirements.txt
          python .github/utils/download_from_gdrive.py
          gh secret set GOOGLE_DRIVE_TOKEN --org discos --visibility selected --repos discos,deployment < token.json
      - name: Install the virtual machine
        run: |
          vboxmanage import discos_manager.ova --vsys 0 --options keepallmacs
          rm discos_manager.ova
          tar -xzvf vagrant.tar.gz
        working-directory: /home/runner
      - name: Add the virtual machine to Vagrant
        run: |
          sed -i "s/$(cat id)/$(vboxmanage list vms | grep 'discos_manager' | grep -oP '(?<=\{)[0-9a-fA-F-]+(?=\})')/" action_provision
          sed -i "s/$(cat id)/$(vboxmanage list vms | grep 'discos_manager' | grep -oP '(?<=\{)[0-9a-fA-F-]+(?=\})')/" id
        working-directory: /home/runner/.deployment/.vagrant/machines/manager/virtualbox/
      - name: Clone the deployment repository
        uses: actions/checkout@v4
        with:
          repository: 'discos/deployment'
      - name: Install deployment package and dependencies
        run: |
          python -m pip install -r requirements.txt
          pip install .
      - name: Deploy DISCOS
        run: |
          discos-deploy manager:development --deploy-only -s ${{ matrix.station }} -b ${{ github.ref_name }}
      - name: Shutdown the virtual machine
        run: |
          discos-vms stop
+3 −20
Original line number Diff line number Diff line
/********************************************************************************
** Form generated from reading ui file 'MedicinaActiveSurfaceGUI.ui'
** Form generated from reading UI file 'MedicinaActiveSurfaceGUI.ui'
**
** Created: Wed Dec 7 09:22:24 2022
**      by: Qt User Interface Compiler version 4.5.2
** Created by: Qt User Interface Compiler version 4.8.7
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef MEDICINAACTIVESURFACEGUI_H
@@ -17675,9 +17674,6 @@ public:
        buttonGroup1->setEnabled(false);
        buttonGroup1->setGeometry(QRect(970, 448, 288, 291));
        CalibrateButton = new QPushButton(buttonGroup1);
        QButtonGroup *buttonGroup = new QButtonGroup(MedicinaActiveSurfaceGUI);
        buttonGroup->setObjectName(QString::fromUtf8("buttonGroup"));
        buttonGroup->addButton(CalibrateButton);
        CalibrateButton->setObjectName(QString::fromUtf8("CalibrateButton"));
        CalibrateButton->setGeometry(QRect(192, 45, 90, 35));
        QPalette palette321;
@@ -17731,7 +17727,6 @@ public:
        palette321.setBrush(QPalette::Disabled, QPalette::LinkVisited, brush10);
        CalibrateButton->setPalette(palette321);
        StopButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(StopButton);
        StopButton->setObjectName(QString::fromUtf8("StopButton"));
        StopButton->setGeometry(QRect(4, 5, 90, 35));
        QPalette palette322;
@@ -17785,7 +17780,6 @@ public:
        palette322.setBrush(QPalette::Disabled, QPalette::LinkVisited, brush10);
        StopButton->setPalette(palette322);
        ResetButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(ResetButton);
        ResetButton->setObjectName(QString::fromUtf8("ResetButton"));
        ResetButton->setGeometry(QRect(98, 5, 90, 35));
        QPalette palette323;
@@ -17839,7 +17833,6 @@ public:
        palette323.setBrush(QPalette::Disabled, QPalette::LinkVisited, brush10);
        ResetButton->setPalette(palette323);
        RefPosButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(RefPosButton);
        RefPosButton->setObjectName(QString::fromUtf8("RefPosButton"));
        RefPosButton->setGeometry(QRect(4, 45, 90, 35));
        QPalette palette324;
@@ -17893,7 +17886,6 @@ public:
        palette324.setBrush(QPalette::Disabled, QPalette::LinkVisited, brush10);
        RefPosButton->setPalette(palette324);
        TopButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(TopButton);
        TopButton->setObjectName(QString::fromUtf8("TopButton"));
        TopButton->setGeometry(QRect(5, 125, 90, 35));
        QPalette palette325;
@@ -17947,7 +17939,6 @@ public:
        palette325.setBrush(QPalette::Disabled, QPalette::LinkVisited, brush10);
        TopButton->setPalette(palette325);
        StowButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(StowButton);
        StowButton->setObjectName(QString::fromUtf8("StowButton"));
        StowButton->setGeometry(QRect(98, 45, 90, 35));
        QPalette palette326;
@@ -18001,7 +17992,6 @@ public:
        palette326.setBrush(QPalette::Disabled, QPalette::LinkVisited, brush10);
        StowButton->setPalette(palette326);
        BottomButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(BottomButton);
        BottomButton->setObjectName(QString::fromUtf8("BottomButton"));
        BottomButton->setGeometry(QRect(98, 125, 90, 35));
        QPalette palette327;
@@ -18055,7 +18045,6 @@ public:
        palette327.setBrush(QPalette::Disabled, QPalette::LinkVisited, brush10);
        BottomButton->setPalette(palette327);
        SetupButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(SetupButton);
        SetupButton->setObjectName(QString::fromUtf8("SetupButton"));
        SetupButton->setGeometry(QRect(192, 5, 90, 35));
        QPalette palette328;
@@ -18109,7 +18098,6 @@ public:
        palette328.setBrush(QPalette::Disabled, QPalette::LinkVisited, brush10);
        SetupButton->setPalette(palette328);
        DownButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(DownButton);
        DownButton->setObjectName(QString::fromUtf8("DownButton"));
        DownButton->setGeometry(QRect(98, 85, 90, 35));
        QPalette palette329;
@@ -18163,7 +18151,6 @@ public:
        palette329.setBrush(QPalette::Disabled, QPalette::LinkVisited, brush10);
        DownButton->setPalette(palette329);
        UpButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(UpButton);
        UpButton->setObjectName(QString::fromUtf8("UpButton"));
        UpButton->setGeometry(QRect(4, 85, 90, 35));
        QPalette palette330;
@@ -18217,7 +18204,6 @@ public:
        palette330.setBrush(QPalette::Disabled, QPalette::LinkVisited, brush10);
        UpButton->setPalette(palette330);
        MoveButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(MoveButton);
        MoveButton->setObjectName(QString::fromUtf8("MoveButton"));
        MoveButton->setGeometry(QRect(5, 165, 90, 35));
        QPalette palette331;
@@ -18279,7 +18265,6 @@ public:
        ActuatorMovelineEdit->setAlignment(Qt::AlignRight);
        ActuatorMovelineEdit->setReadOnly(false);
        CorrectionButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(CorrectionButton);
        CorrectionButton->setObjectName(QString::fromUtf8("CorrectionButton"));
        CorrectionButton->setGeometry(QRect(5, 205, 90, 35));
        QPalette palette332;
@@ -18339,7 +18324,6 @@ public:
        ActuatorCorrectionlineEdit->setAlignment(Qt::AlignRight);
        ActuatorCorrectionlineEdit->setReadOnly(false);
        UpdateButton = new QPushButton(buttonGroup1);
        buttonGroup->addButton(UpdateButton);
        UpdateButton->setObjectName(QString::fromUtf8("UpdateButton"));
        UpdateButton->setGeometry(QRect(5, 245, 90, 35));
        QPalette palette333;
@@ -20676,7 +20660,6 @@ public:
        StatuslineEdit_2->setText(QString());
        StatuslineEdit->setStyleSheet(QApplication::translate("MedicinaActiveSurfaceGUI", "background-color: rgb(0, 85, 255);", 0, QApplication::UnicodeUTF8));
        StatuslineEdit->setText(QApplication::translate("MedicinaActiveSurfaceGUI", "STATUS", 0, QApplication::UnicodeUTF8));
        Q_UNUSED(MedicinaActiveSurfaceGUI);
    } // retranslateUi
};
Loading