Skip to content

Commit

Permalink
deps: Add the possibility to use scripts in deps.json, for check-deps
Browse files Browse the repository at this point in the history
Add the possibility to use scripts in the deps.json file, that are
checked by the check-deps task. Also, add the dotnet-sdk-* and the
mono-devel install scripts.

Signed-off-by: Andre Riesco <[email protected]>
  • Loading branch information
andreriesco committed Mar 15, 2024
1 parent e083e2d commit 422abcb
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 52 deletions.
6 changes: 4 additions & 2 deletions aspnetBlazor/.conf/deps.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"packages": [
"openssh-client",
"sshpass",
"dotnet-sdk-6.0"
"sshpass"
],
"installDepsScripts": [
".conf/install-deps-scripts/install-dotnet-sdk-8.sh"
]
}
6 changes: 4 additions & 2 deletions dotnetAvalonia/.conf/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"packages": [
"openssh-client",
"sshpass",
"dotnet-sdk-7.0",
"dotnet-sdk-8.0",
"libgtk-3-dev"
],
"installDepsScripts": [
".conf/install-deps-scripts/install-dotnet-sdk-7.sh",
".conf/install-deps-scripts/install-dotnet-sdk-8.sh"
]
}
8 changes: 5 additions & 3 deletions dotnetAvaloniaFrameBuffer/.conf/deps.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"packages": [
"openssh-client",
"sshpass",
"dotnet-sdk-8.0",
"dotnet-sdk-7.0"
"sshpass"
],
"installDepsScripts": [
".conf/install-deps-scripts/install-dotnet-sdk-7.sh",
".conf/install-deps-scripts/install-dotnet-sdk-8.sh"
]
}
6 changes: 4 additions & 2 deletions dotnetConsole/.conf/deps.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"packages": [
"openssh-client",
"sshpass",
"dotnet-sdk-8.0"
"sshpass"
],
"installDepsScripts": [
".conf/install-deps-scripts/install-dotnet-sdk-8.sh"
]
}
6 changes: 4 additions & 2 deletions dotnetSlint/.conf/deps.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"packages": [
"openssh-client",
"sshpass",
"dotnet-sdk-8.0"
"sshpass"
],
"installDepsScripts": [
".conf/install-deps-scripts/install-dotnet-sdk-8.sh"
]
}
4 changes: 3 additions & 1 deletion dotnetUno/.conf/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"packages": [
"openssh-client",
"sshpass",
"dotnet-sdk-6.0",
"libgtk-3-dev"
],
"installDepsScripts": [
".conf/install-deps-scripts/install-dotnet-sdk-6.sh"
]
}
4 changes: 3 additions & 1 deletion dotnetUno5/.conf/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"packages": [
"openssh-client",
"sshpass",
"dotnet-sdk-8.0",
"libgtk-3-dev"
],
"installDepsScripts": [
".conf/install-deps-scripts/install-dotnet-sdk-8.sh"
]
}
4 changes: 3 additions & 1 deletion dotnetUno5FrameBuffer/.conf/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"packages": [
"openssh-client",
"sshpass",
"dotnet-sdk-8.0",
"libgtk-3-dev"
],
"installDepsScripts": [
".conf/install-deps-scripts/install-dotnet-sdk-8.sh"
]
}
6 changes: 4 additions & 2 deletions dotnetUnoFrameBuffer/.conf/deps.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"packages": [
"openssh-client",
"sshpass",
"dotnet-sdk-6.0"
"sshpass"
],
"installDepsScripts": [
".conf/install-deps-scripts/install-dotnet-sdk-6.sh"
]
}
6 changes: 3 additions & 3 deletions monoCsharpForms/.conf/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"packages": [
"openssh-client",
"sshpass",
"mono-complete",
"mono-roslyn",
"mono-dbg",
"msbuild",
"nuget"
],
"installDepsScripts": [
".conf/install-deps-scripts/install-mono-devel.sh"
]
}
33 changes: 33 additions & 0 deletions monoCsharpForms/.conf/install-deps-scripts/install-mono-devel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
set -e

# This is a script to install .MOno on Ubuntu, based on the official Mono project recommended method of installation:
# https://www.mono-project.com/download/stable/#download-lin

package='mono-devel'


# Get the source URL of the mono-devel package installed
source=$(apt policy $package | awk '/ \*/{getline; print $2}')


# Check if the dotnet-sdk installed package comes from the Microsoft source
if [ "$source" != "https://download.mono-project.com/repo/ubuntu" ]; then

sudo apt install ca-certificates gnupg -y

# Get and install mono signing key and repository
sudo gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF -y

# Remove the mono-devel installation that doesn't come from the Microsoft source
sudo apt-get remove $package -y

sudo apt-get autoremove -y

fi

# Update packages
sudo apt update -y

# Install the mono-devel that come from the Microsoft source
sudo apt-get install $package -y
129 changes: 104 additions & 25 deletions scripts/checkDeps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ if ($Env:GITLAB_CI -eq $true) {
$Env:DOCKER_HOST = "tcp://docker:2375"
}

# tested on Ubuntu 22.04
$_packages = Get-Content .conf/deps.json | ConvertFrom-Json

# docker and docker-compose are special cases
# TODO: check also for podman or other runtime
Expand All @@ -40,48 +38,129 @@ if ($? -eq $false || [string]::IsNullOrEmpty($_dockerComposeV)) {
exit 69
}

# Get the deps at .conf/deps.json file
$_deps = Get-Content .conf/deps.json | ConvertFrom-Json


# ok docker and docker-compose exist so let's check the packages
$_packagesToInstall = New-Object Collections.Generic.List[string]


# Check if all dependencies are installed
Write-Host -ForegroundColor Yellow "Checking dependencies ..."

foreach ($package in $_packages.packages) {
foreach ($package in $_deps.packages) {

dpkg -s $package > /dev/null 2>&1

if ($? -eq $false) {
$_packagesToInstall.Add($package)
Write-Host -ForegroundColor DarkRed "😵 $package not installed"
Write-Host -ForegroundColor DarkRed "😵 $package debian package dependency not installed"
} else {
Write-Host -ForegroundColor DarkGreen "👍 $package debian package dependency installed"
}
}

$_scriptsToInstall = New-Object Collections.Generic.List[string]

# Check if all dependency installation scripts have been executed before for this project on this machine
foreach ($script in $_deps.installDepsScripts) {
# For scripts, check if their name is present at the .conf/.depok file to see if they have been executed before
$scriptInstalled = (Test-Path ./.conf/.depok) -and (Get-Content ./.conf/.depok | Select-String $script -Quiet)

if ($scriptInstalled -eq $false) {
$_scriptsToInstall.Add($script)
Write-Host -ForegroundColor DarkRed "😵 $script dependency installation script not executed before for this project on this machine"
} else {
Write-Host -ForegroundColor DarkGreen "👍 $package installed"
Write-Host -ForegroundColor DarkGreen "👍 $script dependency installation script executed before for this project on this machine"
}
}

# ask if the user want to install the packages that are not installed
if ($_packagesToInstall.Count -gt 0) {
# Check if there are any packages to be installed or scripts to be executed
if ($_packagesToInstall.Count -eq 0 -and $_scriptsToInstall.Count -eq 0) {
Write-Host -ForegroundColor DarkGreen "✅ All packages already installed and installation script executed before for this project on this machine"

# we need to ran the check deps only if it's not ran yet
New-Item -Path .conf/ -Name .depok -ItemType File 2>&1 | out-null
} else {

$_packagesInstalledOk = $true
$_scriptsInstalledOk = $true

# ask if the user want to install the packages that are not installed
if ($_packagesToInstall.Count -gt 0) {

$_packagesInstalledOk = $false

$_installConfirm = Read-Host `
"Do you want to try to install the dependencies? <y/N>"

if ($_installConfirm -eq 'y') {
# make sure to update the list first
sudo apt-get update

foreach ($item in $_packagesToInstall) {
sudo apt-get install -y $item

if ($? -eq $false) {
Write-Host -ForegroundColor DarkRed "❌ error trying to install package $item"
exit 69
"Do you want to try to install the missing debian package dependencies? <y/N>"

if ($_installConfirm -eq 'y') {
# make sure to update the list first
sudo apt-get update

$_installedScrips = New-Object Collections.Generic.List[string]

# Try to install the packages
foreach ($item in $_packagesToInstall) {
sudo apt-get install -y $item

if ($? -eq $false) {
Write-Host -ForegroundColor DarkRed "❌ error trying to install package $item"
exit 69
}
}

Write-Host -ForegroundColor DarkGreen "✅ All packages installed successfully"

$_packagesInstalledOk = $true

}
}
# ask if the user want to execute the installation scripts that have not been executed before for this project on this machine
if ($_scriptsToInstall.Count -gt 0) {

$_scriptsInstalledOk = $false

$_installConfirm = Read-Host `
"Do you want to try to install the missing debian package dependencies? <y/N>"

if ($_installConfirm -eq 'y') {

$_installedScrips = New-Object Collections.Generic.List[string]

# Try to execute the installation scripts
foreach ($item in $_scriptsToInstall) {
if ($item.EndsWith('.sh')) {
chmod +x $item
}

$_installedScrips.Add($item)
& ./$item 2>&1

if ($? -eq $false) {
Write-Host -ForegroundColor DarkRed "❌ error trying to execute the dependency installation script $item"
exit 69
}
}

Write-Host -ForegroundColor DarkGreen "✅ All packages dependency installation scripts executed successfully"

$_scriptsInstalledOk = $true

}
}

Write-Host -ForegroundColor DarkGreen "✅ All packages installed successfully"
if ($_packagesInstalledOk -eq $true -and $_scriptsInstalledOk -eq $true) {

# all packages installed then dep ok
New-Item -Path .conf/ -Name .depok -ItemType File 2>&1 | out-null

# Add the name of the scripts to the .conf/.depok to know that it has
# already been executed for this project on this machine
foreach ($item in $_installedScrips) {
Add-Content -Path ./.conf/.depok -Value ("$item" + "`n")
}
}
} else {
Write-Host -ForegroundColor DarkGreen "✅ All packages already installed"

# we need to ran the check deps only if it's not ran yet
New-Item -Path .conf/ -Name .depok -ItemType File 2>&1 | out-null
}
42 changes: 34 additions & 8 deletions scripts/createFromTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Write-Host "Container Name -> $containerName"

# get the metadata
$_metadata = Get-Content "$templateFolder/../templates.json" | ConvertFrom-Json
$_templateMetadata =
$_templateMetadata =
$_metadata.Templates |
Where-Object { $_.folder -eq $template }

Expand Down Expand Up @@ -113,14 +113,14 @@ Write-Host -ForegroundColor DarkGreen "✅ Folder copy done"
# apply the common tasks and inputs
if ($_templateMetadata.mergeCommon -ne $False) {
Write-Host -ForegroundColor Yellow "Applying common tasks ..."
$commonTasks =
Get-Content "$templateFolder/../assets/tasks/common.json" |
$commonTasks =
Get-Content "$templateFolder/../assets/tasks/common.json" |
ConvertFrom-Json
$commonInputs =
Get-Content "$templateFolder/../assets/tasks/inputs.json" |
$commonInputs =
Get-Content "$templateFolder/../assets/tasks/inputs.json" |
ConvertFrom-Json
$projTasks =
Get-Content "$location/.vscode/tasks.json" |
$projTasks =
Get-Content "$location/.vscode/tasks.json" |
ConvertFrom-Json

$projTasks.tasks += $commonTasks.tasks
Expand All @@ -146,6 +146,32 @@ Copy-Item "$templateFolder/../scripts/torizonIO.ps1" "$location/.conf"
Copy-Item "$templateFolder/../scripts/checkCIEnv.ps1" "$location/.conf"
Copy-Item "$templateFolder/../scripts/validateDepsRunning.ps1" "$location/.conf"

# Check if there are scripts defined in the .conf/deps.json of the template and, if so,
# copy them to the .conf of the project
$_deps = Get-Content "$templateFolder/.conf/deps.json" | ConvertFrom-Json

# If there are installation scripts listed on the .conf/deps.json of the template
if (($_deps.installDepsScripts.Count -gt 0)) {
# Create the .conf/install-deps-scripts if it doesn't exist and there are
# installation scripts that have the path .conf/install-deps-scripts
if (-not (Test-Path -Path "$location/.conf/install-deps-scripts" )){
New-Item -ItemType Directory -Path "$location/.conf/install-deps-scripts"
}

# If there is no script in the .conf/install-deps-scripts of the template, but there is some script defined in the
# installDepsScripts with the .conf/install-deps-scripts path, then it comes from the scripts/install-deps-scripts
# folder of the vscode-torizon-templates repo. This is useful when there are scripts that are common for many
# templates, like the install-dotnet-sdk-8.sh one for example.
foreach ($script in $_deps.installDepsScripts) {
if ((-not (Test-Path -Path "$location/$script" )) -and
$script -match ".conf/install-deps-scripts") {
# Copy the script from the scripts/install-deps-scripts folder to the .conf/install-deps-scripts folder of the template
$scriptSource = $script.Replace(".conf","scripts")
Copy-Item "$templateFolder/../$scriptSource" "$location/$script"
}
}
}

# copy the github actions if not exists
if (-not (Test-Path "$location/.github")) {
New-Item "$location/.github" -ItemType Directory
Expand Down Expand Up @@ -201,7 +227,7 @@ Get-ChildItem -Force -File -Recurse * | ForEach-Object {
ForEach-Object {
$_ -replace "__home__",$env:HOME
} | Set-Content $a

( Get-Content $a ) |
ForEach-Object {
$_ -replace "__templateFolder__", $template
Expand Down
Loading

0 comments on commit 422abcb

Please sign in to comment.