Skip to content

Commit

Permalink
Merge branch 'feature/85-powershell-azure-integration' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
svelderrainruiz committed Dec 5, 2024
2 parents aa31324 + 14ae67a commit 7529953
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 147 deletions.
65 changes: 0 additions & 65 deletions .github/workflows/Build VI packages.yml

This file was deleted.

85 changes: 85 additions & 0 deletions .github/workflows/Run unit tests and build
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# .github/workflows/build-and-test.yml

name: Build and Test LabVIEW Project

on:
push:
branches:
- develop

jobs:
build-and-test:
name: Build and Test the Icon Editor
runs-on: [self-hosted, iconeditor]

env:
build_id: ${{ github.run_number }}
build_revision: ${{ steps.get_revision.outputs.build_revision }}
build_version: 1.0.${{ env.build_id }}.${{ env.build_revision }}
RelativePath: ${{ github.workspace }}
RelativePathScripts: ${{ github.workspace }}/pipeline/scripts

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get Build Revision
id: get_revision
shell: bash
run: |
# Path to store the build revision counter
COUNTER_FILE="${GITHUB_WORKSPACE}/.github/buildCounter.txt"
echo "Counter file path: $COUNTER_FILE"

# Initialize the counter file if it doesn't exist
if [ ! -f "$COUNTER_FILE" ]; then
echo "Counter file not found. Initializing to 1."
echo "1" > "$COUNTER_FILE"
fi

# Read the current value
build_revision=$(cat "$COUNTER_FILE")
echo "Current build_revision: $build_revision"

# Increment the counter
new_build_revision=$((build_revision + 1))
echo "New build_revision: $new_build_revision"

# Save the new value back to the file
echo "$new_build_revision" > "$COUNTER_FILE"

# Set the output variable
echo "::set-output name=build_revision::$build_revision"

# For debugging
ls -la "${GITHUB_WORKSPACE}/.github"
cat "$COUNTER_FILE"

- name: Set agent into development mode
shell: pwsh
working-directory: ${{ env.RelativePathScripts }}
run: |
.\Set_Development_Mode.ps1 -RelativePath "${{ env.RelativePath }}"

- name: Test and Build the Icon Editor
shell: pwsh
working-directory: ${{ env.RelativePathScripts }}
env:
build_id: ${{ env.build_id }}
build_revision: ${{ env.build_revision }}
build_version: ${{ env.build_version }}
run: |
.\Build.ps1 -RelativePath "${{ env.RelativePath }}" -AbsolutePathScripts "${{ env.RelativePathScripts }}"

- name: Restore agent from development mode
shell: pwsh
working-directory: ${{ env.RelativePathScripts }}
run: |
.\RevertDevelopmentMode.ps1 -RelativePath "${{ env.RelativePath }}"

- name: Commit and Push Build Counter
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'Increment build revision to ${{ env.build_revision }}'
file_pattern: '.github/buildCounter.txt'
Binary file modified Tooling/PrepareIESource.vi
Binary file not shown.
31 changes: 24 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,44 @@ trigger:
include:
- main
- develop
- users/svelderrain/ci-cd # Use forward slashes for branch names

name: $(Build.BuildID)

pool:
pool:
name: "Default"
demands: "iconeditor -equals true"

variables:
build_id: $(Build.BuildID)
build_revision: $[counter('buildCounter',1)]
build_version: '1.0.$(Build.BuildID).$(build_revision)'
RelativePath: '$(Build.Repository.LocalPath)'
RelativePathScripts: '$(Build.Repository.LocalPath)\pipeline\scripts' # Consistently using backslashes
RelativePath: '$(Build.SourcesDirectory)'
RelativePathScripts: '$(Build.SourcesDirectory)\pipeline\scripts'

stages:
- stage: BuildAndTest
displayName: Build and Test LabVIEW Project
jobs:
- job: ExecuteScripts
displayName: Execute Build.ps1 via powershell
displayName: Execute Scripts
steps:
- script: |
powershell -NoProfile -ExecutionPolicy Bypass -File "$(Build.Repository.LocalPath)\pipeline\scripts\Build.ps1" -RelativePath "$(RelativePath)" -RelativePathScripts "$(RelativePathScripts)"
displayName: Test and build the icon editor
- task: PowerShell@2
displayName: 'Set agent into development mode'
inputs:
filePath: '$(RelativePathScripts)\Set_Development_Mode.ps1'
arguments: '-RelativePath "$(RelativePath)"'
workingDirectory: '$(RelativePathScripts)'
failOnStderr: true
errorActionPreference: 'Stop'

