Skip to content

Commit d6f0313

Browse files
Merge pull request #39 from steviecoaster/develop
Release
2 parents 4d1af1d + a6e0647 commit d6f0313

37 files changed

+457
-128
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,29 @@ jobs:
1919
ChocoApiKey: ${{ secrets.ChocoApiKey }}
2020

2121
steps:
22-
- uses: actions/checkout@v2
23-
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0 # Required for GitVersion to behave
25+
2426
- name: GitVersion
2527
id: gitversion
26-
uses: PoshCode/Actions/gitversion@v1
28+
uses: PoshCode/Actions/gitversion@v1.0.1
2729

2830
- name: Install-RequiredModules
2931
uses: PoshCode/Actions/install-requiredmodules@v1
3032

3133
- name: Build Module
32-
run: .\build.ps1 -Build -SemVer "${{ steps.gitversion.outputs.LegacySemVerPadded }}"
34+
run: .\build.ps1 -Build -SemVer "${{ steps.gitversion.outputs.SemVer }}"
3335
shell: pwsh
3436

3537
- name: Upload Built Module
36-
uses: actions/upload-artifact@v2
38+
uses: actions/upload-artifact@v4
3739
with:
38-
name: NexuShell.${{ steps.gitversion.outputs.LegacySemVerPadded }}
40+
name: NexuShell.${{ steps.gitversion.outputs.SemVer }}
3941
path: .\Output
4042

4143
- name: Test Module
42-
run: .\build.ps1 -TestPrePublish -SemVer "${{ steps.gitversion.outputs.LegacySemVerPadded }}"
44+
run: .\build.ps1 -TestPrePublish -SemVer "${{ steps.gitversion.outputs.SemVer }}"
4345
shell: pwsh
4446

4547
- name: Upload Test Results
@@ -66,4 +68,4 @@ jobs:
6668

6769
- name: Publish Module
6870
if: ${{ github.ref == 'refs/heads/main' }}
69-
run: .\build.ps1 -DeployToGallery -SemVer "${{ steps.gitversion.outputs.LegacySemVerPadded }}"
71+
run: .\build.ps1 -DeployToGallery -SemVer "${{ steps.gitversion.outputs.SemVer }}"

.vscode/tasks.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "Build Module",
8+
"type": "shell",
9+
"command": "${workspaceFolder}\\Build.ps1 -Build",
10+
"problemMatcher": [],
11+
"group": {
12+
"kind": "build",
13+
"isDefault": true
14+
}
15+
}
16+
]
17+
}

Build.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@{
22
ModuleManifest = ".\src\NexuShell.psd1"
33
SourceDirectories = "private", "public"
4+
Suffix = "Suffix.ps1"
45
}

build.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ param(
2424
[string]
2525
$SemVer = $(
2626
if (Get-Command gitversion -ErrorAction SilentlyContinue) {
27-
(gitversion | ConvertFrom-Json).LegacySemVerPadded
27+
if (([version]((gitversion /version).Split('+')[0])).Major -gt 5) {
28+
gitversion /showvariable SemVer
29+
} else {
30+
gitversion /showvariable LegacySemVerPadded
31+
}
2832
}
2933
)
3034
)
@@ -92,13 +96,15 @@ process {
9296
Compress-Archive -Path $root\Output\* -DestinationPath $PackageSource\tools\NexuShell.zip -Force #Added force to allow local testing without shenanigans
9397

9498
if (Test-Path "$PackageSource\tools\NexuShell.zip") {
95-
choco pack $Nuspec.FullName --output-directory $root
99+
choco pack $Nuspec.FullName --version $SemVer --output-directory $root
96100
} else {
97101
throw "Welp, ya need the zip in the tools folder, dumby"
98102
}
99103

100-
Get-ChildItem $PackageSource -recurse -filter *.nupkg | ForEach-Object {
101-
choco push $_.FullName -s https://push.chocolatey.org --api-key="'$($env:ChocoApiKey)'"
104+
if ($env:ChocoApiKey) {
105+
Get-ChildItem $PackageSource -Recurse -Filter *.nupkg | ForEach-Object {
106+
choco push $_.FullName -s https://push.chocolatey.org --api-key="'$($env:ChocoApiKey)'"
107+
}
102108
}
103109
}
104110
}

src/NexuShell.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
FunctionsToExport = @()
2424
CmdletsToExport = @()
2525
VariablesToExport = @()
26-
AliasesToExport = @('Get-NexusLifecycle','New-NexusLifecycle')
26+
AliasesToExport = @('Get-NexusLifecycle','New-NexusLifecycle','Get-NexusUri')
2727

