Skip to content
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

Sync eng/common directory with azure-sdk-tools repository #9489

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions eng/common/TestResources/New-TestResources.ps1.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,23 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -OutFile
save test environment settings into a test-resources.json.env file next to test-resources.json.
The file is protected via DPAPI. The environment file would be scoped to the current repository directory.
Note: Supported only on Windows.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

Expand Down
6 changes: 6 additions & 0 deletions eng/common/TestResources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ eng\common\TestResources\New-TestResources.ps1 `
-TestApplicationSecret (ConvertFrom-SecureString $sp.Secret -AsPlainText)
```

If you are running this for a .NET project on Windows, the recommended method is to
add the `-OutFile` switch to the above command. This will save test environment settings
into a test-resources.json.env file next to test-resources.json. The file is protected via DPAPI.
The environment file would be scoped to the current repository directory and avoids the need to
set environment variables or restart your IDE to recognize them.

Along with some log messages, this will output environment variables based on
your current shell like in the following example:

Expand Down
44 changes: 24 additions & 20 deletions eng/common/pipelines/templates/steps/create-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,31 @@ steps:
workingDirectory: ${{ parameters.WorkingDirectory }}
ignoreLASTEXITCODE: true

- pwsh: |
${{ parameters.ScriptDirectory }}/git-branch-push.ps1 `
-PRBranchName "${{ parameters.PRBranchName }}" `
-CommitMsg "${{ parameters.CommitMsg }}" `
-GitUrl "https://$(azuresdk-github-pat)@github.com/${{ parameters.PROwner }}/${{ parameters.RepoName }}.git" `
-PushArgs "${{ parameters.PushArgs }}"

- task: PowerShell@2
displayName: Push changes
workingDirectory: ${{ parameters.WorkingDirectory }}
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: ${{ parameters.ScriptDirectory }}/git-branch-push.ps1
arguments: >
-PRBranchName "${{ parameters.PRBranchName }}"
-CommitMsg "${{ parameters.CommitMsg }}"
-GitUrl "https://$(azuresdk-github-pat)@github.com/${{ parameters.PROwner }}/${{ parameters.RepoName }}.git"
-PushArgs "${{ parameters.PushArgs }}"

