diff --git a/.github/Composite-Actions/Build-Status/action.yml b/.github/Composite-Actions/Build-Status/action.yml new file mode 100644 index 0000000..1d3fb4b --- /dev/null +++ b/.github/Composite-Actions/Build-Status/action.yml @@ -0,0 +1,24 @@ +name: 'Build Status' +description: 'Tags repostitory and shows the build status' +author: 'Mike Burgess' +inputs: + VERSION: + description: 'Version for tagging' + required: true + +runs: + using: 'composite' + + steps: + - name: Checkout files on agent + uses: actions/checkout@v3 + + - name: Tagging repostitory + run: | + git tag ${{ inputs.VERSION }} + git push origin ${{ inputs.VERSION }} + shell: bash + + - name: Show build success + run: echo "The build ${{ inputs.VERSION }} successfully completed" + shell: bash \ No newline at end of file diff --git a/.github/Composite-Actions/Create-Versions-Json/action.yml b/.github/Composite-Actions/Create-Versions-Json/action.yml new file mode 100644 index 0000000..359dfb9 --- /dev/null +++ b/.github/Composite-Actions/Create-Versions-Json/action.yml @@ -0,0 +1,19 @@ +name: 'Create Versions Json' +description: 'Creates a versions.json file' +author: 'Mike Burgess' +inputs: + VERSION: + description: 'Version generated from Set-Branch-Variables' + required: true +runs: + using: 'composite' + steps: + - name: Checkout files on agent + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: test then run set-nugetfeeds.ps1 + run: | + ${{ github.action_path }}/../../../Powershell/Scripts\Set-Versions-Json.ps1 -version ${{ inputs.VERSION }} + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" \ No newline at end of file diff --git a/.github/Composite-Actions/Fix-Nuget-Feeds/action.yml b/.github/Composite-Actions/Fix-Nuget-Feeds/action.yml index 3feca0e..408521f 100644 --- a/.github/Composite-Actions/Fix-Nuget-Feeds/action.yml +++ b/.github/Composite-Actions/Fix-Nuget-Feeds/action.yml @@ -14,6 +14,9 @@ inputs: PROGET_API_KEY: description: 'API key for NuGet.' required: true + SOLUTION_FILE: + description: 'Optional Solution File if you want to run a restore' + required: false runs: using: 'composite' steps: @@ -24,7 +27,15 @@ runs: nuget-api-key: ${{ inputs.PROGET_API_KEY }} - name: test then run set-nugetfeeds.ps1 + if: ${{ inputs.SOLUTION_FILE == null || inputs.SOLUTION_FILE == '' }} run: | ${{ github.action_path }}/../../../Powershell/Scripts\set-nugetfeeds.ps1 -nugetPublish "${{ inputs.NUGET_PUBLISH }}" -nugetSource "${{ inputs.NUGET_SOURCE }}" -nugetLibrary "${{ inputs.NUGET_LIBRARY }}" -nugetApiKey "${{ inputs.PROGET_API_KEY }}" -nugetConfigFullPath "${{ github.workspace }}\nuget.config" + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" + + - name: test then run set-nugetfeeds.ps1 + if: ${{ inputs.SOLUTION_FILE && inputs.SOLUTION_FILE != ''}} + run: | + ${{ github.action_path }}/../../../Powershell/Scripts\set-nugetfeeds.ps1 -nugetPublish "${{ inputs.NUGET_PUBLISH }}" -nugetSource "${{ inputs.NUGET_SOURCE }}" -nugetLibrary "${{ inputs.NUGET_LIBRARY }}" -nugetApiKey "${{ inputs.PROGET_API_KEY }}" -nugetConfigFullPath "${{ github.workspace }}\nuget.config" -solutionFile ${{ inputs.SOLUTION_FILE }} shell: | pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" \ No newline at end of file diff --git a/.github/Composite-Actions/Set-Branch-Variables/action.yml b/.github/Composite-Actions/Set-Branch-Variables/action.yml index fb1e641..3b054cd 100644 --- a/.github/Composite-Actions/Set-Branch-Variables/action.yml +++ b/.github/Composite-Actions/Set-Branch-Variables/action.yml @@ -58,19 +58,33 @@ runs: id: set-dev-variables if: contains(inputs.BRANCH_NAME,'feature') run: | - echo "BUILD_TYPE=dev" >> $GITHUB_ENV - echo "BUILD_CONFIG=Debug" >> $GITHUB_ENV - echo "NUGET_PUBLISH=https://proget.cogstate.com/nuget/cogstate-releases-dev/" >> $GITHUB_ENV - echo "NUGET_SOURCE=https://proget.cogstate.com/nuget/nuget-dev/" >> $GITHUB_ENV - echo "NUGET_LIBRARY=https://proget.cogstate.com/nuget/cogstate-library-nuget-dev/" >> $GITHUB_ENV - shell: bash + Write-Output "BUILD_TYPE=dev" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "BUILD_CONFIG=Debug" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "NUGET_PUBLISH=https://proget.cogstate.com/nuget/cogstate-releases-dev/" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "NUGET_SOURCE=https://proget.cogstate.com/nuget/nuget-dev/" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "NUGET_LIBRARY=https://proget.cogstate.com/nuget/cogstate-library-nuget-dev/" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" - name: Set dev version id: set-dev-version if: contains(inputs.BRANCH_NAME,'feature') run: | - echo "preversion=${{ steps.branch-regex.outputs.group1 }}-${{ env.BUILD_TYPE }}.${{ steps.branch-regex.outputs.group2 }}.${{ github.run_number }}${{ github.run_attempt }}" >> $GITHUB_ENV - shell: bash + $BranchRegexGroup1 = $("${{ steps.branch-regex.outputs.group1 }}").tolower() + $BuildType = $("${{ env.BUILD_TYPE }}").tolower() + $BranchRegexGroup2 = $("${{ steps.branch-regex.outputs.group2 }}").tolower() + $GitHubRunNumber = $("${{ github.run_number }}").tolower() + $GitHubRunAttempt= $("${{ github.run_attempt }}").tolower() + + Write-Output "Branch Regex Group 1: $BranchRegexGroup1" + Write-Output "Build Type: $BuildType" + Write-Output "Branch Regex Group 2: $BranchRegexGroup2" + Write-Output "GitHubRunNumber: $GitHubRunNumber" + Write-Output "GitHubRunAttempt: $GitHubRunAttempt" + + Write-Output "preversion=$BranchRegexGroup1-$BuildType.$BranchRegexGroup2.$GithubRunNumber$GitHubRunAttempt" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" #Set the RC Variables if the branch contains release @@ -78,19 +92,31 @@ runs: id: set-rc-variables if: contains(inputs.BRANCH_NAME,'release') run: | - echo "BUILD_TYPE=rc" >> $GITHUB_ENV - echo "BUILD_CONFIG=Release" >> $GITHUB_ENV - echo "NUGET_PUBLISH=https://proget.cogstate.com/nuget/cogstate-releases-candidate/" >> $GITHUB_ENV - echo "NUGET_SOURCE=https://proget.cogstate.com/nuget/nuget-dev/" >> $GITHUB_ENV - echo "NUGET_LIBRARY=https://proget.cogstate.com/nuget/cogstate-library-nuget/" >> $GITHUB_ENV - shell: bash + Write-Output "BUILD_TYPE=rc" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "BUILD_CONFIG=Release" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "NUGET_PUBLISH=https://proget.cogstate.com/nuget/cogstate-releases-candidate/" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "NUGET_SOURCE=https://proget.cogstate.com/nuget/nuget-dev/" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "NUGET_LIBRARY=https://proget.cogstate.com/nuget/cogstate-library-nuget/" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" - name: Set rc version id: set-rc-version if: contains(inputs.BRANCH_NAME,'release') run: | - echo "preversion=${{ steps.branch-regex.outputs.group1 }}-${{ env.BUILD_TYPE }}.${{ github.run_number }}${{ github.run_attempt }}" >> $GITHUB_ENV - shell: bash + $BranchRegexGroup1 = $("${{ steps.branch-regex.outputs.group1 }}").tolower() + $BuildType = $("${{ env.BUILD_TYPE }}").tolower() + $GitHubRunNumber = $("${{ github.run_number }}").tolower() + $GitHubRunAttempt= $("${{ github.run_attempt }}").tolower() + + Write-Output "Branch Regex Group 1: $BranchRegexGroup1" + Write-Output "Build Type: $BuildType" + Write-Output "GitHubRunNumber: $GitHubRunNumber" + Write-Output "GitHubRunAttempt: $GitHubRunAttempt" + + Write-Output "preversion=$BranchRegexGroup1-$BuildType.$GitHubRunNumber$GitHubRunAttempt" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" #Override the publish variables if they are provided as inputs @@ -98,15 +124,17 @@ runs: id: override-nuget-publish if: inputs.NUGET_PUBLISH_OVERRIDE && contains(inputs.BRANCH_NAME,'release') run: | - echo "NUGET_PUBLISH=${{ inputs.NUGET_PUBLISH_OVERRIDE }}" >> $GITHUB_ENV - shell: bash + Write-Output "NUGET_PUBLISH=${{ inputs.NUGET_PUBLISH_OVERRIDE }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" - name: Override Nuget Dev Publish id: override-nuget-dev-publish if: inputs.NUGET_PUBLISH_DEV_OVERRIDE && contains(inputs.BRANCH_NAME,'feature') run: | - echo "NUGET_PUBLISH=${{ inputs.NUGET_PUBLISH_DEV_OVERRIDE }}" >> $GITHUB_ENV - shell: bash + Write-Output "NUGET_PUBLISH=${{ inputs.NUGET_PUBLISH_DEV_OVERRIDE }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" #Override the Nuget Library variables if they are provided as inputs @@ -114,15 +142,17 @@ runs: id: override-nuget-library if: inputs.NUGET_LIBRARY_OVERRIDE && contains(inputs.BRANCH_NAME,'release') run: | - echo "NUGET_LIBRARY=${{ inputs.NUGET_LIBRARY_OVERRIDE }}" >> $GITHUB_ENV - shell: bash + Write-Output "NUGET_LIBRARY=${{ inputs.NUGET_LIBRARY_OVERRIDE }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" - name: Override Nuget Dev Library id: override-nuget-dev-library if: inputs.NUGET_LIBRARY_DEV_OVERRIDE && contains(inputs.BRANCH_NAME,'feature') run: | - echo "NUGET_LIBRARY=${{ inputs.NUGET_LIBRARY_DEV_OVERRIDE }}" >> $GITHUB_ENV - shell: bash + Write-Output "NUGET_LIBRARY=${{ inputs.NUGET_LIBRARY_DEV_OVERRIDE }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" #Override the Nuget Source variables if they are provided as inputs @@ -130,23 +160,26 @@ runs: id: override-nuget-source if: inputs.NUGET_SOURCE_OVERRIDE && contains(inputs.BRANCH_NAME,'release') run: | - echo "NUGET_SOURCE=${{ inputs.NUGET_SOURCE_OVERRIDE }}" >> $GITHUB_ENV - shell: bash + Write-Output "NUGET_SOURCE=${{ inputs.NUGET_SOURCE_OVERRIDE }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" - name: Override Nuget Dev Source id: override-nuget-dev-source if: inputs.NUGET_SOURCE_DEV_OVERRIDE && contains(inputs.BRANCH_NAME,'feature') run: | - echo "NUGET_SOURCE=${{ inputs.NUGET_SOURCE_DEV_OVERRIDE }}" >> $GITHUB_ENV - shell: bash + Write-Output "NUGET_SOURCE=${{ inputs.NUGET_SOURCE_DEV_OVERRIDE }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" - name: Set output variables id: set-vars run: | - echo "version=${{ env.preversion }}" >> $GITHUB_OUTPUT - echo "build-config=${{ env.BUILD_CONFIG }}" >> $GITHUB_OUTPUT - echo "build-type=${{ env.BUILD_TYPE }}" >> $GITHUB_OUTPUT - echo "nuget-publish=${{ env.NUGET_PUBLISH }}" >> $GITHUB_OUTPUT - echo "nuget-source=${{ env.NUGET_SOURCE }}" >> $GITHUB_OUTPUT - echo "nuget-library=${{ env.NUGET_LIBRARY }}" >> $GITHUB_OUTPUT - shell: bash + Write-Output "version=${{ env.preversion }}" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + Write-Output "build-config=${{ env.BUILD_CONFIG }}" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + Write-Output "build-type=${{ env.BUILD_TYPE }}" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + Write-Output "nuget-publish=${{ env.NUGET_PUBLISH }}" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + Write-Output "nuget-source=${{ env.NUGET_SOURCE }}" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + Write-Output "nuget-library=${{ env.NUGET_LIBRARY }}" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + shell: | + pwsh -noninteractive -command "try {{ $ErrorActionPreference='Stop'; . '{0}' }} catch {{ Write-Error ""FAILED: $_""; throw; }} if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) {{ exit $LASTEXITCODE }}" diff --git a/Powershell/Modules/Version-Control.psm1 b/Powershell/Modules/Version-Control.psm1 index a36a9f0..a81909e 100644 --- a/Powershell/Modules/Version-Control.psm1 +++ b/Powershell/Modules/Version-Control.psm1 @@ -400,4 +400,57 @@ function Invoke-ConfigTransformation { Write-Host "Transformation failed." exit 1 } +} + +function New-VersionsJson { + param ( + [string]$version + ) + + + # Example of calling the function + # $versionString = "6.0.0-rc.cgm-381.7711" + # New-VersionJson -version $versionString + + # Extract major, minor, and patch parts + $major, $minor, $patchSection = $version -split '\.', 3 + + # Initialize default values + $patch = "0" + $revision = "0" + $semanticPart = "" + + # Extract semantic part and the patch and revision numbers + if ($patchSection -match '^(.*?)-(\d+)\.(\d+)$') { + $semanticPart = $matches[1] + $revision = $matches[2] + $patch = $matches[3] + } elseif ($patchSection -match '^(.*?)-(\d+)\.(\d+)$') { + $semanticPart = $matches[1] + $revision = $matches[2] + $patch = $matches[3] + } else { + $patch = $patchSection + $revision = "0" + } + + # Construct the JSON object with ordered properties + $jsonObject = [PSCustomObject]@{ + "cogstate.version.major" = $major + "cogstate.version.minor" = $minor + "cogstate.version.patch" = $patch + "cogstate.version.revision" = "0" + "cogstate.version.semantic2" = $version + "cogstate.version.semantic2.normalized" = "$major.$minor.0-$semanticPart.-$revision.$patch" + "cogstate.version.simple" = "$major.$minor.0.$patch" + } + + # Convert to JSON + $jsonString = $jsonObject | ConvertTo-Json -Depth 3 + + # Save to a file + $outputFile = "versions.json" + $jsonString | Out-File -FilePath $outputFile + + Write-Output "JSON content saved to $outputFile" } \ No newline at end of file diff --git a/Powershell/Scripts/Confirm-PreviousCommitsMerged.ps1 b/Powershell/Scripts/Confirm-PreviousCommitsMerged.ps1 index 2503796..58bf265 100644 --- a/Powershell/Scripts/Confirm-PreviousCommitsMerged.ps1 +++ b/Powershell/Scripts/Confirm-PreviousCommitsMerged.ps1 @@ -3,34 +3,7 @@ $ErrorActionPreference = "Stop" $VerbosePreference = "Continue" $DebugPreference = "Continue" -trap -{ - Write-Error "$($_.Exception)`n`nActual Stack Trace:`n$($_.ScriptStackTrace)`n`nError Output Stack Trace:" - exit 1 -} - -$currentDirectory = Get-Location -Write-Output "Current Directory is: $currentDirectory" - -$parentDirectory = Join-Path -Path $currentDirectory -ChildPath ".." -Write-Output "Parent directory is: $parentDirectory" - -$modulePath = Get-ChildItem $parentDirectory -Recurse -Filter "Version-Control.psm1" | Select-Object -First 1 -if (-not $modulePath) { - Write-Output "Module path not found in current directory, going up a directory..." - $parentDirectory = Set-Location (Join-Path -Path $parentDirectory -ChildPath "..") - Write-Output "Parent directory is now: $parentDirectory" - $modulePath = Get-ChildItem $parentDirectory -Recurse -Filter "Version-Control.psm1" | Select-Object -First 1 -} - -if ($modulePath) { - Write-Output "Module path found: $($modulePath.FullName)" - Import-Module $modulePath.FullName -} else { - Write-Output "Module path not found. Exiting..." - Write-Error "Error: Module path is empty." - exit 2 -} +Import-Module $PSScriptRoot\..\modules\Version-Control.psm1 VerifyAllGitDirectories diff --git a/Powershell/Scripts/Set-Versions-Json.ps1 b/Powershell/Scripts/Set-Versions-Json.ps1 new file mode 100644 index 0000000..74c4966 --- /dev/null +++ b/Powershell/Scripts/Set-Versions-Json.ps1 @@ -0,0 +1,15 @@ +[CmdletBinding()] +param ( + [parameter(Mandatory=$true)] + [String] + $Version +) + +$WarningPreference = "Continue" +$ErrorActionPreference = "Stop" +$VerbosePreference = "Continue" +$DebugPreference = "Continue" + +Import-Module $PSScriptRoot\..\modules\Version-Control.psm1 + +New-VersionsJson -version $Version \ No newline at end of file diff --git a/Powershell/Scripts/set-nugetfeeds.ps1 b/Powershell/Scripts/set-nugetfeeds.ps1 index 96706dc..9dd6eb8 100644 --- a/Powershell/Scripts/set-nugetfeeds.ps1 +++ b/Powershell/Scripts/set-nugetfeeds.ps1 @@ -15,6 +15,9 @@ param ( [parameter(Mandatory=$true)] [string] $nugetApiKey, + [parameter(Mandatory=$false)] + [string] + $solutionFile, [parameter()] [string] $nugetConfigFullPath = "$env:GITHUB_WORKSPACE\nuget.config" @@ -65,6 +68,9 @@ write-output "display nuget sources detailed verbosity" # Display NuGet sources with detailed verbosity nuget.exe source -Verbosity detailed -write-output "nuget restore" -# Nuget Restore -nuget.exe restore Cogstate.Platform\Cogstate.Platform.sln -force -recursive -ConfigFile $nugetConfigFullPath -Verbosity detailed \ No newline at end of file +if(!([string]::IsNullOrEmpty($solutionFile))){ + write-output "SolutionFile supplied, running the nuget restore" + write-output "Contents of the solutionfile variable: $solutionFile" + # Nuget Restore + nuget.exe restore $env:GITHUB_WORKSPACE\$soultionFile -force -recursive -ConfigFile $nugetConfigFullPath -Verbosity detailed +} \ No newline at end of file