Build, Release, and Publish #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a basic workflow to help you get started with Actions | |
name: Build, Release, and Publish | |
# Controls when the workflow will run | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'The next version of the module - 0.0.0.0 for prerelease, 0.0.0 for regular' | |
required: true | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "build" | |
build: | |
# The type of runner that the job will run on | |
runs-on: windows-latest | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v3 | |
# Runs a set of commands using the runners shell | |
- name: Change the version | |
run: | | |
# get the manifest | |
$newVersionString = "${{github.event.inputs.version}}" | |
$newVersion = [Version]::new($newVersionString) | |
# determine if this is a Release or Pre-Release | |
if ($newVersion.Revision -eq -1) | |
{ | |
#regular, change the version and remove the pre-release block from the manifest | |
Write-Output "Performing regular build..." | |
(Get-Content -Path '.\CareLink.psd1') -replace '1.0', $newVersionString | Set-Content -Path '.\CareLink.psd1' | |
} | |
else | |
{ | |
#alpha, change the version and update the pre-release block from the manifest | |
Write-Output "Performing pre-release build..." | |
$alphaVersion = "-" + "alpha" + $newVersion.Revision.ToString() | |
$newVersionString = $newVersion.Major.ToString() + "." + $newVersion.Minor.ToString() + "." + $newVersion.Build.ToString() | |
(Get-Content -Path '.\CareLink.psd1') -replace '1.0', $newVersionString | Set-Content -Path '.\CareLink.psd1' | |
#prep the PrivateData section, then set the pre-release version | |
Update-ModuleManifest -Path ".\CareLink.psd1" | |
Update-ModuleManifest -Path ".\CareLink.psd1" -Prerelease "$alphaVersion" | |
} | |
Write-Output "Updated Manifest---" | |
# Test the module with updated version | |
- name: Test the module | |
run: Test-ModuleManifest '.\CareLink.psd1' | |
# Runs a set of commands using the runners shell | |
- name: Copy the required files to a temp directory | |
run: | | |
New-Item -Path "C:\Users\runneradmin\Documents\PowerShell\Modules\CareLink" -ItemType Directory | |
Copy-Item CareLink.psd1 -Destination "C:\Users\runneradmin\Documents\PowerShell\Modules\CareLink" | |
Copy-Item CareLink.psm1 -Destination "C:\Users\runneradmin\Documents\PowerShell\Modules\CareLink" | |
# publish the build artifact up to GitHub | |
- name: publish the artifact (folder) back to GitHub | |
uses: actions/upload-artifact@master | |
with: | |
name: CareLink | |
path: C:\Users\runneradmin\Documents\PowerShell\Modules\CareLink\ | |
# publish to PowerShell Gallery | |
- name: publish to PowerShell Gallery | |
run: | | |
Write-Output "Publishing to PowerShell Gallery" | |
Import-Module "C:\Users\runneradmin\Documents\PowerShell\Modules\CareLink\CareLink.psd1" | |
Get-Module CareLink | |
Publish-Module -Name "CareLink" -NuGetApiKey ${{secrets.CARELINKPWSHGALLERYKEY}} -LicenseUri "https://github.com/AdhocAdam/CareLink/blob/main/LICENSE" |