psgraph-publish #11
Workflow file for this run
This file contains hidden or 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
| 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 # требуется для корректной работы с git и ветками | |
| - 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 | |
| } | |
| # Удаляем префикс v, если он есть | |
| $tag = $tag -replace '^v', '' | |
| # Разделяем версию и prerelease-суффикс (если есть) | |
| 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 | |
| } | |
| $psd1 = Get-Item ./PSGraph/PSQuickGraph.psd1 | |
| if (-not $psd1) { | |
| Write-Error "Module manifest (.psd1) not found!" | |
| exit 1 | |
| } | |
| $content = Get-Content $psd1.FullName | |
| # Обновляем ModuleVersion | |
| $versionPattern = 'ModuleVersion\s*=\s*''[^'']*''' | |
| $content = $content -replace $versionPattern, "ModuleVersion = '$version'" | |
| # Обработка Prerelease | |
| if ($prerelease) { | |
| # Раскомментируем и задаём значение | |
| $content = $content -replace '^\s*#\s*Prerelease\s*=\s*''[^'']*''', "Prerelease = '$prerelease'" | |
| } else { | |
| # Оставляем строку закомментированной (ничего не делаем) | |
| } | |
| Set-Content -Path $psd1.FullName -Value $content | |
| "version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append | |
| - name: Setup .NET Core SDK ${{ matrix.dotnet-version }} | |
| uses: actions/setup-dotnet@v3 | |
| with: | |
| dotnet-version: ${{ matrix.dotnet-version }} | |
| - name: Install dependencies | |
| run: dotnet restore | |
| - name: Build | |
| 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 | |
| run: | | |
| if [ "${{ github.event.release.prerelease }}" = "true" ]; then | |
| dotnet publish -c Debug -o "./PSQuickGraph" | |
| else | |
| dotnet publish -c Release -o "./PSQuickGraph" | |
| fi | |
| - name: Publish to PSGallery | |
| shell: pwsh | |
| run: | | |
| Publish-Module -Path "./PSQuickGraph" -NuGetApiKey ${{ secrets.PS_GALLERY_SECRET }} | |
| - 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" |