Skip to content

Commit ee31b25

Browse files
authored
Merge pull request #21 from stiwicourage/develop
Enhance workflows and add Nova CLI functions for project management
2 parents e68cf8f + 8dcd12f commit ee31b25

19 files changed

Lines changed: 577 additions & 6 deletions

.github/workflows/Tests.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ name: Run Tests
22

33
on:
44
push:
5-
branches:
6-
- main
75
pull_request:
86
branches:
97
- main
8+
- develop
109
workflow_dispatch:
1110

1211
defaults:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Dependency Review Action
2+
#
3+
# This Action will scan dependency manifest files that change as part of a Pull Request,
4+
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
5+
# Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable
6+
# packages will be blocked from merging.
7+
#
8+
# Source repository: https://github.com/actions/dependency-review-action
9+
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
10+
name: 'Dependency review'
11+
on:
12+
pull_request:
13+
branches: [ "develop" ]
14+
15+
# If using a dependency submission action in this workflow this permission will need to be set to:
16+
#
17+
# permissions:
18+
# contents: write
19+
#
20+
# https://docs.github.com/en/enterprise-cloud@latest/code-security/supply-chain-security/understanding-your-software-supply-chain/using-the-dependency-submission-api
21+
permissions:
22+
contents: read
23+
# Write permissions for pull-requests are required for using the `comment-summary-in-pr` option, comment out if you aren't using this option
24+
pull-requests: write
25+
26+
jobs:
27+
dependency-review:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: 'Checkout repository'
31+
uses: actions/checkout@v4
32+
- name: 'Dependency Review'
33+
uses: actions/dependency-review-action@v4
34+
# Commonly enabled options, see https://github.com/actions/dependency-review-action#configuration-options for all available options.
35+
with:
36+
comment-summary-in-pr: always
37+
# fail-on-severity: moderate
38+
# deny-licenses: GPL-1.0-or-later, LGPL-2.0-or-later
39+
# retry-on-snapshot-warnings: true

.github/workflows/powershell.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
#
6+
# https://github.com/microsoft/action-psscriptanalyzer
7+
# For more information on PSScriptAnalyzer in general, see
8+
# https://github.com/PowerShell/PSScriptAnalyzer
9+
10+
name: PSScriptAnalyzer
11+
12+
on:
13+
push:
14+
branches: [ "develop" ]
15+
pull_request:
16+
branches: [ "develop" ]
17+
schedule:
18+
- cron: '22 19 * * 2'
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
build:
25+
permissions:
26+
contents: read # for actions/checkout to fetch code
27+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
28+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
29+
name: PSScriptAnalyzer
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Run PSScriptAnalyzer
35+
uses: microsoft/psscriptanalyzer-action@6b2948b1944407914a58661c49941824d149734f
36+
with:
37+
# Check https://github.com/microsoft/action-psscriptanalyzer for more info about the options.
38+
# The below set up runs PSScriptAnalyzer to your entire repository and runs some basic security rules.
39+
path: .\
40+
recurse: true
41+
# Include your own basic security rules. Removing this option will run all the rules
42+
includeRule: '"PSAvoidGlobalAliases", "PSAvoidUsingConvertToSecureStringWithPlainText"'
43+
output: results.sarif
44+
45+
# Upload the SARIF file generated in the previous step
46+
- name: Upload SARIF results file
47+
uses: github/codeql-action/upload-sarif@v3
48+
with:
49+
sarif_file: results.sarif

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ This is not required for local module builds. In this repository, GitHub Actions
236236
If you are running GitHub Actions, use the following yaml workflow template to test, build and publish a module, which helps to automate the process of:
237237

238238
1. Checking out the repository code.
239-
1. Installing the `ModuleTools` bootstrap module from the PowerShell Gallery.
239+
1. Installing the `NovaModuleTools` bootstrap module from the PowerShell Gallery.
240240
1. Building the module.
241241
1. Running Pester tests.
242242
1. Running semantic-release to choose the version, update release files, tag, and publish.
@@ -273,9 +273,9 @@ jobs:
273273
npm ci
274274
shell: pwsh
275275