- pwsh: |
${{ parameters.ScriptDirectory }}/Submit-PullRequest.ps1 `
-RepoOwner "${{ parameters.RepoOwner }}" `
-RepoName "${{ parameters.RepoName }}" `
-BaseBranch "${{ parameters.BaseBranchName }}" `
-PROwner "${{ parameters.PROwner }}" `
-PRBranch "${{ parameters.PRBranchName }}" `
-AuthToken "$(azuresdk-github-pat)" `
-PRTitle "${{ parameters.PRTitle }}"

- task: PowerShell@2
displayName: Create pull request
workingDirectory: ${{ parameters.WorkingDirectory }}
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: ${{ parameters.ScriptDirectory }}/Submit-PullRequest.ps1
arguments: >
-RepoOwner "${{ parameters.RepoOwner }}"
-RepoName "${{ parameters.RepoName }}"
-BaseBranch "${{ parameters.BaseBranchName }}"
-PROwner "${{ parameters.PROwner }}"
-PRBranch "${{ parameters.PRBranchName }}"
-AuthToken "$(azuresdk-github-pat)"
-PRTitle "${{ parameters.PRTitle }}"
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ steps:
- task: PowerShell@2
displayName: 'Verify Package Tags and Create Git Releases'
inputs:
targetType: filePath
filePath: ${{ parameters.ScriptDirectory }}/create-tags-and-git-release.ps1
arguments: -artifactLocation ${{parameters.ArtifactLocation}} -packageRepository ${{parameters.PackageRepository}} -releaseSha ${{parameters.ReleaseSha}} -repoId ${{parameters.RepoId}} -workingDirectory '${{parameters.WorkingDirectory}}'
arguments: >
-artifactLocation ${{ parameters.ArtifactLocation }}
-packageRepository ${{ parameters.PackageRepository }}
-releaseSha ${{ parameters.ReleaseSha }}
-repoId ${{ parameters.RepoId }}
-workingDirectory '${{ parameters.WorkingDirectory }}'
pwsh: true
timeoutInMinutes: 5
env:
Expand Down
24 changes: 12 additions & 12 deletions eng/common/pipelines/templates/steps/docs-metadata-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ parameters:
steps:
- pwsh: |
git clone https://github.com/${{ parameters.TargetDocRepoOwner }}/${{ parameters.TargetDocRepoName }} ${{ parameters.WorkingDirectory }}/repo

try {
Push-Location ${{ parameters.WorkingDirectory }}/repo

Write-Host "git checkout smoke-test"
git checkout smoke-test
} finally {
Expand All @@ -33,14 +33,14 @@ steps:
inputs:
targetType: filePath
filePath: ${{ parameters.ScriptDirectory }}/update-docs-metadata.ps1
arguments: >
-ArtifactLocation ${{parameters.ArtifactLocation}}
-Repository ${{parameters.PackageRepository}}
-ReleaseSHA ${{parameters.ReleaseSha}}
-RepoId ${{parameters.RepoId}}
-WorkDirectory '${{parameters.WorkingDirectory}}'
-DocRepoLocation "${{parameters.WorkingDirectory}}/repo"
-Language "${{parameters.Language}}"
arguments: >
-ArtifactLocation ${{ parameters.ArtifactLocation }}
-Repository ${{ parameters.PackageRepository }}
-ReleaseSHA ${{ parameters.ReleaseSha }}
-RepoId ${{ parameters.RepoId }}
-WorkDirectory "${{ parameters.WorkingDirectory }}"
-DocRepoLocation "${{ parameters.WorkingDirectory }}/repo"
-Language "${{parameters.Language}}"
-DocRepoContentLocation ${{ parameters.DocRepoDestinationPath }}
pwsh: true
env:
Expand All @@ -54,5 +54,5 @@ steps:
CommitMsg: "Update readme content for ${{ parameters.ArtifactName }}"
PRTitle: "Docs.MS Readme Update."
BaseBranchName: smoke-test
WorkingDirectory: ${{parameters.WorkingDirectory}}/repo
ScriptDirectory: ${{parameters.WorkingDirectory}}/${{parameters.ScriptDirectory}}
WorkingDirectory: ${{ parameters.WorkingDirectory }}/repo
ScriptDirectory: ${{ parameters.WorkingDirectory }}/${{ parameters.ScriptDirectory }}
12 changes: 8 additions & 4 deletions eng/common/pipelines/templates/steps/publish-blobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ parameters:

steps:
- pwsh: |
Invoke-WebRequest -MaximumRetryCount 10 -Uri "https://aka.ms/downloadazcopy-v10-windows" `
-OutFile "azcopy.zip" | Wait-Process; Expand-Archive -Path "azcopy.zip" -DestinationPath "$(Build.BinariesDirectory)/azcopy/"
Invoke-WebRequest -MaximumRetryCount 10 -Uri "https://aka.ms/downloadazcopy-v10-windows" -OutFile "azcopy.zip" | Wait-Process;
Expand-Archive -Path "azcopy.zip" -DestinationPath "$(Build.BinariesDirectory)/azcopy/"
workingDirectory: $(Build.BinariesDirectory)
displayName: Download and Extract azcopy Zip

- task: Powershell@2
inputs:
targetType: 'filePath'
filePath: ${{ parameters.ScriptPath }}
arguments: -AzCopy $(Resolve-Path "$(Build.BinariesDirectory)/azcopy/azcopy_windows_amd64_*/azcopy.exe")[0] -DocLocation "${{ parameters.FolderForUpload }}" -SASKey "${{ parameters.BlobSASKey }}" -Language "${{ parameters.TargetLanguage }}" -BlobName "${{ parameters.BlobName }}"
arguments: >
-AzCopy $(Resolve-Path "$(Build.BinariesDirectory)/azcopy/azcopy_windows_amd64_*/azcopy.exe")[0]
-DocLocation "${{ parameters.FolderForUpload }}"
-SASKey "${{ parameters.BlobSASKey }}"
-Language "${{ parameters.TargetLanguage }}"
-BlobName "${{ parameters.BlobName }}"
pwsh: true
workingDirectory: $(Pipeline.Workspace)
displayName: Copy Docs to Blob
Expand Down
29 changes: 20 additions & 9 deletions eng/common/scripts/Submit-PullRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,25 @@ param(
$PRBody = $PRTitle
)

