-
Notifications
You must be signed in to change notification settings - Fork 4
/
.gitlab-ci.yml
92 lines (85 loc) · 3.35 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TITLE =~ /^(\[Draft\]|\(Draft\)|Draft:)/
when: never
default:
# UBI is RedHat's free Universal Base Image.
image: mcr.microsoft.com/powershell/test-deps:ubi-9
cache:
- key: test-cache
paths:
- /opt/bitwarden-cli/
- /home/runner/.local/share/powershell/Modules/
before_script:
- Install-PSResource -Name Pester,Microsoft.PowerShell.SecretManagement -Repository PSGallery -TrustRepository
- |
# Get Latest Version Number
$res = Invoke-RestMethod "https://github.com/bitwarden/clients/releases.atom"
$version = ($res.id | Select-String -Pattern "(?<=\/cli-v)([\d.]+)").Matches[0].Value
# Determine OS string.
if($IsWindows) { $os = "windows"}
elseif($IsMacOS) { $os = "macos"}
elseif($IsLinux) { $os = "linux"}
# Download file list
$Downloads = @(
@{
Name = "Binary"
Uri = "https://github.com/bitwarden/clients/releases/download/cli-v$version/bw-$os-$version.zip"
OutFile = New-TemporaryFile
},
@{
Name = "Checksum"
Uri = "https://github.com/bitwarden/clients/releases/download/cli-v$version/bw-$os-sha256-$version.txt"
OutFile = New-TemporaryFile
}
)
# Download files in parallel.
$jobs = @()
foreach ($Download in $Downloads) {
$jobs += Start-ThreadJob -Name $Download.Name -ScriptBlock {
$params = $using:Download
Invoke-WebRequest -Uri $params.Uri -OutFile $params.OutFile
}
}
Write-Host "Downloading Bitwarden"
Receive-Job -Job $jobs -Wait
$hash = Get-FileHash -Path ($Downloads | Where-Object {$_.Name -eq "Binary"}).OutFile -Algorithm SHA256
$checksum = Get-Content -Path ($Downloads | Where-Object {$_.Name -eq "Checksum"}).OutFile
if($hash.Hash -ine $checksum) {
Write-Error @"
The SHA256 Hash of the Downloaded Bitwarden CLI Doesn't Match The Provided Checksum!
Hash: {0}
Checksum: {1}
"@ -f $hash.Hash, $checksum
}
else {
if(!(Test-Path -Path "/opt/bitwarden-cli/" -PathType Container)) {
New-Item -Path "/opt/bitwarden-cli/" -ItemType Directory | Out-Null
}
# Extract bw from the downloaded zip file.
Expand-Archive -Path ($Downloads | Where-Object {$_.Name -eq "Binary"}).OutFile -DestinationPath /opt/bitwarden-cli/
# Cleanup Downloaded Files
$Downloads.OutFile | Remove-Item
}
tests:
stage: test
script:
- |
Import-Module Microsoft.PowerShell.SecretManagement
$env:BITWARDEN_CLI_PATH = (Get-ChildItem -Path "/opt/bitwarden-cli" -Filter "bw*" -File).FullName
$config = New-PesterConfiguration
$config.Run.Path = "."
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.OutputFormat = 'JaCoCo'
$config.CodeCoverage.OutputPath = 'coverage.xml'
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = "JUnitXml"
$config.TestResult.OutputPath = "testResults.xml"
Invoke-Pester -Configuration $config
artifacts:
reports:
coverage_report:
path: coverage.xml
coverage_format: jacoco
junit: testResults.xml
coverage: /Covered (\d+\.\d+%)/