Skip to content

Commit

Permalink
Publish via GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
brianary committed Mar 12, 2022
1 parent bc7b482 commit 6ac604b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 46 deletions.
55 changes: 46 additions & 9 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
name: .NET Core

on: [push]

on: push
jobs:
build:

ci-linux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.2.108
- name: Build with dotnet
run: dotnet build --configuration Release
dotnet-version: 6.0.x
- name: Build
run: dotnet build -c Release
- name: Test
run: dotnet publish -t:test
ci-windows:
runs-on: windows-latest
env:
gallerykey: ${{ secrets.gallerykey }}
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 2
- name: Module update check
id: is_module_update_test
shell: pwsh
run: |
Write-Host "::set-output name=is_module_update::$(@(git diff --name-only HEAD~ HEAD -- "$(Resolve-Path .\src\*\*.psd1)").Count -gt 0)"
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Build
run: dotnet build -c Release
- name: Test
run: dotnet publish -t:test
- name: Publish
if: success() && env.gallerykey && steps.is_module_update_test.outputs.is_module_update == 'True'
shell: pwsh
run: |
dotnet publish -c Release
$MSBuildProjectName = [io.path]::GetFileNameWithoutExtension("$(Resolve-Path ./src/*/*.fsproj)")
$env:PSModulePath -split ';' |
ForEach-Object {"$_/$MSBuildProjectName"} |
Where-Object {Test-Path $_ -Type Container} |
Remove-Item -Recurse -Force
Push-Location ./src/*/bin/Release/*/publish
Import-LocalizedData Module -FileName $MSBuildProjectName -BaseDirectory "$PWD"
$Version = $Module.ModuleVersion
$InstallPath = "$env:UserProfile/Documents/PowerShell/Modules/$MSBuildProjectName/$Version"
if(!(Test-Path $InstallPath -Type Container)) {mkdir $InstallPath}
Copy-Item * -Destination $InstallPath
Pop-Location
Publish-Module -Name $MSBuildProjectName -NuGetApiKey $env:gallerykey
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pretendpoint
============

<!-- To publish to PowerShell Gallery: dotnet build -t:PublishModule -c Release -->
<!-- To publish to PowerShell Gallery, commit an update to the .psd1 file -->
<img src="Pretendpoint.svg" alt="Pretendpoint icon" align="right" />

[![PowerShell Gallery Version](https://img.shields.io/powershellgallery/v/Pretendpoint)](https://www.powershellgallery.com/packages/Pretendpoint/)
Expand Down
18 changes: 0 additions & 18 deletions Set-ApiKey.ps1

This file was deleted.

18 changes: 0 additions & 18 deletions src/Pretendpoint/Pretendpoint.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,4 @@
<PSModulePath Include="$(PSModulePath)" Exclude="C:\Program Files\**;C:\Windows\**;C:\ProgramData\chocolatey\**" />
</ItemGroup>

<Target Name="PublishModule" DependsOnTargets="Publish" Condition="'$(Configuration)' == 'Release'">
<RemoveDir Directories="@(PSModulePath-&gt;'%(FullPath)\$(MSBuildProjectName)')" />
<Copy SourceFiles="$(OutputPath)\publish\FSharp.Core.dll" DestinationFolder="$(OutputPath)" />
<ItemGroup><ModuleFiles Include="$(OutputPath)\*" /></ItemGroup>
<Copy SourceFiles="@(ModuleFiles)" DestinationFolder="@(PSModulePath-&gt;'%(FullPath)\$(MSBuildProjectName)\$(Version)')" />
<Exec Command='pwsh -noni -nop -c "[bool](Get-SecretInfo $(MSBuildProjectName) -Vault PowerShellGallery)"'
ConsoleToMSBuild="true" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true">
<Output TaskParameter="ConsoleOutput" PropertyName="HasApiKey" />
</Exec>
<Error Text="To publish, first run: .\Set-ApiKey.ps1" Condition="!$(HasApiKey)" />
<Exec Command='pwsh -nop -c "(New-Object PSCredential _,(Get-Secret $(MSBuildProjectName) -Vault PowerShellGallery)).GetNetworkCredential().Password"'
ConsoleToMSBuild="true" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" Condition="$(HasApiKey)">
<Output TaskParameter="ConsoleOutput" PropertyName="ApiKey" />
</Exec>
<Exec Command='pwsh -noni -nop -c "Import-Module $(MSBuildProjectName); Publish-Module -Name $(MSBuildProjectName) -NuGetApiKey $(ApiKey)"'
IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" Condition="$(HasApiKey)" />
</Target>

</Project>

0 comments on commit 6ac604b

Please sign in to comment.