diff --git a/.github/workflows/Run unit tests and build.yml b/.github/workflows/Run unit tests and build.yml new file mode 100644 index 00000000..982ce1d7 --- /dev/null +++ b/.github/workflows/Run unit tests and build.yml @@ -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' \ No newline at end of file diff --git a/.github/workflows/trigger-azure-pipeline.yml b/.github/workflows/trigger-azure-pipeline.yml new file mode 100644 index 00000000..b8be5ded --- /dev/null +++ b/.github/workflows/trigger-azure-pipeline.yml @@ -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" diff --git a/pipeline/scripts/Build.ps1 b/pipeline/scripts/Build.ps1 new file mode 100644 index 00000000..d07b7519 --- /dev/null +++ b/pipeline/scripts/Build.ps1 @@ -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 +}