276-
- name: Install ModuleTools bootstrap module form PSGallery
276+
- name: Install NovaModuleTools bootstrap module form PSGallery
277277
run: |
278-
Install-PSResource -Repository PSGallery -Name ModuleTools -TrustRepository
278+
Install-PSResource -Repository PSGallery -Name NovaModuleTools -TrustRepository
279279
Install-PSResource -Repository PSGallery -Name Microsoft.PowerShell.PlatyPS -TrustRepository
280280
Install-PSResource -Repository PSGallery -Name Pester -TrustRepository
281281
shell: pwsh

nova

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env pwsh
2+
param(
3+
[Parameter(Position = 0)]
4+
[string]$Command,
5+
6+
[Parameter(Position = 1, ValueFromRemainingArguments)]
7+
[string[]]$Arguments
8+
)
9+
10+
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
11+
$projectFile = Join-Path $scriptRoot 'project.json'
12+
$projectName = if (Test-Path -LiteralPath $projectFile) {
13+
(Get-Content -LiteralPath $projectFile -Raw | ConvertFrom-Json).ProjectName
14+
}
15+
else {
16+
'NovaModuleTools'
17+
}
18+
19+
function Import-NovaSourceScripts {
20+
$srcRoot = Join-Path $scriptRoot 'src'
21+
$scriptFolders = @('private', 'public')
22+
23+
foreach ($folder in $scriptFolders) {
24+
$folderPath = Join-Path $srcRoot $folder
25+
if (-not (Test-Path -LiteralPath $folderPath)) {
26+
continue
27+
}
28+
29+
$files = Get-ChildItem -Path $folderPath -Filter '*.ps1' -File -Recurse | Sort-Object FullName
30+
foreach ($file in $files) {
31+
. $file.FullName
32+
}
33+
}
34+
}
35+
36+
$distModulePath = Join-Path $scriptRoot "dist/$projectName"
37+
$distModuleFile = Join-Path $distModulePath "$projectName.psm1"
38+
39+
if (Test-Path -LiteralPath $distModuleFile) {
40+
Import-Module $distModulePath -Force
41+
}
42+
elseif (Test-Path -LiteralPath (Join-Path $scriptRoot 'src/public/InvokeNovaCli.ps1')) {
43+
Import-NovaSourceScripts
44+
}
45+
else {
46+
Import-Module $projectName -Force
47+
}
48+
49+
Invoke-NovaCli -Command $Command @Arguments
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function Get-GitCommitMessageForVersionBump {
2+
[CmdletBinding()]
3+
param(
4+
[Parameter(Mandatory)][string]$ProjectRoot
5+
)
6+
7+
if (-not (Test-Path -LiteralPath (Join-Path $ProjectRoot '.git'))) {
8+
return @()
9+
}
10+
11+
$format = '%s%n%b%n--END-COMMIT--'
12+
$lastTag = & git -C $ProjectRoot describe --tags --abbrev=0 2> $null
13+
14+
if ($LASTEXITCODE -eq 0 -and -not [string]::IsNullOrWhiteSpace($lastTag)) {
15+
$raw = & git -C $ProjectRoot log "$lastTag..HEAD" --format=$format 2> $null
16+
}
17+
else {
18+
$raw = & git -C $ProjectRoot log --format=$format 2> $null
19+
}
20+
21+
if ($LASTEXITCODE -ne 0 -or -not $raw) {
22+
return @()
23+
}
24+
25+
$text = ($raw -join [Environment]::NewLine)
26+
$commits = $text -split '(?m)^--END-COMMIT--\r?$'
27+
return @($commits | ForEach-Object {$_.Trim()} | Where-Object {-not [string]::IsNullOrWhiteSpace($_)})
28+
}
29+

