Skip to content

Added extra step in workflow to set DIS_PATH environment variable #23

Added extra step in workflow to set DIS_PATH environment variable

Added extra step in workflow to set DIS_PATH environment variable #23

name: DataMiner CI Automation
on:
push:
branches: []
tags:
- "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
- "[0-9]+.[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+"
workflow_dispatch: null
jobs:
validate_skyline_quality_gate:
name: SDK Skyline Quality Gate
runs-on: windows-latest
env:
detected-unit-tests: none
outputs:
quality: ${{ steps.quality-step.outputs.results }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Initialize
run: |
echo "workspace" ${{ github.workspace }}
echo "ref name" ${{ github.ref_name }}
echo "run number" ${{ github.run_number }}
echo "ref type" ${{ github.ref_type }}
echo "repository" ${{ github.repository }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: zulu
- name: Find .sln file
id: findSlnFile
run: |
echo solutionFilePath=$(find . -type f -name '*.sln') >> $GITHUB_OUTPUT
shell: bash
- name: Enable Skyline GitHub NuGet Registry
if: github.repository_owner == 'SkylineCommunications'
run: dotnet nuget add source "https://nuget.pkg.github.com/SkylineCommunications/index.json" --username USERNAME --password ${{ secrets.GITHUB_TOKEN }}
- name: Enable Skyline Azure Cloud NuGet Registry
env:
AZURE_TOKEN_EXISTS: ${{ secrets.AZURE_TOKEN }}
if: env.AZURE_TOKEN_EXISTS != null && github.repository_owner == 'SkylineCommunications'
run: |
$SOURCE_NAME="CloudNuGets"
$SOURCE_URL="https://pkgs.dev.azure.com/skyline-cloud/Cloud_NuGets/_packaging/CloudNuGet/nuget/v3/index.json"
# Check if the source exists. If it does, update it.
if (dotnet nuget list source | Select-String -Pattern $SOURCE_NAME) {
Write-Host "Updating existing source $SOURCE_NAME."
dotnet nuget update source $SOURCE_NAME --source $SOURCE_URL --username az --password ${{ secrets.AZURE_TOKEN }} --store-password-in-clear-text
} else {
Write-Host "Adding new source $SOURCE_NAME."
dotnet nuget add source $SOURCE_URL --name $SOURCE_NAME --username az --password ${{ secrets.AZURE_TOKEN }} --store-password-in-clear-text
}
- name: Enable Skyline Azure Private NuGet Registry
env:
AZURE_TOKEN_EXISTS: ${{ secrets.AZURE_TOKEN }}
if: env.AZURE_TOKEN_EXISTS != null && github.repository_owner == 'SkylineCommunications'
run: |
$SOURCE_NAME="PrivateAzureNuGets"
$SOURCE_URL="https://pkgs.dev.azure.com/skyline-cloud/_packaging/skyline-private-nugets/nuget/v3/index.json"
# Check if the source exists. If it does, update it.
if (dotnet nuget list source | Select-String -Pattern $SOURCE_NAME) {
Write-Host "Updating existing source $SOURCE_NAME."
dotnet nuget update source $SOURCE_NAME --source $SOURCE_URL --username az --password ${{ secrets.AZURE_TOKEN }} --store-password-in-clear-text
} else {
Write-Host "Adding new source $SOURCE_NAME."
dotnet nuget add source $SOURCE_URL --name $SOURCE_NAME --username az --password ${{ secrets.AZURE_TOKEN }} --store-password-in-clear-text
}
- name: Set DIS_PATH environment variable
run: echo "DIS_PATH=${{ github.workspace }}\\Dlls\\DIS" >> $GITHUB_ENV
shell: bash
- name: Building
run: dotnet build "${{ steps.findSlnFile.outputs.solutionFilePath }}" -p:DefineConstants="DCFv1%3BDBInfo%3BALARM_SQUASHING" --configuration Release -nodeReuse:false
- name: Unit Tests
id: unit-tests
run: dotnet test "${{ steps.findSlnFile.outputs.solutionFilePath }}" --filter TestCategory!=IntegrationTest --logger "trx;logfilename=unitTestResults.trx" --collect "XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura,opencover
continue-on-error: true
- name: Install SonarCloud scanner
run: |
dotnet tool install dotnet-sonarscanner --global
- name: Prepare SonarCloud Variables
id: prepSonarCloudVar
run: |
import os
env_file = os.getenv('GITHUB_ENV')
with open(env_file, "a") as myfile:
myfile.write("lowerCaseOwner=" + str.lower("${{ github.repository_owner }}"))
shell: python
- name: Get SonarCloud Status
id: get-sonarcloud-status
run: |
echo "sonarCloudProjectStatus=$(curl https://${{ secrets.SONAR_TOKEN }}@sonarcloud.io/api/qualitygates/project_status?projectKey=SkylineCommunications_SLC-DISMACRO-Script-Context)" >> $env:GITHUB_OUTPUT
continue-on-error: true
- name: Log SonarCloud Status
id: log-sonarcloud-status
run: |
echo "${{ steps.get-sonarcloud-status.outputs.sonarCloudProjectStatus }}"
- name: Trigger Initial Analysis
if: fromJson(steps.get-sonarcloud-status.outputs.sonarCloudProjectStatus).projectStatus.status == 'NONE'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet sonarscanner begin /k:"SkylineCommunications_SLC-DISMACRO-Script-Context" /o:"${{ env.lowerCaseOwner }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" /d:sonar.cs.vstest.reportsPaths="**/TestResults/**.trx"
dotnet build "${{ steps.findSlnFile.outputs.solutionFilePath }}" -p:DefineConstants="DCFv1%3BDBInfo%3BALARM_SQUASHING" --configuration Release -nodeReuse:false
dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
continue-on-error: true
- name: Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet sonarscanner begin /k:"SkylineCommunications_SLC-DISMACRO-Script-Context" /o:"${{ env.lowerCaseOwner }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" /d:sonar.cs.vstest.reportsPaths="**/TestResults/**.trx"
dotnet build "${{ steps.findSlnFile.outputs.solutionFilePath }}" -p:DefineConstants="DCFv1%3BDBInfo%3BALARM_SQUASHING" --configuration Release -nodeReuse:false
dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
continue-on-error: true
- name: SonarCloud Quality Gate check
id: sonarcloud-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
with:
scanMetadataReportFile: .sonarqube/out/.sonar/report-task.txt
continue-on-error: true
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Quality Gate
id: quality-step
run: |
if "${{ steps.unit-tests.outcome }}" == "failure" or "${{ steps.sonarcloud-quality-gate-check.outcome }}" == "failure" or "${{ steps.sonarcloud-quality-gate-check.outputs.quality-gate-status }}" == "FAILED":
print("Quality gate failed due to:")
if "${{ steps.unit-tests.outcome }}" == "failure":
print("- Test failures")
if "${{ steps.sonarcloud-quality-gate-check.outcome }}" == "failure":
print("- Could not retrieve SonarCloud quality gate status")
if "${{ steps.sonarcloud-quality-gate-check.outputs.quality-gate-status }}" == "FAILED":
print("- Code analysis quality gate failed")
if "${{ steps.unit-tests.outcome }}" == "failure" or "${{ steps.sonarcloud-quality-gate-check.outcome }}" == "failure" or "${{ steps.sonarcloud-quality-gate-check.outputs.quality-gate-status }}" == "FAILED":
exit(1)
shell: python
artifact_creation_registration:
name: Artifact Registration and Upload
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
needs: validate_skyline_quality_gate
env:
result-artifact-id: none
outputs:
artifact-id: ${{ env.result-artifact-id }}
steps:
- uses: actions/checkout@v4
- name: readDir
run: ls
- name: Initialize
run: |
echo "workspace" ${{ github.workspace }}
echo "ref name" ${{ github.ref_name }}
echo "run number" ${{ github.run_number }}
echo "ref type" ${{ github.ref_type }}
echo "repository" ${{ github.repository }}
- name: Find .sln file
id: findSlnFile
run: |
echo solutionFilePath=$(find . -type f -name '*.sln') >> $GITHUB_OUTPUT
shell: bash
- name: Find or create NuGet.config file
if: github.repository_owner == 'SkylineCommunications'
id: findOrCreateNuGetFile
run: |
file=$(find . -type f -iname 'nuget.config' | head -n 1)
if [[ -n "$file" ]]; then
echo "NuGet config file exists: $file"
echo NuGetFileName=$(basename $file) >> $GITHUB_OUTPUT
else
echo "NuGet config does not exist. Creating..."
dotnet new nugetconfig --output ${{ github.workspace }}
echo NuGetFileName=nuget.config >> $GITHUB_OUTPUT
fi
shell: bash
- name: Enable Skyline GitHub NuGet Registry
if: github.repository_owner == 'SkylineCommunications'
run: dotnet nuget add source "https://nuget.pkg.github.com/SkylineCommunications/index.json" --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --configfile ${{ github.workspace }}/${{ steps.findOrCreateNuGetFile.outputs.NuGetFileName }}
- name: Enable Skyline Azure Cloud NuGet Registry
env:
AZURE_TOKEN_EXISTS: ${{ secrets.AZURE_TOKEN }}
if: env.AZURE_TOKEN_EXISTS != null && github.repository_owner == 'SkylineCommunications'
run: >
$SOURCE_NAME="CloudNuGets"
$SOURCE_URL="https://pkgs.dev.azure.com/skyline-cloud/Cloud_NuGets/_packaging/CloudNuGet/nuget/v3/index.json"
# Check if the source exists. If it does, update it.
if (dotnet nuget list source | Select-String -Pattern $SOURCE_NAME) {
Write-Host "Updating existing source $SOURCE_NAME."
dotnet nuget update source $SOURCE_NAME --source $SOURCE_URL --username az --password ${{ secrets.AZURE_TOKEN }} --store-password-in-clear-text
} else {
Write-Host "Adding new source $SOURCE_NAME."
dotnet nuget add source $SOURCE_URL --name $SOURCE_NAME --username az --password ${{ secrets.AZURE_TOKEN }} --store-password-in-clear-text
}
shell: pwsh
- name: Enable Skyline Azure Private NuGet Registry
env:
AZURE_TOKEN_EXISTS: ${{ secrets.AZURE_TOKEN }}
if: env.AZURE_TOKEN_EXISTS != null && github.repository_owner ==
'SkylineCommunications'
run: >
$SOURCE_NAME="PrivateAzureNuGets"
$SOURCE_URL="https://pkgs.dev.azure.com/skyline-cloud/_packaging/skyline-private-nugets/nuget/v3/index.json"
# Check if the source exists. If it does, update it.
if (dotnet nuget list source | Select-String -Pattern $SOURCE_NAME) {
Write-Host "Updating existing source $SOURCE_NAME."
dotnet nuget update source $SOURCE_NAME --source $SOURCE_URL --username az --password ${{ secrets.AZURE_TOKEN }} --store-password-in-clear-text
} else {
Write-Host "Adding new source $SOURCE_NAME."
dotnet nuget add source $SOURCE_URL --name $SOURCE_NAME --username az --password ${{ secrets.AZURE_TOKEN }} --store-password-in-clear-text
}
shell: pwsh
- name: NuGet restore solution
run: dotnet restore "${{ steps.findSlnFile.outputs.solutionFilePath }}"
- name: Install .NET Tools
run: |
dotnet tool install -g Skyline.DataMiner.CICD.Tools.Packager
dotnet tool install -g Skyline.DataMiner.CICD.Tools.CatalogUpload
- name: Create package name
id: packageName
run: |
tempName="${{ github.repository }} ${{ github.ref_name }}"
echo name=${tempName//[\"\/\\<>|:*?]/_} >> $GITHUB_OUTPUT
shell: bash
- name: Create dmapp package
run: dataminer-package-create dmapp "${{ github.workspace }}" --type automation --version ${{ github.ref_name }} --output "${{ github.workspace }}" --name "${{ steps.packageName.outputs.name }}"
- name: Upload to Catalog
id: uploadToCatalog
run: echo "id=$(dataminer-catalog-upload with-registration --path-to-artifact "${{ github.workspace }}/${{ steps.packageName.outputs.name }}.dmapp" --uri-sourcecode "${{ github.server_url }}/${{ github.repository }}" --artifact-version ${{ github.ref_name }} --dm-catalog-token ${{ secrets.api-key }})" >> $GITHUB_OUTPUT
- name: (Release) Set artifact Id
run: echo "result-artifact-id=${{ steps.uploadToCatalog.outputs.id }}" >> $GITHUB_ENV