From 55a76e1d485a4841f8dbbbed21ca17f447d99bcb Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Fri, 24 Jan 2025 09:15:46 -0800 Subject: [PATCH 1/2] Fix pipeline generation for private repos --- .../templates/jobs/prepare-pipelines.yml | 18 +++++++++++------- .../templates/steps/sparse-checkout.yml | 15 +++++++++++++++ .../templates/steps/validate-all-packages.yml | 2 +- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/eng/common/pipelines/templates/jobs/prepare-pipelines.yml b/eng/common/pipelines/templates/jobs/prepare-pipelines.yml index 0d3f7397541a..8d59bcdb6ace 100644 --- a/eng/common/pipelines/templates/jobs/prepare-pipelines.yml +++ b/eng/common/pipelines/templates/jobs/prepare-pipelines.yml @@ -50,17 +50,21 @@ jobs: - '!sdk/**/recordings/*' - '!sdk/**/SessionRecords/*' - '!sdk/**/session-records/*' + ${{ if endsWith(parameters.Repository, '-pr') }}: + TokenToUseForAuth: $(azuresdk-github-pat) + - template: /eng/common/pipelines/templates/steps/install-pipeline-generation.yml - template: /eng/common/pipelines/templates/steps/set-default-branch.yml - pwsh: | Write-Host "Setting up pipeline variables" - if ("${{ parameters.Repository }}" -match "Azure/azure-sdk-for-(?[^-]*)(?-pr)?") { - $prefix = $matches['prefix'] - $devOpsPath = "\$prefix" + if ("${{ parameters.Repository }}" -match "Azure/azure-sdk-for-(?[^-]*)(?-pr)?") { + $lang = $matches['lang'] + $devOpsPath = "\$lang" + $prefix = $lang if ($matches['pr']) { $devOpsPath = "${devOpsPath}\pr" - $prefix = "${prefix}-pr" + $prefix += "-pr" Write-Host "##vso[task.setvariable variable=ProjectForPRValidation]internal" } Write-Host "Prefix = $prefix" @@ -79,8 +83,8 @@ jobs: $testServiceConnections = '"Azure" "azure-sdk-tests" "azure-sdk-tests-preview" "azure-sdk-tests-public" "Azure SDK Test Resources - LiveTestSecrets"' $internalServiceConnections = '"Azure" "Azure SDK Artifacts" "Azure SDK Engineering System" "opensource-api-connection" "AzureSDKEngKeyVault Secrets"' - # Map the language prefix to the appropriate variable groups - switch ($prefix) + # Map the language to the appropriate variable groups + switch ($lang) { "java" { $internalVariableGroups = '$(AzureSDK_Maven_Release_Pipeline_Secrets) $(Release_Secrets_for_GitHub) $(APIReview_AutoCreate_Configurations)' @@ -115,7 +119,7 @@ jobs: $generateUnifiedWeekly = 'true' } default { - Write-Error "Prefix '$prefix' is not recognized." + Write-Error "Language '$lang' is not recognized." exit 1 } } diff --git a/eng/common/pipelines/templates/steps/sparse-checkout.yml b/eng/common/pipelines/templates/steps/sparse-checkout.yml index 49ba3000df32..2fafa0465afe 100644 --- a/eng/common/pipelines/templates/steps/sparse-checkout.yml +++ b/eng/common/pipelines/templates/steps/sparse-checkout.yml @@ -11,11 +11,20 @@ parameters: - name: SkipCheckoutNone type: boolean default: false + - name: TokenToUseForAuth + type: string + default: '' steps: - ${{ if not(parameters.SkipCheckoutNone) }}: - checkout: none + - ${{ if ne(parameters.TokenToUseForAuth, '') }}: + - pwsh: | + $base64Token = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("nobody:${{ parameters.TokenToUseForAuth }}")) + git config set --global "http.extraheader" "AUTHORIZATION: basic $base64Token" + displayName: Setup git config auth header + - task: PowerShell@2 ${{ if eq(length(parameters.Repositories), 1) }}: displayName: 'Sparse checkout ${{ parameters.Repositories[0].Name }}' @@ -126,3 +135,9 @@ steps: } pwsh: true workingDirectory: $(System.DefaultWorkingDirectory) + + - ${{ if ne(parameters.TokenToUseForAuth, '') }}: + - pwsh: | + git config unset --global "http.extraheader" + displayName: Removing git config auth header + condition: always() diff --git a/eng/common/pipelines/templates/steps/validate-all-packages.yml b/eng/common/pipelines/templates/steps/validate-all-packages.yml index 679d8830a459..03a5f84cc29a 100644 --- a/eng/common/pipelines/templates/steps/validate-all-packages.yml +++ b/eng/common/pipelines/templates/steps/validate-all-packages.yml @@ -4,7 +4,7 @@ parameters: ConfigFileDir: $(Build.ArtifactStagingDirectory)/PackageInfo steps: - - ${{ if and(ne(variables['Skip.PackageValidation'], 'true'), eq(variables['System.TeamProject'], 'internal')) }}: + - ${{ if and(ne(variables['Skip.PackageValidation'], 'true'), and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['System.TeamProject'], 'internal'))) }}: - pwsh: | echo "##vso[task.setvariable variable=SetAsReleaseBuild]false" displayName: "Set as release build" From 7aa720848f8a1b8e28ef53e8b2e6b435c4ae39bb Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Mon, 3 Feb 2025 14:51:46 -0800 Subject: [PATCH 2/2] Update eng/common/pipelines/templates/steps/sparse-checkout.yml --- eng/common/pipelines/templates/steps/sparse-checkout.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/common/pipelines/templates/steps/sparse-checkout.yml b/eng/common/pipelines/templates/steps/sparse-checkout.yml index 2fafa0465afe..82c41ae9d3c5 100644 --- a/eng/common/pipelines/templates/steps/sparse-checkout.yml +++ b/eng/common/pipelines/templates/steps/sparse-checkout.yml @@ -22,6 +22,7 @@ steps: - ${{ if ne(parameters.TokenToUseForAuth, '') }}: - pwsh: | $base64Token = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("nobody:${{ parameters.TokenToUseForAuth }}")) + Write-Host "##vso[task.setvariable variable=_base64AuthToken;issecret=true;]$base64Token" git config set --global "http.extraheader" "AUTHORIZATION: basic $base64Token" displayName: Setup git config auth header