src/private/GetNovaCliOptions.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
function ConvertFrom-NovaCliArgument {
2+
[CmdletBinding()]
3+
param(
4+
[string[]]$Arguments
5+
)
6+
7+
$options = @{}
8+
$index = 0
9+
10+
while ($index -lt $Arguments.Count) {
11+
$token = $Arguments[$index]
12+
13+
switch -Regex ($token) {
14+
'^(--local|-Local)$' {
15+
$options.Local = $true
16+
}
17+
'^(--repository|-Repository)$' {
18+
$index++
19+
if ($index -ge $Arguments.Count) {
20+
throw 'Missing value for --repository'
21+
}
22+
23+
$options.Repository = $Arguments[$index]
24+
}
25+
'^(--path|-Path|-ModuleDirectoryPath)$' {
26+
$index++
27+
if ($index -ge $Arguments.Count) {
28+
throw 'Missing value for --path'
29+
}
30+
31+
$options.ModuleDirectoryPath = $Arguments[$index]
32+
}
33+
'^(--apikey|-ApiKey)$' {
34+
$index++
35+
if ($index -ge $Arguments.Count) {
36+
throw 'Missing value for --apikey'
37+
}
38+
39+
$options.ApiKey = $Arguments[$index]
40+
}
41+
default {
42+
throw "Unknown argument: $token"
43+
}
44+
}
45+
46+
$index++
47+
}
48+
49+
return $options
50+
}
51+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function Get-VersionLabelFromCommitSet {
2+
[CmdletBinding()]
3+
param(
4+
[Parameter(Mandatory)][string[]]$Messages
5+
)
6+
7+
if ($Messages | Where-Object {$_ -match '(?im)BREAKING CHANGE|^[a-z]+(\(.+\))?!:'}) {
8+
return 'Major'
9+
}
10+
11+
if ($Messages | Where-Object {$_ -match '(?im)^\s*feat(\(.+\))?:'}) {
12+
return 'Minor'
13+
}
14+
15+
if ($Messages | Where-Object {$_ -match '(?im)^\s*fix(\(.+\))?:'}) {
16+
return 'Patch'
17+
}
18+
19+
return 'Patch'
20+
}
21+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function Publish-NovaBuiltModule {
2+
[CmdletBinding(DefaultParameterSetName = 'Local')]
3+
param(
4+
[Parameter(ParameterSetName = 'Repository')]
5+
[string]$Repository,
6+
7+
[string]$ModuleDirectoryPath,
8+
[string]$ApiKey
9+
)
10+
11+
$projectInfo = Get-MTProjectInfo
12+
13+
if (-not (Test-Path -LiteralPath $projectInfo.OutputModuleDir)) {
14+
throw 'Dist folder is empty, build the module before running publish command'
15+
}
16+
17+
if ($PSCmdlet.ParameterSetName -eq 'Repository') {
18+
$resolvedApiKey = $ApiKey
19+
if ($Repository -eq 'PSGallery' -and [string]::IsNullOrWhiteSpace($resolvedApiKey)) {
20+
$resolvedApiKey = $env:PSGALLERY_API
21+
}
22+
23+
$publishParams = @{
24+
Path = $projectInfo.OutputModuleDir
25+
Repository = $Repository
26+
Verbose = $true
27+
}
28+
29+
if (-not [string]::IsNullOrWhiteSpace($resolvedApiKey)) {
30+
$publishParams.ApiKey = $resolvedApiKey
31+
}
32+
33+
Publish-PSResource @publishParams
34+
return
35+
}
36+
37+
Publish-MTLocal -ModuleDirectoryPath $ModuleDirectoryPath
38+
}
39+

src/public/GetNovaProjectInfo.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function Get-NovaProjectInfo {
2+
[CmdletBinding()]
3+
param(
4+
[Parameter(Position = 0)]
5+
[string]$Path = (Get-Location).Path,
6+
7+
[switch]$Version
8+
)
9+
10+
$projectInfo = Get-MTProjectInfo -Path $Path
11+
12+
if ($Version) {
13+
return $projectInfo.Version
14+
}
15+
16+
return $projectInfo
17+
}

0 commit comments

Comments
 (0)