Skip to content

Commit 41db13d

Browse files
authored
Merge branch 'main' into docs/issues
2 parents 4d5db69 + 6e8c8e4 commit 41db13d

46 files changed

Lines changed: 2029 additions & 635 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Update ubuntu runner"
2+
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Updating PowerShell
7+
shell: bash
8+
run: |
9+
###################################
10+
# Prerequisites
11+
12+
# Update the list of packages
13+
sudo apt-get update
14+
15+
# Install pre-requisite packages.
16+
sudo apt-get install -y wget apt-transport-https software-properties-common
17+
18+
# Get the version of Ubuntu
19+
source /etc/os-release
20+
21+
# Download the Microsoft repository keys
22+
wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
23+
24+
# Register the Microsoft repository keys
25+
sudo dpkg -i packages-microsoft-prod.deb
26+
27+
# Delete the the Microsoft repository keys file
28+
rm packages-microsoft-prod.deb
29+
30+
# Update the list of packages after we added packages.microsoft.com
31+
sudo apt-get update
32+
33+
###################################
34+
# Install PowerShell
35+
sudo apt-get install -y powershell
36+
37+
# Start PowerShell
38+
pwsh -v

.github/scripts/pester.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$config = New-PesterConfiguration
2+
$config.Run.Path = @('./tests/')
3+
$config.Run.ExcludePath = @('./tests/pester.ps1', './tests/Indented.ScriptAnalyzerRules/')
4+
$config.Run.Exit = $true
5+
$config.Output.CIFormat = 'GithubActions'
6+
$config.Output.Verbosity = 'Detailed'
7+
Invoke-Pester -Configuration $config

.github/workflows/Documentation.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: 📄 Documentation
22
on:
3+
workflow_dispatch:
34
push:
45
branches:
56
- main
@@ -11,6 +12,9 @@ jobs:
1112
name: Deploy docs to GitHub Pages
1213
runs-on: ubuntu-latest
1314
steps:
15+
- name: Update ubuntu runner
16+
uses: ./.github/actions/update-ubuntu-runner
17+
id: update-ubuntu-runner
1418
- name: Checkout
1519
uses: actions/checkout@v2
1620
- name: Test

.github/workflows/Release.yaml

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,9 @@ jobs:
88
name: Release module
99
runs-on: ubuntu-latest
1010
steps:
11-
- name: Updating PowerShell
12-
run: |
13-
###################################
14-
# Prerequisites
15-
16-
# Update the list of packages
17-
sudo apt-get update
18-
19-
# Install pre-requisite packages.
20-
sudo apt-get install -y wget apt-transport-https software-properties-common
21-
22-
# Get the version of Ubuntu
23-
source /etc/os-release
24-
25-
# Download the Microsoft repository keys
26-
wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
27-
28-
# Register the Microsoft repository keys
29-
sudo dpkg -i packages-microsoft-prod.deb
30-
31-
# Delete the the Microsoft repository keys file
32-
rm packages-microsoft-prod.deb
33-
34-
# Update the list of packages after we added packages.microsoft.com
35-
sudo apt-get update
36-
37-
###################################
38-
# Install PowerShell
39-
sudo apt-get install -y powershell
40-
41-
# Start PowerShell
42-
pwsh -v
11+
- name: Update ubuntu runner
12+
uses: ./.github/actions/update-ubuntu-runner
13+
id: update-ubuntu-runner
4314
- name: Checkout code
4415
uses: actions/checkout@v3
4516
with:

.github/workflows/Tests.yaml

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
11
name: ⚗️ Tests
22
on: [pull_request]
33
jobs:
4-
test:
5-
name: Run Tests
6-
runs-on: ${{ matrix.os }}
7-
strategy:
8-
fail-fast: false
9-
matrix:
10-
os: [ubuntu-latest, windows-latest]
4+
scriptanalyzer:
5+
permissions:
6+
contents: read
7+
name: PSScriptAnalyzer Tests
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- name: Update ubuntu runner
12+
uses: ./.github/actions/update-ubuntu-runner
13+
id: update-ubuntu-runner
14+
- name: Run PSScriptAnalyzer
15+
shell: pwsh
16+
run: |
17+
$invokeScriptAnalyzerSplat = @{
18+
Path = 'AzureDevOpsPowerShell'
19+
ReportSummary = $true
20+
Recurse = $true
21+
Settings = 'tests/ScriptAnalyzerSettings.psd1'
22+
EnableExit = $true
23+
}
24+
Invoke-ScriptAnalyzer @invokeScriptAnalyzerSplat
25+
pester:
26+
permissions:
27+
contents: read
28+
name: Pester Tests
29+
runs-on: ubuntu-latest
1130
steps:
1231
- uses: actions/checkout@v3
13-
- name: Test
32+
- name: Update ubuntu runner
33+
uses: ./.github/actions/update-ubuntu-runner
34+
id: update-ubuntu-runner
35+
- name: Build
36+
shell: pwsh
37+
run: |
38+
./build.ps1 -Task Build -Bootstrap
39+
- name: Run Pester
1440
shell: pwsh
1541
run: |
16-
./build.ps1 -task GenerateMarkdown -Bootstrap
42+
.github/scripts/pester.ps1
1743
validate-commits:
1844
runs-on: ubuntu-latest
1945
steps:

