build: Resolve commit message on reusable workflow #665
Workflow file for this run
This file contains 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: Build | |
on: | |
workflow_dispatch: | |
inputs: | |
skip-duplicates: | |
description: "Whether to fail or skip duplicates when uploading to a package repository" | |
required: false | |
default: "true" | |
push: | |
branches: [beta, master, release-*] | |
pull_request: | |
branches: [master, release-*] | |
jobs: | |
build: | |
env: | |
GIT_REF: ${{ github.ref }} | |
Solution: src/GeneXus.DeploymentTargets.sln | |
Configuration: Release | |
runs-on: windows-latest | |
outputs: | |
NUGET_VERSION: ${{ steps.buildVariables.outputs.NUGET_PACKAGE_VERSION }} | |
SHOULD_DEPLOY: ${{ steps.buildVariables.outputs.SHOULD_DEPLOY }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Calculate environment variables | |
id: buildVariables | |
run: | | |
$IsMaster = $false | |
switch -regex ($Env:GIT_REF) { | |
'master' { | |
$IsPrerelease = $true | |
$IsMaster = $true | |
$SHOULD_DEPLOY = 'true' | |
} | |
'beta' { | |
$IsPrerelease = $true | |
$SHOULD_DEPLOY = 'true' | |
} | |
'release-*' { | |
$IsPrerelease = $false | |
$SHOULD_DEPLOY = 'true' | |
} | |
default { | |
$IsPrerelease = $false | |
$SHOULD_DEPLOY = 'false' | |
} | |
} | |
$COMMIT_NUMBER = @($(git rev-list --count origin/master..), $(git rev-list --count HEAD))[$IsPrerelease] | |
$GetFileVersionOutput = dotnet msbuild ./Directory.Build.props /t:GetFileVersionForPackage /p:COMMIT_NUMBER=$COMMIT_NUMBER /p:VersionSuffix="" /p:UseDefaultSuffix=false | |
"$GetFileVersionOutput" -match "(?<=FileVersion:)(.*)" > $null | |
$NUGET_PACKAGE_VERSION = $Matches[0].Trim() | |
if ($IsPrerelease -eq $true) { | |
$VersionTag = @("beta", "preview")[$IsMaster] | |
$Timestamp = (Get-Date -AsUTC).ToString("yyyyMMddHHmmss") | |
$NUGET_PACKAGE_VERSION = $NUGET_PACKAGE_VERSION + "-" + $VersionTag + "." + $Timestamp | |
} | |
Write-Output "[info] Package version: $NUGET_PACKAGE_VERSION" | |
echo "NUGET_PACKAGE_VERSION=$NUGET_PACKAGE_VERSION" >> $env:GITHUB_ENV | |
echo "IsPrerelease=$IsPrerelease" >> $env:GITHUB_ENV | |
echo "NUGET_PACKAGE_VERSION=$NUGET_PACKAGE_VERSION" >> $env:GITHUB_OUTPUT | |
echo "SHOULD_DEPLOY=$SHOULD_DEPLOY" >> $env:GITHUB_OUTPUT | |
- name: Generate package | |
env: | |
CommitNumber: ${{env.COMMIT_NUMBER}} | |
run: dotnet pack $Env:Solution --configuration $Env:Configuration /p:Version=$Env:NUGET_PACKAGE_VERSION | |
- name: Configure Azure Artifacts feed | |
if: github.repository_owner == 'genexuslabs' && steps.buildVariables.outputs.SHOULD_DEPLOY == 'true' | |
env: | |
AzureArtifactsPrereleaseFeedURL: https://pkgs.dev.azure.com/genexuslabs/da74dc90-a4aa-4020-afcf-1afbf89d5bbd/_packaging/deployment-targets-prereleases/nuget/v3/index.json | |
AzureArtifactsReleaseFeedURL: https://pkgs.dev.azure.com/genexuslabs/da74dc90-a4aa-4020-afcf-1afbf89d5bbd/_packaging/deployment-targets-releases/nuget/v3/index.json | |
run: | | |
$IsPrerelease = [System.Convert]::ToBoolean($Env:IsPrerelease) | |
$AZURE_ARTIFACTS_URL = @("$Env:AzureArtifactsReleaseFeedURL", "$Env:AzureArtifactsPrereleaseFeedURL")[$IsPrerelease] | |
dotnet nuget add source $AZURE_ARTIFACTS_URL --name AzureArtifacts --username genexuslabs --password ${{ secrets.AZURE_ARTIFACTS_TOKEN }} | |
echo "AZURE_ARTIFACTS_URL=$AZURE_ARTIFACTS_URL" >> $env:GITHUB_ENV | |
- name: Push packages | |
if: github.repository_owner == 'genexuslabs' && steps.buildVariables.outputs.SHOULD_DEPLOY == 'true' | |
env: | |
GPRFeedURL: https://nuget.pkg.github.com/genexuslabs/index.json | |
NuGetFeedURL: https://api.nuget.org/v3/index.json | |
run: | | |
$IsPrerelease = [System.Convert]::ToBoolean($Env:IsPrerelease) | |
$totalPackages = 0 | |
$pushedToAzure = 0 | |
$pushedToGitHub = 0 | |
$pushedToNuget = 0 | |
$IsInternalOnlyPackage = $true | |
Get-ChildItem ".\*.nupkg" -Recurse | ForEach-Object { | |
$PushToGitHubArgs = @("nuget", "push", $_.FullName, "--source", $Env:GPRFeedURL, "--api-key", "${{ secrets.SECURE_TOKEN }}") | |
$PushToNugetArgs = @("nuget", "push", $_.FullName, "--source", $Env:NuGetFeedURL, "--api-key", "${{ secrets.NUGET_ORG_TOKEN }}") | |
$PushToAzureArgs = @("nuget", "push", $_.FullName, "--source", $Env:AZURE_ARTIFACTS_URL, "--api-key", "DUMMY-KEY") | |
if ([string]::IsNullOrEmpty("${{ github.event.inputs.skip-duplicates }}") ) { | |
$skipDuplicates = $true | |
} else { | |
$skipDuplicates = [System.Convert]::ToBoolean("${{ github.event.inputs.skip-duplicates }}") | |
} | |
if ($skipDuplicates) { | |
$PushToNugetArgs += "--skip-duplicate" | |
$PushToGitHubArgs += "--skip-duplicate" | |
$PushToAzureArgs += "--skip-duplicate" | |
} | |
dotnet $PushToAzureArgs | |
$pushedToAzure += 1 | |
if (!$IsPrerelease) { | |
dotnet $PushToGitHubArgs | |
$pushedToGitHub += 1 | |
if (!$IsInternalOnlyPackage) { | |
dotnet $PushToNugetArgs | |
$pushedToNuget += 1 | |
} | |
} | |
$totalPackages += 1 | |
} | |
Write-Output "Number of packages found: $totalPackages" | |
Write-Output "Number of packages pushed to Azure Artifacts: $pushedToAzure" | |
Write-Output "Number of packages pushed to GitHub: $pushedToGitHub" | |
Write-Output "Number of packages pushed to Nuget.org: $pushedToNuget" | |
update-genexus-dependency: | |
concurrency: | |
group: build-${{ github.ref }} | |
cancel-in-progress: true | |
uses: genexuslabs/build-genexus-reusable-workflow/.github/workflows/update-genexus-dep-version.yml@main | |
needs: build | |
if: github.repository_owner == 'genexuslabs' && needs.build.outputs.SHOULD_DEPLOY == 'true' | |
with: | |
VERSION: ${{ needs.build.outputs.NUGET_VERSION }} | |
PACKAGE_NAMES: "GeneXus.DeploymentTargets" | |
secrets: inherit |