Write-Host "> $PSCommandPath $args"
$headers = @{
Authorization = "bearer $AuthToken"
}

$query = "state=open&head=${PROwner}:${PRBranch}&base=${BaseBranch}"

$resp = Invoke-RestMethod "https://api.github.com/repos/$RepoOwner/$RepoName/pulls?$query"
try {
$resp = Invoke-RestMethod -Headers $headers "https://api.github.com/repos/$RepoOwner/$RepoName/pulls?$query"
}
catch {
Write-Error "Invoke-RestMethod [https://api.github.com/repos/$RepoOwner/$RepoName/pulls?$query] failed with exception:`n$_"
exit 1
}
$resp | Write-Verbose

if ($resp.Count -gt 0) {
Write-Host -f green "Pull request already exists $($resp[0].html_url)"
}
else {
$headers = @{
Authorization = "bearer $AuthToken"
}

$data = @{
title = $PRTitle
head = "${PROwner}:${PRBranch}"
Expand All @@ -64,9 +68,16 @@ else {
maintainer_can_modify = $true
}

$resp = Invoke-RestMethod -Method POST -Headers $headers `
https://api.github.com/repos/$RepoOwner/$RepoName/pulls `
-Body ($data | ConvertTo-Json)
try {
$resp = Invoke-RestMethod -Method POST -Headers $headers `
"https://api.github.com/repos/$RepoOwner/$RepoName/pulls" `
-Body ($data | ConvertTo-Json)
}
catch {
Write-Error "Invoke-RestMethod [https://api.github.com/repos/$RepoOwner/$RepoName/pulls] failed with exception:`n$_"
exit 1
}

$resp | Write-Verbose
Write-Host -f green "Pull request created https://github.com/$RepoOwner/$RepoName/pull/$($resp.number)"
}
2 changes: 0 additions & 2 deletions eng/common/scripts/copy-docs-to-blobstorage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ param (
$UploadLatest=1
)

Write-Host "> $PSCommandPath $args"

$Language = $Language.ToLower()

# Regex inspired but simplified from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
Expand Down
2 changes: 0 additions & 2 deletions eng/common/scripts/create-tags-and-git-release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ param (
[switch]$continueOnError = $false
)

Write-Host "> $PSCommandPath $args"

. (Join-Path $PSScriptRoot artifact-metadata-parsing.ps1)

$apiUrl = "https://api.github.com/repos/$repoId"
Expand Down
4 changes: 1 addition & 3 deletions eng/common/scripts/git-branch-push.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ param(
[string] $PushArgs = ""
)

Write-Host "> $PSCommandPath $args"

# This is necessay because of the janky git command output writing to stderr.
# Without explicitly setting the ErrorActionPreference to continue the script
# would fail the first time git wrote command output.
Expand Down Expand Up @@ -122,7 +120,7 @@ do
}

Write-Host "git add -A"
git add -A
git add -A
if ($LASTEXITCODE -ne 0)
{
Write-Error "Unable to git add LASTEXITCODE=$($LASTEXITCODE), see command output above."
Expand Down
6 changes: 2 additions & 4 deletions eng/common/scripts/update-docs-metadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ param (
$DocRepoContentLocation = "docs-ref-services/" # within the doc repo, where does our readme go?
)

Write-Host "> $PSCommandPath $args"


# import artifact parsing and semver handling
. (Join-Path $PSScriptRoot artifact-metadata-parsing.ps1)
Expand Down Expand Up @@ -58,7 +56,7 @@ function GetAdjustedReadmeContent($pkgInfo, $lang){
$pkgId = $pkgInfo.PackageId.Replace("@azure/", "")

try {
$metadata = GetMetaData -lang $lang
$metadata = GetMetaData -lang $lang

$service = $metadata | ? { $_.Package -eq $pkgId }

Expand Down Expand Up @@ -99,7 +97,7 @@ $pkgs = VerifyPackages -pkgRepository $Repository `

if ($pkgs) {
Write-Host "Given the visible artifacts, readmes will be copied for the following packages"
Write-Host ($pkgs | % { $_.PackageId })
Write-Host ($pkgs | % { $_.PackageId })

foreach ($packageInfo in $pkgs) {
# sync the doc repo
Expand Down