.github/workflows/powershell.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ name: PSScriptAnalyzer
22

33
on:
44
push:
5-
branches: [ "main"]
6-
pull_request:
7-
branches: [ "main" ]
5+
branches: ["main"]
86
schedule:
9-
- cron: '27 5 * * 3'
7+
- cron: "27 5 * * 3"
108

119
permissions:
1210
contents: read

AzureDevOpsPowerShell/Public/Api/ApprovalsAndChecks/CheckConfigurations/Add-AzDoPipelineBranchControl.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ function Add-AzDoPipelineBranchControl {
55
.DESCRIPTION
66
Creates a Build Validation policy on a branch
77
.EXAMPLE
8-
```powershell
98
$params = @{
109
CollectionUri = "https://dev.azure.com/contoso"
1110
PAT = "***"
@@ -14,7 +13,7 @@ function Add-AzDoPipelineBranchControl {
1413
ProjectName = "Project 1"
1514
Id = 1
1615
}
17-
```
16+
1817
Set-AzDoBranchPolicyBuildValidation @params
1918
2019
This example creates a policy with splatting parameters
@@ -89,7 +88,7 @@ function Add-AzDoPipelineBranchControl {
8988
}
9089

9190
Process {
92-
$projectId = (Get-AzDoproject -CollectionUri $CollectionUri -ProjectName $ProjectName).projectId
91+
$projectId = (Get-AzDoProject -CollectionUri $CollectionUri -ProjectName $ProjectName).projectId
9392

9493
foreach ($name in $ResourceName) {
9594

AzureDevOpsPowerShell/Public/Api/Core/Projects/Get-AzDoProject.ps1

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,17 @@ function Get-AzDoProject {
7171
method = 'GET'
7272
}
7373

74-
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get Environments from: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) {
75-
$projects = (Invoke-AzDoRestMethod @params).value
74+
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get Project(s)")) {
75+
Write-Debug "Calling Invoke-AzDoRestMethod with"
76+
Write-Debug ($params | Out-String)
77+
78+
$result = (Invoke-AzDoRestMethod @params).value | Where-Object { -not $ProjectName -or $_.Name -in $ProjectName }
7679

77-
if ($ProjectName) {
78-
foreach ($name in $ProjectName) {
79-
$project = $projects | Where-Object { $_.name -eq $name }
80-
if (-not($project)) {
81-
Write-Warning "Project $name not found"
82-
} else {
83-
$result += $project
84-
}
85-
}
86-
} else {
87-
$result += $projects
88-
}
8980

9081
} else {
91-
$body | Format-List
82+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
9283
}
9384
}
94-
9585
end {
9686
if ($result) {
9787
$result | ForEach-Object {
@@ -107,3 +97,4 @@ function Get-AzDoProject {
10797
}
10898
}
10999
}
100+

AzureDevOpsPowerShell/Public/Api/Core/Projects/New-AzDoProject.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,18 @@ function New-AzDoProject {
149149
}
150150

151151
if ($PSCmdlet.ShouldProcess($CollectionUri, "Create project named: $($PSStyle.Bold)$name$($PSStyle.Reset)")) {
152-
153-
$body | Invoke-AzDoRestMethod @params | Out-Null
152+
Write-Debug "Calling Invoke-AzDoRestMethod with"
153+
Write-Debug ($params | Out-String)
154+
155+
try {
156+
$body | Invoke-AzDoRestMethod @params | Out-Null
157+
} catch {
158+
if ($_ -match 'TF200019') {
159+
Write-Warning "Project $name already exists, trying to get it"
160+
} else {
161+
Write-AzDoError -message $_
162+
}
163+
}
154164

155165
do {
156166
Start-Sleep 5
@@ -165,6 +175,8 @@ function New-AzDoProject {
165175
$response.State -ne 'wellFormed'
166176
)
167177
$result += ($response)
178+
} else {
179+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
168180
}
169181
}
170182
}

AzureDevOpsPowerShell/Public/Api/Core/Projects/Remove-AzDoProject.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Remove-AzDoProject {
4646
)
4747

4848
begin {
49-
$result = New-Object -TypeName "System.Collections.ArrayList"
49+
$result = @()
5050
}
5151

5252
Process {
@@ -61,7 +61,12 @@ function Remove-AzDoProject {
6161
}
6262

6363
if ($PSCmdlet.ShouldProcess($CollectionUri, "Delete project named: $($PSStyle.Bold)$name$($PSStyle.Reset)")) {
64-
$result.add((Invoke-AzDoRestMethod @params)) | Out-Null
64+
Write-Debug "Calling Invoke-AzDoRestMethod with"
65+
Write-Debug ($params | Out-String)
66+
67+
$result += Invoke-AzDoRestMethod @params
68+
} else {
69+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
6570
}
6671
}
6772
}

0 commit comments

Comments
 (0)