Skip to content

Use Find-PSResource to Azure Artifacts instead of Find-Module to PSGallery #27942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wyunchi-ms
Copy link
Contributor

Description

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

@Copilot Copilot AI review requested due to automatic review settings June 12, 2025 07:54
Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the version controller script to use Find-PSResource against an Azure Artifacts feed (or fallback repository) instead of Find-Module from PSGallery.

  • Introduces conditional logic to detect DEFAULT_PS_REPOSITORY_URL and use credentials for Azure Artifacts
  • Switches Find-Module calls in both Bump-AzVersion and Update-AzPreviewChangelog to Find-PSResource
  • Adds version filtering and sorting for LTS releases

Comment on lines +183 to +186
$galleryAz = Find-PSResource -Name AzPreview -Repository $Env:DEFAULT_PS_REPOSITORY_NAME -Credential $credentialsObject -TrustRepository
}
else {
$galleryAz = Find-PSResource -Name AzPreview -Repository $GalleryName -Version *
Copy link
Preview

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the LTS branch, the command references 'AzPreview' instead of 'Az', which breaks the original LTS logic for bumping the stable Az module. It should use -Name Az to fetch the correct module.

Suggested change
$galleryAz = Find-PSResource -Name AzPreview -Repository $Env:DEFAULT_PS_REPOSITORY_NAME -Credential $credentialsObject -TrustRepository
}
else {
$galleryAz = Find-PSResource -Name AzPreview -Repository $GalleryName -Version *
$galleryAz = Find-PSResource -Name Az -Repository $Env:DEFAULT_PS_REPOSITORY_NAME -Credential $credentialsObject -TrustRepository
}
else {
$galleryAz = Find-PSResource -Name Az -Repository $GalleryName -Version *

Copilot uses AI. Check for mistakes.

Comment on lines +179 to +200
if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
Write-Host "Using DEFAULT_PS_REPOSITORY_NAME: $Env:DEFAULT_PS_REPOSITORY_NAME"
$AccessTokenSecureString = $env:SYSTEM_ACCESS_TOKEN | ConvertTo-SecureString -AsPlainText -Force
$credentialsObject = [pscredential]::new("ONEBRANCH_TOKEN", $AccessTokenSecureString)
$galleryAz = Find-PSResource -Name AzPreview -Repository $Env:DEFAULT_PS_REPOSITORY_NAME -Credential $credentialsObject -TrustRepository
}
else {
$galleryAz = Find-PSResource -Name AzPreview -Repository $GalleryName -Version *
}
$galleryAz = $galleryAz | Where-Object { ([System.Version]($_.Version)).Major%2 -eq 0 } | Sort-Object {[System.Version]$_.Version} -Descending
}
else
{
if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
Write-Host "Using DEFAULT_PS_REPOSITORY_NAME: $Env:DEFAULT_PS_REPOSITORY_NAME"
$AccessTokenSecureString = $env:SYSTEM_ACCESS_TOKEN | ConvertTo-SecureString -AsPlainText -Force
$credentialsObject = [pscredential]::new("ONEBRANCH_TOKEN", $AccessTokenSecureString)
$galleryAz = Find-PSResource -Name AzPreview -Repository $Env:DEFAULT_PS_REPOSITORY_NAME -Credential $credentialsObject -TrustRepository
}
else {
$galleryAz = Find-PSResource -Name AzPreview -Repository $GalleryName
}
Copy link
Preview

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The repository-detection and credential setup blocks are duplicated in both release branches. Consider extracting this into a helper function to reduce duplication and simplify future updates.

Suggested change
if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
Write-Host "Using DEFAULT_PS_REPOSITORY_NAME: $Env:DEFAULT_PS_REPOSITORY_NAME"
$AccessTokenSecureString = $env:SYSTEM_ACCESS_TOKEN | ConvertTo-SecureString -AsPlainText -Force
$credentialsObject = [pscredential]::new("ONEBRANCH_TOKEN", $AccessTokenSecureString)
$galleryAz = Find-PSResource -Name AzPreview -Repository $Env:DEFAULT_PS_REPOSITORY_NAME -Credential $credentialsObject -TrustRepository
}
else {
$galleryAz = Find-PSResource -Name AzPreview -Repository $GalleryName -Version *
}
$galleryAz = $galleryAz | Where-Object { ([System.Version]($_.Version)).Major%2 -eq 0 } | Sort-Object {[System.Version]$_.Version} -Descending
}
else
{
if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
Write-Host "Using DEFAULT_PS_REPOSITORY_NAME: $Env:DEFAULT_PS_REPOSITORY_NAME"
$AccessTokenSecureString = $env:SYSTEM_ACCESS_TOKEN | ConvertTo-SecureString -AsPlainText -Force
$credentialsObject = [pscredential]::new("ONEBRANCH_TOKEN", $AccessTokenSecureString)
$galleryAz = Find-PSResource -Name AzPreview -Repository $Env:DEFAULT_PS_REPOSITORY_NAME -Credential $credentialsObject -TrustRepository
}
else {
$galleryAz = Find-PSResource -Name AzPreview -Repository $GalleryName
}
$galleryAz = Get-GalleryAz -ReleaseType "LTS" -GalleryName $GalleryName
$galleryAz = $galleryAz | Where-Object { ([System.Version]($_.Version)).Major%2 -eq 0 } | Sort-Object {[System.Version]$_.Version} -Descending
}
else
$galleryAz = Get-GalleryAz -ReleaseType "STS" -GalleryName $GalleryName

Copilot uses AI. Check for mistakes.

$galleryAz = (Find-Module -Name Az -Repository $GalleryName -AllVersions | Where-Object {([System.Version]($_.Version)).Major%2 -eq 0} | Sort-Object {[System.Version]$_.Version} -Descending)[0]
}else{
$galleryAz = Find-Module -Name Az -Repository $GalleryName
if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
Copy link
Preview

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using Test-Path to check for an environment variable can be misleading—consider directly testing $env:DEFAULT_PS_REPOSITORY_URL (e.g. if (-not [string]::IsNullOrEmpty($env:DEFAULT_PS_REPOSITORY_URL))) to ensure the variable is both present and nonempty.

Suggested change
if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
if (-not [string]::IsNullOrEmpty($env:DEFAULT_PS_REPOSITORY_URL)) {

Copilot uses AI. Check for mistakes.

}else{
$galleryAz = Find-Module -Name Az -Repository $GalleryName
if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
Write-Host "Using DEFAULT_PS_REPOSITORY_NAME: $Env:DEFAULT_PS_REPOSITORY_NAME"
Copy link
Preview

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using Write-Verbose instead of Write-Host for informational messages so that consumers can control verbosity with the -Verbose switch.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant