Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
85 changes: 85 additions & 0 deletions .github/workflows/Run unit tests and build.yml
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: ${{ vars.AgentWorkingFolder }}
RelativePathScripts: ${{ vars.AgentWorkingFolder }}/pipeline/scripts

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

- 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'
56 changes: 56 additions & 0 deletions .github/workflows/trigger-azure-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: PR Triggered Tests

on:
pull_request_target:
types: [opened, synchronize, reopened]

jobs:
trigger-azure-pipeline:
runs-on: ubuntu-latest
if: contains(github.event.pull_request.base.ref, 'develop')
steps:
- name: Check if authorized to run tests
id: check
run: |
# Add any conditions if necessary. For now, always allow.
echo "ok=true" >> $GITHUB_OUTPUT

- name: Trigger Azure DevOps Pipeline
if: steps.check.outputs.ok == 'true'
run: |
PAT="${{ secrets.AZURE_DEVOPS_PAT }}"
ORG="sergiovelderrain"
PROJECT="sergiovelderrain"
PIPELINE_ID="1"
API_VERSION="6.0-preview.1"

# Ensure PAT is not empty
if [ -z "$PAT" ]; then
echo "AZURE_DEVOPS_PAT is not set or empty!"
exit 1
fi

# Base64 encode credentials
AUTH=$(echo -n ":$PAT" | base64)

# Use the PR's head ref for the pipeline branch
PR_HEAD_REF="${{ github.event.pull_request.head.ref }}"
JSON_BODY='{
"resources": {
"repositories": {
"self": {
"refName": "refs/heads/'"${PR_HEAD_REF}"'"
}
}
}
}'

echo "Triggering Azure DevOps pipeline with the following JSON:"
echo "$JSON_BODY"

# Use --http1.1 to avoid HTTP/2 related issues, remove -s for verbosity
curl --http1.1 -v -X POST \
-H "Authorization: Basic $AUTH" \
-H "Content-Type: application/json" \
-d "$JSON_BODY" \
"https://dev.azure.com/$ORG/$PROJECT/_apis/pipelines/$PIPELINE_ID/runs?api-version=$API_VERSION"
112 changes: 112 additions & 0 deletions pipeline/scripts/Build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# .\Build.ps1 -RelativePath "C:\labview-icon-editor" -AbsolutePathScripts "C:\labview-icon-editor\pipeline\scripts"
param(
[Parameter(Mandatory = $true)]
[string]$RelativePath,

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

# Helper function to check for file or directory existence
function Assert-PathExists {
param(
[string]$Path,
[string]$Description
)
if (-Not (Test-Path -Path $Path)) {
Write-Host "The $Description does not exist: $Path" -ForegroundColor Red
exit 1
}
}

# 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 $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
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
Execute-Script "$($AbsolutePathScripts)\Applyvipc.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 32 -RelativePath `"$RelativePath`" -VIPCPath `"Tooling\deployment\Dependencies.vipc`" -VIP_LVVersion 2021"

# 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
Execute-Script "$($AbsolutePathScripts)\Close_LabVIEW.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 32"

# 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
Execute-Script "$($AbsolutePathScripts)\RunUnitTests.ps1" `
"-MinimumSupportedLVVersion 2021 -SupportedBitness 64 -RelativePath `"$RelativePath`""

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

# Rename the file after build
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"

# 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
exit 1
}