2828
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
2929
PrivateData = @{

src/Suffix.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$script:InstalledNexusService = Get-NexusRepositoryServiceInstall -ErrorAction SilentlyContinue

src/nuget/tools/chocolateyInstall.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ $PathSegment = @{
2525
Core = "PowerShell\Modules\"
2626

2727
AllUsers = $env:ProgramFiles
28-
CurrentUser = $PROFILE | Split-Path | Split-Path
28+
CurrentUser = try {
29+
$PROFILE | Split-Path | Split-Path
30+
} catch {
31+
Write-Warning "Profile is set to '$($PROFILE)'. Current user '$($env:USERNAME)' may not be able to install at user level."
32+
}
2933
}
3034

3135
$Parameters = Get-PackageParameters
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function Get-NexusCertificateDomain {
2+
<#
3+
.SYNOPSIS
4+
Returns the Certificate domain for the specified Nexus configuration, if present.
5+
6+
.DESCRIPTION
7+
Uses the KeyTool to open the currently used KeyStore and grab the domain.
8+
9+
.PARAMETER DataDir
10+
The path to the Sonatype Nexus data directory, e.g. C:\ProgramData\sonatype-work\nexus3.
11+
12+
.PARAMETER ProgramDir
13+
The path to the Sonatype Nexus program files, e.g. C:\ProgramData\nexus.
14+
15+
.EXAMPLE
16+
Get-NexusCertificateDomain -DataDir C:\ProgramData\sonatype-work\nexus3 -ProgramDir C:\ProgramData\nexus
17+
#>
18+
param(
19+
[string]$DataDir = $script:InstalledNexusService.DataFolder,
20+
21+
[string]$ProgramDir = $script:InstalledNexusService.ProgramFolder
22+
)
23+
$Config = Get-NexusConfiguration -Path $DataDir\etc\nexus.properties
24+
if ($Config.'nexus-args'.Split(',') -contains '${jetty.etc}/jetty-https.xml') {
25+
[xml]$HttpsConfig = Get-Content $ProgramDir\etc\jetty\jetty-https.xml
26+
$KeyToolPath = Join-Path $ProgramDir "jre/bin/keytool.exe"
27+
$KeyStorePath = Join-Path (Join-Path $ProgramDir "etc/ssl") $HttpsConfig.SelectSingleNode("//Set[@name='KeyStorePath']").'#text'
28+
$KeyStorePassword = $HttpsConfig.SelectSingleNode("//Set[@name='KeyStorePassword']").'#text'
29+
30+
if ((Test-Path $KeyToolPath) -and (Test-Path $KeyStorePath)) {
31+
# Running in a job, as otherwise KeyTool fails when run without input
32+
Start-Job {
33+
$KeyToolOutput = $using:KeyStorePassword | & "$using:KeyToolPath" -list -v -keystore "$using:KeyStorePath" -J"-Duser.language=en" 2>$null
34+
if ($KeyToolOutput -join "`n" -match "(?smi)Certificate\[1\]:\nOwner: CN=(?<Domain>.+?)(\n|,)") {
35+
$Matches.Domain
36+
}
37+
} | Receive-Job -Wait
38+
}
39+
}
40+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function Get-NexusConfiguration {
2+
<#
3+
.SYNOPSIS
4+
Returns a list of settings configured in nexus.properties.
5+
6+
.DESCRIPTION
7+
Retrieves the specified file (defaulting to the default install location) and returns each active setting.
8+
9+
.PARAMETER Path
10+
The path to the properties file to return.
11+
12+
.EXAMPLE
13+
Get-NexusConfiguration
14+
# Returns all properties and values
15+
16+
.EXAMPLE
17+
(Get-NexusConfiguration).'application-port-ssl'
18+
# Returns the value for a single property, 'application-port-ssl'
19+
#>
20+
[CmdletBinding()]
21+
param(
22+
$Path = (Join-Path $script:InstalledNexusService.DataFolder "etc\nexus.properties")
23+
)
24+
Get-Content $Path | Where-Object {
25+
$_ -and $_ -notmatch "^\W*#"
26+
} | ConvertFrom-StringData
27+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function Get-NexusRepositoryServiceInstall {
2+
<#
3+
.SYNOPSIS
4+
If found, returns the name of the Nexus service and the install and data directories it uses.
5+
6+
.DESCRIPTION
7+
Checks all current services for services that run "nexus.exe", then returns the program and data directories for one/each.
8+
9+
.PARAMETER AllResults
10+
To speed up execution, by default we check services until we find the first one running nexus.exe.
11+
If you have more than one instance installed, you can use this switch to check all services.
12+
13+
.EXAMPLE
14+
Get-NexusRepositoryInstallValues
15+
#>
16+
[CmdletBinding()]
17+
param(
18+
# By default, we assume there is only one service. This searches for all installed services.
19+
[switch]$AllResults
20+
)
21+
# If you have a lot of services, searching them all may take longer -
22+
# so we can stop searching when we find the first service matching nexus.exe.
23+
$ResultCount = @{}
24+
if (-not $AllResults) { $ResultCount.First = 1 }
25+
26+
$NexusService = Get-ChildItem HKLM:\System\CurrentControlSet\Services\ | Where-Object {
27+
($ImagePath = Get-ItemProperty -Path $_.PSPath -Name ImagePath -ErrorAction SilentlyContinue) -and
28+
$ImagePath.ImagePath.Trim('"''').EndsWith('\nexus.exe')
29+
} | Select-Object @ResultCount
30+
31+
foreach ($Service in $NexusService) {
32+
$ServiceName = $Service.PSChildName
33+
$TargetFolder = (Get-ItemProperty -Path $Service.PSPath).ImagePath.Trim('"''') | Split-Path | Split-Path
34+
$DataFolder = Convert-Path (Join-Path $TargetFolder "$((Get-Content $TargetFolder\bin\nexus.vmoptions) -match '^-Dkaraf.data=(?<RelativePath>.+)$' -replace '^-Dkaraf.data=')")
35+
[PSCustomObject]@{
36+
ServiceName = $ServiceName
37+
ProgramFolder = $TargetFolder
38+
DataFolder = $DataFolder
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)