Skip to content

Commit 0d56cac

Browse files
committed
Add GH Action to publsih module on GH release
1 parent 2af4ca6 commit 0d56cac

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

.github/workflows/publish.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Publish
2+
on:
3+
workflow_dispatch:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
name: Publish
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Publish
14+
shell: pwsh
15+
run: |
16+
$apiKey = '${{ secrets.PS_GALLERY_API_KEY }}' | ConvertTo-SecureString -AsPlainText -Force
17+
$cred = [pscredential]::new('apikey', $apiKey)
18+
./build.ps1 -Task Publish -PSGalleryApiKey $cred -Bootstrap

.github/workflows/push.yml renamed to .github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: CI
1+
name: Test
22
on: [push]
33
jobs:
44
test:
5-
name: Run Tests
5+
name: Test
66
runs-on: ${{ matrix.os }}
77
strategy:
88
fail-fast: false

build.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ param(
2727

2828
# List available build tasks
2929
[parameter(ParameterSetName = 'Help')]
30-
[switch]$Help
30+
[switch]$Help,
31+
32+
[pscredential]$PSGalleryApiKey
3133
)
3234

3335
$ErrorActionPreference = 'Stop'
@@ -50,7 +52,10 @@ if ($PSCmdlet.ParameterSetName -eq 'Help') {
5052
Format-Table -Property Name, Description, Alias, DependsOn
5153
} else {
5254
Set-BuildEnvironment -Force
53-
54-
Invoke-psake -buildFile $psakeFile -taskList $Task -nologo
55+
$parameters = @{}
56+
if ($PSGalleryApiKey) {
57+
$parameters['galleryApiKey'] = $PSGalleryApiKey
58+
}
59+
Invoke-psake -buildFile $psakeFile -taskList $Task -nologo -parameters $parameters
5560
exit ( [int]( -not $psake.build_success ) )
5661
}

psakeFile.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
properties {
22
$settings = . ([IO.Path]::Combine($PSScriptRoot, 'build.settings.ps1'))
3+
if ($galleryApiKey) {
4+
$settings.PSGalleryApiKey = $galleryApiKey.GetNetworkCredential().password
5+
}
36
}
47

58
task default -depends Test
@@ -59,7 +62,7 @@ task Build -depends Init, Clean {
5962
task Publish -depends Test {
6063
" Publishing version [$($settings.Manifest.ModuleVersion)] to PSGallery..."
6164
if ($settings.PSGalleryApiKey) {
62-
Publish-Module -Path $settings.ModuleOutDir -NuGetApiKey $settings.PSGalleryApiKey -Repository PSGallery
65+
Publish-Module -Path $settings.ModuleOutDir -NuGetApiKey $settings.PSGalleryApiKey
6366
} else {
6467
throw 'Did not find PSGallery API key!'
6568
}

requirements.psd1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
PSDependOptions = @{
33
Target = 'CurrentUser'
44
}
5-
65
BuildHelpers = '2.0.16'
76
Pester = @{
87
MinimumVersion = '5.2.2'

0 commit comments

Comments
 (0)