Skip to content

v2.5.0-beta2

v2.5.0-beta2 #40

Workflow file for this run

name: psgraph-publish
on:
release:
types: [published]
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['9.0.x']
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install PowerShell
uses: PSModule/install-powershell@v1
with:
Version: latest
- name: Ensure release tag exists
id: ensure_tag
run: |
if [ -z "${GITHUB_REF##refs/tags/}" ]; then
echo "Error: Release must have a tag."
exit 1
fi
- name: Install dependencies
run: dotnet restore
- name: Build PowerShell module
run: |
if [ "${{ github.event.release.prerelease }}" = "true" ]; then
dotnet build -c Debug
else
dotnet build -c Release
fi
- name: Run .NET tests
run: dotnet test --verbosity normal
- name: Run Pester tests
shell: pwsh
run: |
Invoke-Pester -Path ./PsGraph.Pester.Tests/
- name: dotnet publish PowerShell module
run: |
if [ "${{ github.event.release.prerelease }}" = "true" ]; then
dotnet publish -c Debug -o "./PSQuickGraph"
else
dotnet publish -c Release -o "./PSQuickGraph"
fi
# --- Manual Version Reminder / Guard ---
- name: Verify manifest version matches release tag (manual update reminder)
if: github.event_name == 'release'
shell: pwsh
run: |
$tag = "${env:GITHUB_REF}" -replace '^refs/tags/',''
$tag = $tag -replace '^v',''
if ($tag -notmatch '^([0-9]+\.[0-9]+\.[0-9]+)(?:-([A-Za-z0-9\-]+))?$') {
Write-Error 'Bad tag'; exit 1
}
$ver = $Matches[1]; $pre = $Matches[2]
$manifest = Join-Path $PWD 'PSQuickGraph/PSQuickGraph.psd1'
$md = Test-ModuleManifest -Path $manifest
$moduleVersion = $md.Version
$manifestPrerelease = $md.PrivateData.PSData.Prerelease
$ok = $true
if ($moduleVersion -ne $ver) {
Write-Host "::error::Manifest ModuleVersion ($moduleVersion) does not match tag version ($ver)."; $ok = $false
}
if ($pre) {
if ($manifestPrerelease -ne $pre) {
Write-Host "::error::Manifest Prerelease ('$manifestPrerelease') does not match tag prerelease ('$pre')."; $ok = $false
}
} else {
if ($manifestPrerelease) {
Write-Host "::warning::Manifest has Prerelease '$manifestPrerelease' but tag is a stable release."; $ok = $false
}
}
if (-not $ok) {
Write-Host '--- Manual Action Required ---'
Write-Host 'Update PSGraph/PSQuickGraph.psd1 with:'
Write-Host " ModuleVersion = '$ver'"
if ($pre) { Write-Host " Prerelease = '$pre'" } else { Write-Host ' (Remove/Comment any Prerelease entry)' }
Write-Host 'Commit the change and recreate the release (or re-run after fixing).'
exit 1
} else {
$suffix = if ($manifestPrerelease) { "-$manifestPrerelease" } else { '' }
Write-Host "Manifest version check passed ($moduleVersion$suffix)."
}
# --- PowerShell Module Versioning ---
- name: Extract version from tag and update module manifest
id: set_version
shell: pwsh
run: |
$tag = "${env:GITHUB_REF}" -replace '^refs/tags/',''
$tag = $tag -replace '^v',''
if ($tag -notmatch '^([0-9]+\.[0-9]+\.[0-9]+)(?:-([A-Za-z0-9\-]+))?$') {
Write-Error 'Bad tag'; exit 1
}
$ver = $Matches[1]; $pre = $Matches[2]
$manifest = Join-Path $PWD 'PSQuickGraph/PSQuickGraph.psd1'
$md = Test-ModuleManifest -Path $manifest
if ($pre) {
Update-ModuleManifest -Path $manifest -ModuleVersion $ver -Prerelease $pre
} else {
Update-ModuleManifest -Path $manifest -ModuleVersion $ver -Prerelease ''
}
"version=$ver" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"prerelease=$pre" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
# --- PowerShell Module Build/Test/Publish ---
- name: Publish PowerShell module to PSGallery
shell: pwsh
run: |
Publish-Module -Path "./PSQuickGraph" -NuGetApiKey ${{ secrets.PS_GALLERY_SECRET }}
# --- NuGet Common Package Build/Publish ---
- name: Build PSGraph.Common (Debug on prerelease, Release on release)
run: |
if [ -n "${{ steps.set_version.outputs.prerelease }}" ]; then
VERSION="${{ steps.set_version.outputs.version }}-${{ steps.set_version.outputs.prerelease }}"
CONFIG=Debug
else
VERSION="${{ steps.set_version.outputs.version }}"
CONFIG=Release
fi
dotnet build PSGraph.Common/PSGraph.Common.csproj \
--configuration $CONFIG \
--no-restore \
-p:PackageVersion="$VERSION" \
-p:Version="$VERSION"
- name: Pack PSGraph.Common (Debug/pre-release on prerelease, Release on release)
shell: bash
run: |
if [ -n "${{ steps.set_version.outputs.prerelease }}" ]; then
VERSION="${{ steps.set_version.outputs.version }}-${{ steps.set_version.outputs.prerelease }}"
CONFIG=Debug
else
VERSION="${{ steps.set_version.outputs.version }}"
CONFIG=Release
fi
dotnet pack PSGraph.Common/PSGraph.Common.csproj \
--configuration $CONFIG \
--no-build \
--output ./nupkg \
-p:PackageVersion="$VERSION" \
-p:Version="$VERSION"
- name: Publish PSGraph.Common to NuGet
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
# --- Commit manifest changes ---
# - name: Commit and push updated manifest
# if: success()
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# git config user.name "github-actions[bot]"
# git config user.email "github-actions[bot]@users.noreply.github.com"
# SOURCE_BRANCH="${{ github.event.release.target_commitish }}"
# if [ -z "$SOURCE_BRANCH" ]; then
# echo "Could not determine source branch. Exiting."
# exit 1
# fi
# if [[ "$SOURCE_BRANCH" =~ ^[0-9a-f]{40}$ ]]; then
# echo "Commitish is a SHA, not a branch name. Aborting."
# exit 1
# fi
# git fetch origin "$SOURCE_BRANCH"
# git switch "$SOURCE_BRANCH"
# git pull origin "$SOURCE_BRANCH"
# git add ./PSQuickGraph/*.psd1
# git commit -m "ci: update module version to ${{ steps.set_version.outputs.version }}" || echo "Nothing to commit"
# git push origin "$SOURCE_BRANCH"