- task: PowerShell@2
displayName: 'Test and Build the Icon Editor'
inputs:
filePath: '$(RelativePathScripts)\Build.ps1'
arguments: >
-RelativePath "$(RelativePath)"
-AbsolutePathScripts "$(RelativePathScripts)"
workingDirectory: '$(RelativePathScripts)'
failOnStderr: true
errorActionPreference: 'Stop'
4 changes: 2 additions & 2 deletions pipeline/scripts/AddTokenToLabVIEW.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ param(

# Construct the command
$script = @"
g-cli --lv-ver $MinimumSupportedLVVersion --arch $SupportedBitness -v $RelativePath\Tooling\deployment\Create_LV_INI_Token.vi" -- LabVIEW Localhost.LibraryPaths "$RelativePath"
g-cli --lv-ver $MinimumSupportedLVVersion --arch $SupportedBitness -v "$RelativePath\Tooling\deployment\Create_LV_INI_Token.vi" -- "LabVIEW" "Localhost.LibraryPaths" "$RelativePath"
"@

Write-Output "Executing the following command:"
Expand All @@ -20,7 +20,7 @@ try {

# Check the exit code of the executed command
if ($LASTEXITCODE -eq 0) {
Write-Host "Unzip vi.lib/LabVIEW Icon API from LabVIEW $MinimumSupportedLVVersion ($SupportedBitness-bit) and remove localhost.library path from ini file"
Write-Host "Create localhost.library path from ini file"
}
} catch {
Write-Host ""
Expand Down
93 changes: 61 additions & 32 deletions pipeline/scripts/Build.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# .\Build.ps1 -RelativePath "C:\labview-icon-editor" -AbsolutePathScripts "C:\labview-icon-editor\pipeline\scripts"
param(
[Parameter(Mandatory = $true)]
[string]$RelativePath,

[Parameter(Mandatory = $true)]
[string]$RelativePathScripts
[string]$AbsolutePathScripts
)

# Helper function to check for file or directory existence
Expand All @@ -18,64 +19,92 @@ function Assert-PathExists {
}
}

# Helper function to execute scripts sequentially
function Execute-Script {
param(
[string]$ScriptPath,
[string]$Arguments
)
Write-Host "Executing: $ScriptPath $Arguments" -ForegroundColor Cyan
try {
# Build and execute the command
$command = "& `"$ScriptPath`" $Arguments"
Invoke-Expression $command

# Check for errors in the script execution
if ($LASTEXITCODE -ne 0) {
Write-Host "Error occurred while executing: $ScriptPath with arguments: $Arguments. Exit code: $LASTEXITCODE" -ForegroundColor Red
exit $LASTEXITCODE
}
} catch {
Write-Host "Error occurred while executing: $ScriptPath with arguments: $Arguments. Exiting." -ForegroundColor Red
exit 1
}
}

# Main script logic
try {
# Validate required paths
Assert-PathExists $RelativePath "RelativePath"
Assert-PathExists "$RelativePath\resource\plugins" "Plugins folder"
Assert-PathExists $RelativePathScripts "Scripts folder"
Assert-PathExists $AbsolutePathScripts "Scripts folder"

# Clean up .lvlibp files in the plugins folder
Write-Host "Cleaning up old .lvlibp files in plugins folder..." -ForegroundColor Yellow
$PluginFiles = Get-ChildItem -Path "`"$RelativePath\resource\plugins`"" -Filter '*.lvlibp' -ErrorAction SilentlyContinue
$PluginFiles = Get-ChildItem -Path "$RelativePath\resource\plugins" -Filter '*.lvlibp' -ErrorAction SilentlyContinue
if ($PluginFiles) {
$PluginFiles | Remove-Item -Force
Write-Host "Deleted .lvlibp files from plugins folder." -ForegroundColor Green
} else {
Write-Host "No .lvlibp files found to delete." -ForegroundColor Cyan
}
# Set development mode

# Apply dependencies for LV 2021
Write-Host "Applying dependencies for LabVIEW 2021..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$RelativePathScripts\Applyvipc.ps1`" -MinimumSupportedLVVersion 2021 -SupportedBitness 32 -RelativePath `"$RelativePath`" -VIPCPath `"Tooling\deployment\Dependencies.vipc`" -VIP_LVVersion 2021" -NoNewWindow -Wait
Execute-Script "$($AbsolutePathScripts)\Applyvipc.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 32 -RelativePath `"$RelativePath`" -VIPCPath `"Tooling\deployment\Dependencies.vipc`" -VIP_LVVersion 2021"

# Add token to LabVIEW
Write-Host "Adding token to LabVIEW..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$RelativePathScripts\AddTokenToLabVIEW.ps1`" -MinimumSupportedLVVersion 2021 -SupportedBitness 32 -RelativePath `"$RelativePath`"" -NoNewWindow -Wait
# Run Unit Tests
Execute-Script "$($AbsolutePathScripts)\RunUnitTests.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 32 -RelativePath `"$RelativePath`""

# Build LV Library
Execute-Script "$($AbsolutePathScripts)\Build_lvlibp.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 32 -RelativePath `"$RelativePath`""

# Close LabVIEW
Write-Host "Closing LabVIEW..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$RelativePathScripts\Close_LabVIEW.ps1`" -MinimumSupportedLVVersion 2021 -SupportedBitness 32" -NoNewWindow -Wait

# Prepare LabVIEW source
Write-Host "Preparing LabVIEW source..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$RelativePathScripts\Prepare_LabVIEW_source.ps1`" -MinimumSupportedLVVersion 2021 -SupportedBitness 32 -RelativePath `"$RelativePath`" -LabVIEW_Project 'lv_icon_editor' -Build_Spec 'Editor Packed Library'" -NoNewWindow -Wait
# Close LabVIEW
Execute-Script "$($AbsolutePathScripts)\Close_LabVIEW.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 32"

# Close LabVIEW again
Write-Host "Closing LabVIEW again..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$RelativePathScripts\Close_LabVIEW.ps1`" -MinimumSupportedLVVersion 2021 -SupportedBitness 32" -NoNewWindow -Wait
# Rename the file after build
Execute-Script "$($AbsolutePathScripts)\Rename-File.ps1" `
"-CurrentFilename `"$RelativePath\resource\plugins\lv_icon.lvlibp`" -NewFilename 'lv_icon_x86.lvlibp'"

# Apply dependencies for LV 2021
Execute-Script "$($AbsolutePathScripts)\Applyvipc.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 64 -RelativePath `"$RelativePath`" -VIPCPath `"Tooling\deployment\Dependencies.vipc`" -VIP_LVVersion 2021"

# Run Unit Tests
Write-Host "Running unit tests..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$RelativePathScripts\RunUnitTests.ps1`" -MinimumSupportedLVVersion 2021 -SupportedBitness 32 -RelativePath `"$RelativePath`"" -NoNewWindow -Wait
Execute-Script "$($AbsolutePathScripts)\RunUnitTests.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 64 -RelativePath `"$RelativePath`""

# Build LV Library
Write-Host "Building LabVIEW library (.lvlibp)..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$RelativePathScripts\Build_lvlibp.ps1`" -MinimumSupportedLVVersion 2021 -SupportedBitness 32 -RelativePath `"$RelativePath`"" -NoNewWindow -Wait

# Restore LabVIEW source setup
Write-Host "Restoring LabVIEW source setup..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$RelativePathScripts\RestoreSetupLVSource.ps1`" -MinimumSupportedLVVersion 2021 -SupportedBitness 32 -RelativePath `"$RelativePath`" -LabVIEW_Project 'lv_icon_editor' -Build_Spec 'Editor Packed Library'" -NoNewWindow -Wait

# Close LabVIEW
Write-Host "Finalizing by closing LabVIEW..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$RelativePathScripts\Close_LabVIEW.ps1`" -MinimumSupportedLVVersion 2021 -SupportedBitness 32" -NoNewWindow -Wait
Execute-Script "$($AbsolutePathScripts)\Build_lvlibp.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 64 -RelativePath `"$RelativePath`""

# Rename the file after build
Write-Host "Renaming built library file..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$RelativePathScripts\Rename-File.ps1`" -CurrentFilename `"$RelativePath\resource\plugins\lv_icon.lvlibp`" -NewFilename 'lv_icon_x86.lvlibp'" -NoNewWindow -Wait
Execute-Script "$($AbsolutePathScripts)\Rename-File.ps1" `
"-CurrentFilename `"$RelativePath\resource\plugins\lv_icon.lvlibp`" -NewFilename 'lv_icon_x64.lvlibp'"

# Build VI Package
Execute-Script "$($AbsolutePathScripts)\build_vip.ps1" `
"-SupportedBitness 64 -RelativePath `"$RelativePath`" -VIPBPath `"Tooling\deployment\NI Icon editor.vipb`" -VIP_LVVersion 2021 -MinimumSupportedLVVersion 2021"

# Success message
# Close LabVIEW
Execute-Script "$($AbsolutePathScripts)\Close_LabVIEW.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 64"

Write-Host "All scripts executed successfully!" -ForegroundColor Green
} catch {
Write-Host "An unexpected error occurred during script execution: $($_.Exception.Message)" -ForegroundColor Red
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pipeline/scripts/Close_LabVIEW.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ try {
exit 1
}

Write-Host "Close LabVIEW $MinimumSupportedLVVersion ($SupportedBitness-bit)" .ps1
Write-Host "Close LabVIEW $MinimumSupportedLVVersion ($SupportedBitness-bit)"
Loading

0 comments on commit 7529953

Please sign in to comment.