Skip to content

Instantly share code, notes, and snippets.

@cprima
Last active February 8, 2024 17:10
Show Gist options
  • Save cprima/4be7d60c9b5501127c5760ee247fd27d to your computer and use it in GitHub Desktop.
Save cprima/4be7d60c9b5501127c5760ee247fd27d to your computer and use it in GitHub Desktop.
Project Basturma Pipelines: RPA UiPath Project Read-ProjectJson and Increment-SemVer

Project Basturma Pipelines

Welcome to the Project Basturma repository! This project is dedicated to providing robust CI/CD pipeline scripts and tools for UiPath RPA (Robotic Process Automation) development. The goal is to streamline the automation deployment process, ensuring efficient, consistent, and error-free delivery of RPA solutions.

@see github.com/rpapub/project-basturma-pipelines

Author

This project is created and maintained by Christian Prior-Mamulyan cprior@gmail.com

Licence

Creative Commons Attribution 4.0 International License (CC-BY)

# Author: Christian Prior-Mamulyan (cprior@gmail.com)
# Repository Location: https://github.com/rpapub/project-basturma-pipelines
# LICENSE: CC-BY
name: UiPath Cloud uipcli.exe Build and Deploy
on:
#push:
# branches:
# #- "**" # Trigger on pushes to any branch
# - master # Trigger on pushes to the master branch
pull_request:
branches:
- releases # Trigger on pushes to the releases branch
#schedule:
# - cron: "42 */2 * * *" # Trigger repeatedly, every 2 hours, at 42 minutes past the hour
workflow_dispatch: # Allow manual triggering of the workflow
env:
# Setting an environment variable with the value of a configuration variable
UIPATHCLOUDACCOUNTNAME: ${{ vars.UIPATHCLOUDACCOUNTNAME }}
UIPATHCLOUDAPPLICATIONID: ${{ vars.UIPATHCLOUDAPPLICATIONID }}
UIPATHCLOUDAPPLICATIONSCOPE: ${{ vars.UIPATHCLOUDAPPLICATIONSCOPE }}
UIPATHCLOUDFOLDERNAME: ${{ vars.UIPATHCLOUDFOLDERNAME }}
UIPATHCLOUDTENANTNAME: ${{ vars.UIPATHCLOUDTENANTNAME }}
UIPATHCLOUDORCHESTRATORURL: ${{ vars.UIPATHCLOUDORCHESTRATORURL }}
jobs:
build-and-deploy:
runs-on: windows-latest # Use a Windows runner
environment:
name: Development
steps:
- name: Checkout Repository
uses: actions/checkout@v3
# If you don't have commands for clearing old results, comment out or remove this step
#- name: Clear old job results
# run: # Add your commands to clear old results here
- name: Download and Extract UiPath CLI
run: |
$version = "23.6.8581.19168"
$extractPath = "C:\Program Files\uipcli"
$packageName = "UiPath.CLI.Windows"
$packageUrl = "https://uipath.pkgs.visualstudio.com/Public.Feeds/_packaging/UiPath-Official/nuget/v3/flat2/$packageName/$version/$packageName.$version.nupkg"
$tempPath = [System.IO.Path]::GetTempPath() + "$packageName.$version.nupkg"
$tempZipPath = [System.IO.Path]::GetTempPath() + "$packageName.$version.zip"
Invoke-WebRequest -Uri $packageUrl -OutFile $tempPath
Rename-Item -Path $tempPath -NewName $tempZipPath
Expand-Archive -Path $tempZipPath -DestinationPath $extractPath -Force
shell: pwsh
- name: Read project.json and echo version
run: |
$json = Get-Content "$env:GITHUB_WORKSPACE\project.json" -Raw | ConvertFrom-Json
$projectVersion = $json.projectVersion
echo "PROJECT_VERSION=$projectVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
$name = $json.name
echo "PROJECT_NAME=$name" | Out-File -FilePath $env:GITHUB_ENV -Append
echo $json
shell: pwsh
# New step to echo the PROJECT_VERSION
- name: Echo Project Version
run: |
echo "Project Version: $env:PROJECT_VERSION"
echo "Project Name: $env:PROJECT_NAME"
- name: Echo All Environment Variables
shell: pwsh
run: |
Get-ChildItem env: | ForEach-Object { Write-Host $_.Name = $_.Value }
- name: Run UiPath CLI Command
run: |
& 'C:\Program Files\uipcli\tools\uipcli.exe' package pack "$env:GITHUB_WORKSPACE\project.json" --output "output" --traceLevel Verbose --autoVersion --disableTelemetry --outputType Process
shell: pwsh
- name: List Contents of Output Directory
run: |
Get-ChildItem "output" -Recurse
shell: pwsh
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: uipcli-package-pack-output
path: output/${{ env.PROJECT_NAME }}*.nupkg
- name: Deploy to Development
run: |
# Specify the directory where NuGet packages are located
$nupkg_directory = "$env:GITHUB_WORKSPACE/output"
# List all NuGet package files in the directory
$nupkg_files = Get-ChildItem $nupkg_directory -Filter "${{ env.PROJECT_NAME }}*.nupkg" -File
if ($nupkg_files.Count -eq 0) {
echo "No matching NuGet package files found."
} elseif ($nupkg_files.Count -eq 1) {
# If only one matching file is found, use it
$nupkg_file = $nupkg_files[0].FullName
echo "NuGet Package File: $nupkg_file"
# Run uipcli.exe command with the selected package file
& 'C:\Program Files\uipcli\tools\uipcli.exe' package deploy "$nupkg_file" ${{ env.UIPATHCLOUDORCHESTRATORURL }} ${{ env.UIPATHCLOUDTENANTNAME }} --token ${{ secrets.UIPATHCLOUDADMINTENANTSERVICESAPIACCESSKEY }} --accountName ${{ env.UIPATHCLOUDACCOUNTNAME }}
} else {
echo "Multiple matching NuGet package files found. Unable to proceed."
}
shell: pwsh
PS D:\github.com\rpapub\basturma-pipelines\powershell> Import-Module .\src\SemVerTools\SemVerTools.psm1
PS D:\github.com\rpapub\basturma-pipelines\powershell> Import-Module .\src\UiPathCicdScripts\UiPathProjectJsonTools.psm1
PS D:\github.com\rpapub\basturma-pipelines\powershell> $projectJson = Read-ProjectJson -projectJsonPath "C:\Users\Public\Documents\UiPath\BlankProcess\project.json"
PS D:\github.com\rpapub\basturma-pipelines\powershell> Parse-SemVer -semVerString $projectJson.projectVersion
Name Value
---- -----
Major 1
Minor 1
Patch 10
PreRelease
Build
PS D:\github.com\rpapub\basturma-pipelines\powershell> Increment-SemVer $projectJson.projectVersion
1.1.11
PS D:\github.com\rpapub\basturma-pipelines\powershell> Increment-SemVer $projectJson.projectVersion -commitMessage 'Minor: New feature foobar'
1.2.0
PS D:\github.com\rpapub\basturma-pipelines\powershell> Increment-SemVer $projectJson.projectVersion -commitMessage 'Major: New GUI'
2.0.0
'''
UiPath Workflow Analyzer to SonarQube Converter
This script converts the results from the UiPath Workflow Analyzer into the
Generic Issue Import Format accepted by SonarQube.
Prerequisites:
- Requires the output from UiPath's Workflow Analyzer in JSON format.
How to obtain uipath-workflow-analyzer_results.json:
- Use the UiPath CLI tool with the following command:
uipcli.exe package analyze ./BlankProcess/project.json --resultPath path/to/uipath-workflow-analyzer_results.json
- Import with the following command:
sonar-scanner.bat -D"sonar.projectKey=yourkey42" -D"sonar.sources=." -D"sonar.host.url=http://your-sonar-url:9000" -D"sonar.login=sqp_foobar4782f7305137b0279b38e887e4e2foobar" -Dsonar.externalIssuesReportPaths=path/to/sonarqube_input.json
Todo:
- needs more error handling in case of null values
Author: Christian Prior-Mamulyan (cprior@gmail.com)
Repository Location: https://github.com/rpapub/project-basturma-pipelines
LICENSE: CC-BY
'''
import json
# Load UiPath Workflow Analyzer results
with open('uipath-workflow-analyzer_results.json', 'r', encoding='utf-8') as f:
uipath_results = json.load(f)
sonarqube_results = []
severity_mapping = {
4: 'BLOCKER',
3: 'CRITICAL',
2: 'MAJOR'
}
for result in uipath_results:
issue = {}
issue['engineId'] = 'uipath-workflow-analyzer'
issue['ruleId'] = result['ErrorCode']
issue['type'] = 'CODE_SMELL' # default, can be adjusted based on your needs
issue['severity'] = severity_mapping.get(result['ErrorSeverity'], 'MINOR')
issue['primaryLocation'] = {
'message': result['Description'],
'filePath': result['FilePath'] if result['FilePath'] else 'unknown_path'
}
# Add recommendation as additional info if available
if 'Recommendation' in result and result['Recommendation'] is not None:
issue['primaryLocation']['message'] += " Recommendation: " + result['Recommendation']
sonarqube_results.append(issue)
# Wrap the array in a JSON object
output_data = {
"issues": sonarqube_results
}
# Save the results in Generic Issue Import Format
with open('sonarqube_input.json', 'w', encoding='utf-8') as f:
json.dump(output_data, f, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment