|
1 | | -name: PowerShell module deployment |
| 1 | +name: Publish module to PowerShell Gallery |
2 | 2 | on: |
3 | 3 | workflow_run: |
4 | 4 | workflows: [".NET build and test"] |
5 | 5 | types: [completed] |
6 | 6 | branches: [main] |
7 | | -defaults: |
8 | | - run: |
9 | | - shell: pwsh |
10 | 7 | jobs: |
11 | | - setup: |
12 | | - name: Setup and confirm module change |
13 | | - runs-on: windows-latest |
14 | | - outputs: |
15 | | - psd1_changed: ${{ steps.has_psd1_changed.outputs.psd1_changed }} |
16 | | - steps: |
17 | | - - name: Checkout |
18 | | - uses: actions/checkout@v4 |
19 | | - with: |
20 | | - fetch-depth: 2 |
21 | | - - name: Module update check |
22 | | - id: has_psd1_changed |
23 | | - continue-on-error: true |
24 | | - run: | |
25 | | - $change = @(git diff --name-only HEAD~ HEAD -- (Resolve-Path .\src\*\*.psd1)).Count |
26 | | - "psd1_changed=$( $change ? $true : $null )" >> $env:GITHUB_OUTPUT |
27 | | - Get-Content $env:GITHUB_OUTPUT -Raw |
28 | | - - name: Try changed files approach |
29 | | - id: try-psd1-changed |
30 | | - uses: tj-actions/changed-files@v45 |
31 | | - with: |
32 | | - files: src/*/*.psd1 |
33 | | - - name: Check changed files output |
34 | | - env: |
35 | | - try_psd1_has_changed: ${{ steps.try-psd1-changed.outputs.any_changed }} |
36 | | - run: | |
37 | | - "changed? $env:try_psd1_has_changed" |
38 | | - - name: Did change |
39 | | - if: ${{ steps.try-psd1-changed.outputs.any_changed == 'true' }} |
40 | | - run: | |
41 | | - "Changed!" |
42 | | - - name: Did not change |
43 | | - if: ${{ steps.try-psd1-changed.outputs.any_changed != 'true' }} |
44 | | - run: | |
45 | | - "Did not change." |
46 | 8 | publish: |
47 | 9 | name: Publish to PowerShell Gallery |
48 | 10 | runs-on: windows-latest |
49 | | - needs: setup |
50 | | - if: ${{ needs.setup.outputs.psd1_changed }}e |
51 | | - env: |
52 | | - gallerykey: ${{ secrets.gallerykey }} |
53 | 11 | steps: |
54 | | - - name: Checkout |
55 | | - uses: actions/checkout@v4 |
56 | | - - name: Build |
57 | | - if: success() && env.gallerykey |
58 | | - run: dotnet build -c Release |
59 | | - - name: Publish |
60 | | - if: success() && env.gallerykey |
61 | | - run: | |
62 | | - #Requires -Version 7 |
63 | | - dotnet publish -c Release |
64 | | - $MSBuildProjectName = Resolve-Path src/*/*.fsproj |Split-Path -LeafBase |
65 | | - Join-Path ($env:PSModulePath -split ';') $MSBuildProjectName | |
66 | | - Where-Object {Test-Path $_ -Type Container} | |
67 | | - Remove-Item -Recurse -Force |
68 | | - Push-Location ./src/*/bin/Release/*/publish |
69 | | - Import-LocalizedData Module -FileName $MSBuildProjectName -BaseDirectory "$PWD" |
70 | | - $Version = $Module.ModuleVersion |
71 | | - $InstallPath = "$env:UserProfile/Documents/PowerShell/Modules/$MSBuildProjectName/$Version" |
72 | | - if(!(Test-Path $InstallPath -Type Container)) {mkdir $InstallPath} |
73 | | - Copy-Item * -Destination $InstallPath |
74 | | - Pop-Location |
75 | | - Publish-Module -Name $MSBuildProjectName -NuGetApiKey $env:gallerykey |
| 12 | + - name: Publish module |
| 13 | + uses: brianary/powershell-gallery-publish@v1 |
| 14 | + with: |
| 15 | + gallery-key: ${{ secrets.gallerykey }} |
0 commit comments