Skip to content
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

Feature/85 powershell azure integration #86

Merged
merged 34 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a39486f
Merge branch 'develop' into users/svelderrain/ci-cd
svelderrainruiz Nov 24, 2024
cbca779
Merge branch 'develop' into users/svelderrain/ci-cd
svelderrainruiz Dec 3, 2024
4f9e11f
Adding powershell callls to the YAML file
svelderrainruiz Dec 3, 2024
5798df9
Had a mistake on the relative path, was pointing to a different worki…
svelderrainruiz Dec 3, 2024
be4734b
YAML now calls Build.ps1 script directly to have the same way of buil…
svelderrainruiz Dec 3, 2024
25bbebf
no message
svelderrainruiz Dec 3, 2024
e3d033e
no message
svelderrainruiz Dec 3, 2024
b1f9659
no message
svelderrainruiz Dec 3, 2024
4d94e08
no message
svelderrainruiz Dec 3, 2024
3eccec2
no message
svelderrainruiz Dec 3, 2024
3eb7e2c
Merge branch 'develop' into users/svelderrain/ci-cd
svelderrainruiz Dec 4, 2024
5bda59e
Progress: Added error handling to the VI that zip vi.lib, previous r…
svelderrainruiz Dec 4, 2024
c0c8cb4
Added the correct message
svelderrainruiz Dec 4, 2024
3a1a294
Can build the VI Package now,
svelderrainruiz Dec 4, 2024
71aff90
s
svelderrainruiz Dec 4, 2024
b308bb6
Update azure-pipelines.yml
svelderrainruiz Dec 4, 2024
f417b69
Update azure-pipelines.yml
svelderrainruiz Dec 4, 2024
2ab9473
Update azure-pipelines.yml
svelderrainruiz Dec 4, 2024
4a7643f
Removed a breakpoint stopping the agent
svelderrainruiz Dec 4, 2024
033ebbb
Using a powershell task on YAML file, made the build.ps1 to provide m…
svelderrainruiz Dec 4, 2024
c95b077
Revert "Using a powershell task on YAML file, made the build.ps1 to p…
svelderrainruiz Dec 4, 2024
3f2c2e6
Added error checking
svelderrainruiz Dec 4, 2024
3bcb187
Merge branch 'users/svelderrain/ci-cd' into feature/85-powershell-azu…
svelderrainruiz Dec 4, 2024
72c6255
Made a change on the way we setup the agent into development mode.
svelderrainruiz Dec 5, 2024
ab8a88a
Made a correction on a path from YAML file that was updated on the po…
svelderrainruiz Dec 5, 2024
b777d1d
Update Set_Development_Mode.ps1
svelderrainruiz Dec 5, 2024
82a9be4
Update Set_Development_Mode.ps1
svelderrainruiz Dec 5, 2024
13f9ff7
Revert "Update Set_Development_Mode.ps1"
svelderrainruiz Dec 5, 2024
5411c0a
Setting to development mode only on the YAML pipeline
svelderrainruiz Dec 5, 2024
7f985a6
Was missing closing LabVIEW 64 bits at the end of the build, leaving …
svelderrainruiz Dec 5, 2024
5dd99aa
Adding a setup and cleanup stage to the YAML file
svelderrainruiz Dec 5, 2024
d1d129d
Updated the github action to match the same logic as the Azure devops…
svelderrainruiz Dec 5, 2024
40ff5de
Updated this scripts since it was failing
svelderrainruiz Dec 5, 2024
14ae67a
Removed restoring the agent
svelderrainruiz Dec 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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