Update NuGets #1296
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update NuGets | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 23 * * *' | |
| defaults: | |
| run: | |
| shell: pwsh | |
| jobs: | |
| Update: | |
| runs-on: [ windows-latest ] | |
| steps: | |
| - uses: actions/checkout@v4.1.1 | |
| - name: CheckUser | |
| run: | | |
| if ("$ENV:GITHUB_REPOSITORY" -eq "fscpscollaborative/fscps" -and "$ENV:GITHUB_ACTOR" -ne "onikolaiev") { | |
| Write-Host "::Error::You cannot run deploy and collect in the fscpscollaborative/fscps repo" | |
| exit 1 | |
| } | |
| - name: Update Nugets | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| $baseFolder = $ENV:GITHUB_WORKSPACE | |
| Import-Module PowerShellGet | |
| $helperPath = Join-Path -Path $baseFolder -ChildPath "Actions\FSC-PS-Helper.ps1" -Resolve | |
| . ($helperPath) | |
| installModules AZ.Storage,d365fo.tools,fscps.lcs | |
| $lcsUserName = "${{ secrets.LCS_USERNAME }}" | |
| $lcsUserPassword = "${{ secrets.LCS_USER_PASSWORD }}" | |
| $lcsProjectId = "${{ secrets.LCS_PROJECT_ID }}" | |
| $lcsClientId = "${{ secrets.LCS_CLIENT_ID }}" | |
| $StorageSAStoken = "${{ secrets.NUGET_STORAGE_SAS_TOKEN }}" | |
| $regex = [regex] "\b(([0-9]*[0-9])\.){3}(?:[0-9]*[0-9]?)\b" | |
| [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
| $lcstoken = GetToken -lcsClientId $lcsClientId -lcsUserName $lcsUserName -lcsUserPasswd $lcsUserPassword | |
| Set-Location $baseFolder | |
| $branch = main #[System.IO.Path]::GetRandomFileName() | |
| $githubOwner = "$ENV:GITHUB_ACTOR" | |
| $minimumfscversion = "10.0.39" | |
| $fscVersionRegex = [regex] "(([0-9]*[0-9])\.){2}(?:[0-9]*[0-9]?)" | |
| invoke-git config --global user.email "$githubOwner@users.noreply.github.com" | |
| invoke-git config --global user.name "$githubOwner" | |
| invoke-git config --global hub.protocol https | |
| invoke-git config --global core.autocrlf true | |
| #invoke-git checkout -b $branch main | |
| invoke-git checkout $branch | |
| $settingsFile = @" | |
| { | |
| "lcsUsername": "$lcsUserName", | |
| "lcsPassword": "$lcsUserPassword" | |
| } | |
| "@ | |
| Set-FSCPSLCSSettings -SettingsJsonString $settingsFile | |
| $assetsList = Get-FSCPSLCSSharedAssetList -AssetFileType SoftwareDeployablePackage | |
| $assetsList | Sort-Object{$_.LocalModifiedDate} | ForEach-Object { | |
| $fileName = $_.Name | |
| $fscVersion = Get-FSCVersionFromPackageName $_.Name | |
| if($fscVersion -gt $minimumfscversion -and $fscVersion.Length -gt 6 -and -not $fileName.StartsWith("AX2012")) | |
| { | |
| OutputInfo "#################### $fscVersion #####################" | |
| $token = GetToken -lcsClientId $lcsClientId -lcsUserName $lcsUserName -lcsUserPasswd $lcsUserPassword | |
| #ProcessingSDP -FSCVersion $fscVersion -AssetId $_.Id -AssetName $fileName -ProjectId $lcsProjectId -LCSToken $lcstoken -StorageSAStoken $StorageSAStoken | |
| ProcessingSDP -SelectedAsset $_ -AssetCollection $assetsList -ProjectId $lcsProjectId -LCSToken $token -StorageSAStoken $StorageSAStoken | |
| } | |
| } | |
| $assetsList = Get-FSCPSLCSSharedAssetList -AssetFileType NuGetPackage | |
| $assetsList | Sort-Object{$_.LocalModifiedDate} | ForEach-Object { | |
| $fileName = $_.FileName | |
| $fscVersion = Get-FSCVersionFromPackageName $_.Name | |
| if($fscVersion -gt $minimumfscversion -and $fscVersion.Length -gt 6) | |
| { | |
| OutputInfo "#################### $fscVersion #####################" | |
| $token = GetToken -lcsClientId $lcsClientId -lcsUserName $lcsUserName -lcsUserPasswd $lcsUserPassword | |
| try | |
| { | |
| ProcessingNuGet -FSCVersion $fscVersion -AssetId $_.Id -AssetName $fileName -ProjectId $lcsProjectId -LCSToken $lcstoken -StorageSAStoken $StorageSAStoken -LCSAssetName $_.Name | |
| } | |
| catch | |
| { | |
| $_.Exception.Message | |
| } | |
| } | |
| } | |
| Set-Location $baseFolder | |
| invoke-git add . | |
| $status = invoke-git status --porcelain=v2 -returnValue | |
| OutputInfo "Git changes: $($status)" | |
| if ($status) { | |
| invoke-git commit --allow-empty -m 'Update versions.' | |
| invoke-git push -u origin $branch | |
| #Write-Output "Create PR to the main" | |
| #$releaseNotes = "No release notes available!" | |
| #invoke-gh pr create --fill --head $branch --repo "https://github.com/fscpscollaborative/fscps.git" --body "$releaseNotes" --base main | |
| } |