diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 968dc58..edde00b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,39 +3,175 @@ name: psgraph-publish on: release: types: [published] - + workflow_dispatch: jobs: - publish: runs-on: ubuntu-latest strategy: matrix: - dotnet-version: ['9.0.x' ] + dotnet-version: ['9.0.x'] steps: - - uses: actions/checkout@v3 + - 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 + + # --- PowerShell Module Versioning --- + - 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: Extract version from tag and update module manifest + id: set_version + shell: pwsh + run: | + $tag = "${env:GITHUB_REF}" -replace '^refs/tags/', '' + if (-not $tag) { + Write-Error "Tag not found. Failing." + exit 1 + } + $tag = $tag -replace '^v', '' + if ($tag -match '^([0-9]+\.[0-9]+\.[0-9]+)(?:-([A-Za-z0-9\-]+))?$') { + $version = $matches[1] + $prerelease = $matches[2] + } else { + Write-Error "Tag format invalid. Should be X.Y.Z or X.Y.Z-suffix" + exit 1 + } + if ($prerelease -and ($prerelease -notmatch '^(?:-)?[a-zA-Z0-9\-]+$')) { + Write-Error "Prerelease string '$prerelease' contains invalid characters. Only a-z, A-Z, 0-9, and hyphen (-) at the beginning are allowed." + exit 1 + } + $psd1 = Get-Item ./PSGraph/PSQuickGraph.psd1 + if (-not $psd1) { + Write-Error "Module manifest (.psd1) not found!" + exit 1 + } + $content = Get-Content $psd1.FullName + $versionPattern = 'ModuleVersion\s*=\s*''[^'']*''' + $content = $content -replace $versionPattern, "ModuleVersion = '$version'" + if ($prerelease) { + $content = $content -replace '^\s*#\s*Prerelease\s*=\s*''[^'']*''', "Prerelease = '$prerelease'" + } + Set-Content -Path $psd1.FullName -Value $content + "version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append + "prerelease=$prerelease" | Out-File -FilePath $env:GITHUB_OUTPUT -Append + + # --- PowerShell Module Build/Test/Publish --- - name: Install dependencies run: dotnet restore - - name: Build - run: dotnet build - - name: Test + + - 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: Pester tests shell: pwsh run: | Invoke-Pester -Path ./PsGraph.Pester.Tests/ + - name: dotnet publish run: dotnet publish -o "./PSQuickGraph" + - name: psgallery publish run: | - $env:GITHUB_WORKSPACE - Publish-Module -Path "./PSQuickGraph" -NuGetApiKey ${{ secrets.PS_GALLERY_SECRET }} + 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 + + - name: Publish PowerShell module to PSGallery shell: pwsh - + run: | + Publish-Module -Path "./PSQuickGraph" -NuGetApiKey ${{ secrets.PS_GALLERY_SECRET }} + # --- NuGet Common Package Build/Publish --- + - name: Set Version Suffix for Pre-release (Common) + if: github.event.release.prerelease == true + run: | + echo "VERSION_SUFFIX=${{ steps.set_version.outputs.prerelease }}" >> $GITHUB_ENV + + - name: Build PSGraph.Common (Debug on prerelease, Release on release) + run: | + if [ "${{ github.event.release.prerelease }}" = "true" ]; then + dotnet build PSGraph.Common/PSGraph.Common.csproj --configuration Debug --no-restore + else + dotnet build PSGraph.Common/PSGraph.Common.csproj --configuration Release --no-restore + fi + + - name: Pack PSGraph.Common (Debug/pre-release on prerelease, Release on release) + shell: bash + run: | + if [ "${{ github.event.release.prerelease }}" = "true" ]; then + VERSION="${{ steps.set_version.outputs.version }}-${{ steps.set_version.outputs.prerelease }}" + dotnet pack PSGraph.Common/PSGraph.Common.csproj \ + --configuration Debug \ + --no-build \ + --output ./nupkg \ + /p:PackageVersion="$VERSION" + else + VERSION="${{ steps.set_version.outputs.version }}" + dotnet pack PSGraph.Common/PSGraph.Common.csproj \ + --configuration Release \ + --no-build \ + --output ./nupkg \ + /p:PackageVersion="$VERSION" + fi + + - 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" \ No newline at end of file diff --git a/.github/workflows/publishCommon.yml b/.github/workflows/publishCommon.yml new file mode 100644 index 0000000..369aac2 --- /dev/null +++ b/.github/workflows/publishCommon.yml @@ -0,0 +1,54 @@ +name: Publish PSGraph.Common NuGet Package + +on: + workflow_dispatch: + +jobs: + build-and-publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9.0.x' + + - name: Restore dependencies + run: dotnet restore PSGraph.Common/PSGraph.Common.csproj + + - name: Set Version Suffix for Pre-release + if: github.ref == 'refs/heads/dev' + run: | + VERSION_SUFFIX="beta-$(date +%Y%m%d%H%M%S)" + echo "VERSION_SUFFIX=$VERSION_SUFFIX" >> $GITHUB_ENV + + - name: Build (Debug on dev, Release on main) + run: | + if [ "${{ github.ref }}" = "refs/heads/dev" ]; then + dotnet build PSGraph.Common/PSGraph.Common.csproj --configuration Debug --no-restore + else + dotnet build PSGraph.Common/PSGraph.Common.csproj --configuration Release --no-restore + fi + + - name: Pack (Debug/pre-release on dev, Release on main) + run: | + if [ "${{ github.ref }}" = "refs/heads/dev" ]; then + dotnet pack PSGraph.Common/PSGraph.Common.csproj \ + --configuration Debug \ + --no-build \ + --output ./nupkg \ + --version-suffix $VERSION_SUFFIX + else + dotnet pack PSGraph.Common/PSGraph.Common.csproj \ + --configuration Release \ + --no-build \ + --output ./nupkg + fi + + - name: Publish 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 }} \ No newline at end of file diff --git a/PSGraph.Common/PSGraph.Common.csproj b/PSGraph.Common/PSGraph.Common.csproj index cdf6839..68e9f09 100644 --- a/PSGraph.Common/PSGraph.Common.csproj +++ b/PSGraph.Common/PSGraph.Common.csproj @@ -4,7 +4,7 @@ net9.0 enable enable - 1.0.1 + 1.0.3 Andrey Vernigora PSGraph.Common Common types of PSGraph module diff --git a/PSQuickGraph/PSQuickGraph.psd1 b/PSQuickGraph/PSQuickGraph.psd1 new file mode 100644 index 0000000..b64a33d --- /dev/null +++ b/PSQuickGraph/PSQuickGraph.psd1 @@ -0,0 +1,123 @@ +# +# Module manifest for module 'PSGraph' +# +# Generated by: Andrei +# +# Generated on: 07.04.2017 +# + +@{ + +# Script module or binary module file associated with this manifest. +RootModule = "PSGraph.dll" + +# Version number of this module. +ModuleVersion = '2.3.1' + +# Supported PSEditions +# CompatiblePSEditions = @() + +# ID used to uniquely identify this module +GUID = '4bd5a906-8e03-497e-80eb-209e71caae45' + +# Author of this module +Author = 'Andrey Vernigora' + +# Company or vendor of this module +CompanyName = 'Unknown' + +# Copyright statement for this module +Copyright = '(c) 2017 Andrei. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'This module is a wrapper for QuickGraph library.' + +# Minimum version of the Windows PowerShell engine required by this module +# PowerShellVersion = '' + +# Name of the Windows PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the Windows PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# CLRVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @("QuickGraph.dll", "QuickGraph.Data.dll", "QuickGraph.Graphviz.dll", "QuickGraph.Serialization.dll", "GraphSharp.dll", "GraphSharp.Controls.dll") +RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = @() + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = @("*") + +# Variables to export from this module +VariablesToExport = '*' + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = @() + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ +Prerelease = 'beta6' + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/eosfor/PSGraph' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +}