Skip to content

Commit f19c804

Browse files
committed
new publish pipeline
1 parent 6d21989 commit f19c804

1 file changed

Lines changed: 90 additions & 12 deletions

File tree

.github/workflows/publish.yml

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,117 @@ name: psgraph-publish
33
on:
44
release:
55
types: [published]
6-
76
workflow_dispatch:
87

98
jobs:
10-
119
publish:
1210
runs-on: ubuntu-latest
1311
strategy:
1412
matrix:
15-
dotnet-version: ['9.0.x' ]
13+
dotnet-version: ['9.0.x']
1614

1715
steps:
18-
- uses: actions/checkout@v3
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0 # требуется для корректной работы с git и ветками
20+
21+
- name: Ensure release tag exists
22+
id: ensure_tag
23+
run: |
24+
if [ -z "${GITHUB_REF##refs/tags/}" ]; then
25+
echo "Error: Release must have a tag."
26+
exit 1
27+
fi
28+
29+
- name: Extract version from tag and update module manifest
30+
id: set_version
31+
shell: pwsh
32+
run: |
33+
$tag = "${env:GITHUB_REF}" -replace '^refs/tags/', ''
34+
if (-not $tag) {
35+
Write-Error "Tag not found. Failing."
36+
exit 1
37+
}
38+
39+
$isPrerelease = "${{ github.event.release.prerelease }}" -eq "true"
40+
$dateSuffix = Get-Date -Format "yyyyMMdd-HHmm"
41+
$newVersion = if ($isPrerelease) { "$tag-prerelease-$dateSuffix" } else { $tag }
42+
43+
$psd1 = Get-ChildItem -Path ./PSQuickGraph -Filter *.psd1 | Select-Object -First 1
44+
if (-not $psd1) {
45+
Write-Error "Module manifest (.psd1) not found!"
46+
exit 1
47+
}
48+
49+
$content = Get-Content $psd1.FullName
50+
$versionPattern = 'ModuleVersion\s*=\s*''[^'']*'''
51+
$newContent = $content -replace $versionPattern, "ModuleVersion = '$newVersion'"
52+
Set-Content -Path $psd1.FullName -Value $newContent
53+
54+
"version=$newVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
55+
1956
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
2057
uses: actions/setup-dotnet@v3
2158
with:
2259
dotnet-version: ${{ matrix.dotnet-version }}
60+
2361
- name: Install dependencies
2462
run: dotnet restore
63+
2564
- name: Build
26-
run: dotnet build
27-
- name: Test
65+
run: |
66+
if [ "${{ github.event.release.prerelease }}" = "true" ]; then
67+
dotnet build -c Debug
68+
else
69+
dotnet build -c Release
70+
fi
71+
72+
- name: Run .NET tests
2873
run: dotnet test --verbosity normal
29-
- name: Pester tests
74+
75+
- name: Run Pester tests
3076
shell: pwsh
3177
run: |
3278
Invoke-Pester -Path ./PsGraph.Pester.Tests/
79+
3380
- name: dotnet publish
34-
run: dotnet publish -o "./PSQuickGraph"
35-
- name: psgallery publish
3681
run: |
37-
$env:GITHUB_WORKSPACE
38-
Publish-Module -Path "./PSQuickGraph" -NuGetApiKey ${{ secrets.PS_GALLERY_SECRET }}
82+
if [ "${{ github.event.release.prerelease }}" = "true" ]; then
83+
dotnet publish -c Debug -o "./PSQuickGraph"
84+
else
85+
dotnet publish -c Release -o "./PSQuickGraph"
86+
fi
87+
88+
- name: Publish to PSGallery
3989
shell: pwsh
40-
90+
run: |
91+
Publish-Module -Path "./PSQuickGraph" -NuGetApiKey ${{ secrets.PS_GALLERY_SECRET }}
92+
93+
- name: Commit and push updated manifest
94+
if: success()
95+
env:
96+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
run: |
98+
git config user.name "github-actions[bot]"
99+
git config user.email "github-actions[bot]@users.noreply.github.com"
100+
101+
# Получаем исходную ветку из события релиза
102+
SOURCE_BRANCH="${{ github.event.release.target_commitish }}"
103+
104+
if [ -z "$SOURCE_BRANCH" ]; then
105+
echo "Could not determine source branch. Exiting."
106+
exit 1
107+
fi
108+
109+
if [[ "$SOURCE_BRANCH" =~ ^[0-9a-f]{40}$ ]]; then
110+
echo "Commitish is a SHA, not a branch name. Aborting."
111+
exit 1
112+
fi
41113
114+
git fetch origin "$SOURCE_BRANCH"
115+
git switch "$SOURCE_BRANCH"
116+
git pull origin "$SOURCE_BRANCH"
117+
git add ./PSQuickGraph/*.psd1
118+
git commit -m "ci: update module version to ${{ steps.set_version.outputs.version }}" || echo "Nothing to commit"
119+
git push origin "$SOURCE_BRANCH"

0 commit comments

Comments
 (0)