Skip to content

Commit 3b0b5eb

Browse files
author
Jani Giannoudis
committed
Add GitHub Actions workflows (release, pages)
1 parent 8d867b3 commit 3b0b5eb

2 files changed

Lines changed: 247 additions & 0 deletions

File tree

.github/workflows/pages.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Deploy DocFX to GitHub Pages
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: pages
15+
cancel-in-progress: false
16+
17+
jobs:
18+
deploy:
19+
runs-on: ubuntu-latest
20+
environment:
21+
name: github-pages
22+
url: ${{ steps.deployment.outputs.page_url }}
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v5
26+
27+
- name: Setup .NET
28+
uses: actions/setup-dotnet@v5
29+
with:
30+
dotnet-version: '10.0.x'
31+
dotnet-quality: 'preview'
32+
33+
- name: Configure GitHub Packages source
34+
run: |
35+
dotnet nuget add source \
36+
"https://nuget.pkg.github.com/Payroll-Engine/index.json" \
37+
--name github --username github-actions \
38+
--password ${{ secrets.PAT_DISPATCH }} \
39+
--store-password-in-clear-text
40+
41+
- name: Build
42+
run: dotnet publish Tools/PayrollEngine.Mcp.Tools.csproj -c Release -o publish
43+
44+
- name: Install DocFX
45+
run: dotnet tool install -g docfx
46+
47+
- name: Build DocFX
48+
run: cd docfx && docfx docfx.json
49+
50+
- name: Upload Pages artifact
51+
uses: actions/upload-pages-artifact@v3
52+
with:
53+
path: docfx/_site
54+
55+
- name: Deploy to GitHub Pages
56+
id: deployment
57+
uses: actions/deploy-pages@v4

.github/workflows/release.yml

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
name: Build & Publish NuGet
2+
3+
on:
4+
repository_dispatch:
5+
types: [release]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Package version (e.g. 1.5.0 or 1.5.0-beta.1)'
10+
required: true
11+
dry_run:
12+
description: 'Dry run (draft release, no commit, no latest tag)'
13+
type: boolean
14+
default: false
15+
16+
permissions:
17+
contents: write
18+
packages: write
19+
20+
env:
21+
DOTNET_VERSION: '10.0.x'
22+
23+
jobs:
24+
build-and-publish:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Determine parameters
28+
id: params
29+
run: |
30+
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
31+
VERSION="${{ github.event.client_payload.version }}"
32+
IS_PRERELEASE="${{ github.event.client_payload.is_prerelease }}"
33+
DRY_RUN="${{ github.event.client_payload.dry_run }}"
34+
else
35+
VERSION="${{ inputs.version }}"
36+
DRY_RUN="${{ inputs.dry_run }}"
37+
if [[ "$VERSION" == *-* ]]; then
38+
IS_PRERELEASE="true"
39+
else
40+
IS_PRERELEASE="false"
41+
fi
42+
fi
43+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
44+
echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT
45+
echo "dry_run=${DRY_RUN}" >> $GITHUB_OUTPUT
46+
if [ "${DRY_RUN}" = "true" ]; then
47+
echo "make_draft=true" >> $GITHUB_OUTPUT
48+
else
49+
echo "make_draft=false" >> $GITHUB_OUTPUT
50+
fi
51+
52+
- uses: actions/checkout@v4
53+
with:
54+
token: ${{ secrets.PAT_DISPATCH }}
55+
fetch-depth: 0
56+
57+
# ── Version Guard ────────────────────────────────
58+
- name: Check if version already exists
59+
if: steps.params.outputs.dry_run != 'true'
60+
uses: actions/github-script@v7
61+
with:
62+
github-token: ${{ secrets.PAT_DISPATCH }}
63+
script: |
64+
const version = '${{ steps.params.outputs.version }}';
65+
const tag = `v${version}`;
66+
const owner = context.repo.owner;
67+
const repo = context.repo.repo;
68+
const errors = [];
69+
try {
70+
await github.rest.git.getRef({ owner, repo, ref: `tags/${tag}` });
71+
errors.push(`Git tag '${tag}' already exists`);
72+
} catch (e) { if (e.status !== 404) throw e; }
73+
try {
74+
await github.rest.repos.getReleaseByTag({ owner, repo, tag });
75+
errors.push(`GitHub Release '${tag}' already exists`);
76+
} catch (e) { if (e.status !== 404) throw e; }
77+
try {
78+
const packages = await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({
79+
package_type: 'nuget', package_name: repo, org: owner
80+
});
81+
if (packages.data.some(p => p.name === version))
82+
errors.push(`NuGet package version '${version}' already exists on GitHub Packages`);
83+
} catch (e) {
84+
if (e.status === 404) console.log(`✅ No package found yet (first publish)`);
85+
else console.warn(`⚠️ Could not check packages: ${e.message}`);
86+
}
87+
if (errors.length > 0)
88+
core.setFailed(`❌ Version guard failed:\n${errors.map(e => ` - ${e}`).join('\n')}`);
89+
else
90+
console.log('\n✅ All version checks passed');
91+
92+
# ── Update Directory.Build.props ─────────────────
93+
- name: Read current version
94+
id: current
95+
run: |
96+
CURRENT=$(grep -oP '(?<=<Version>)[^<]+' Directory.Build.props)
97+
echo "version=${CURRENT}" >> $GITHUB_OUTPUT
98+
99+
- name: Update Directory.Build.props
100+
run: |
101+
VERSION="${{ steps.params.outputs.version }}"
102+
CURRENT="${{ steps.current.outputs.version }}"
103+
if [ "${VERSION}" = "${CURRENT}" ]; then
104+
echo "ℹ️ Version already set to ${VERSION}"
105+
else
106+
sed -i "s|<Version>${CURRENT}</Version>|<Version>${VERSION}</Version>|" Directory.Build.props
107+
echo "✅ Updated: ${CURRENT} → ${VERSION}"
108+
fi
109+
grep '<Version>' Directory.Build.props
110+
111+
- name: Commit version bump
112+
if: steps.params.outputs.dry_run != 'true'
113+
run: |
114+
VERSION="${{ steps.params.outputs.version }}"
115+
git config user.name "github-actions[bot]"
116+
git config user.email "github-actions[bot]@users.noreply.github.com"
117+
git add Directory.Build.props
118+
if git diff --cached --quiet; then
119+
echo "ℹ️ No changes to commit"
120+
else
121+
git commit -m "release: v${VERSION}"
122+
git push
123+
fi
124+
125+
# ── Build ────────────────────────────────────────
126+
- name: Update PE dependency versions
127+
run: |
128+
VERSION="${{ steps.params.outputs.version }}"
129+
find . -name "*.csproj" | xargs sed -i -E \
130+
"s|(<PackageReference Include=\"PayrollEngine\.[^\"]*\" Version=\")[^\"]*\"|\1${VERSION}\"|g"
131+
echo "✅ PE dependencies updated to ${VERSION}"
132+
grep -rh 'PayrollEngine\.' --include="*.csproj" | grep 'Version=' || true
133+
134+
- name: Setup .NET
135+
uses: actions/setup-dotnet@v4
136+
with:
137+
dotnet-version: ${{ env.DOTNET_VERSION }}
138+
139+
- name: Configure GitHub Packages source
140+
run: |
141+
dotnet nuget add source \
142+
"https://nuget.pkg.github.com/Payroll-Engine/index.json" \
143+
--name github \
144+
--username github-actions \
145+
--password ${{ secrets.PAT_DISPATCH }} \
146+
--store-password-in-clear-text
147+
148+
- name: Restore
149+
run: dotnet restore
150+
151+
- name: Build
152+
run: dotnet build --configuration Release --no-restore
153+
154+
- name: Test
155+
run: dotnet test --configuration Release --no-build --verbosity normal
156+
157+
- name: Pack
158+
run: dotnet pack --configuration Release --no-build --output ./nupkgs
159+
160+
# ── Publish ──────────────────────────────────────
161+
- name: Publish to GitHub Packages
162+
run: |
163+
dotnet nuget push ./nupkgs/*.nupkg \
164+
--source "https://nuget.pkg.github.com/Payroll-Engine/index.json" \
165+
--api-key ${{ secrets.GITHUB_TOKEN }} \
166+
--skip-duplicate
167+
168+
- name: Create GitHub Release
169+
uses: softprops/action-gh-release@v2
170+
with:
171+
tag_name: v${{ steps.params.outputs.version }}
172+
name: v${{ steps.params.outputs.version }}
173+
prerelease: ${{ steps.params.outputs.is_prerelease }}
174+
draft: ${{ steps.params.outputs.make_draft }}
175+
generate_release_notes: true
176+
files: ./nupkgs/*.nupkg
177+
178+
- name: Notify orchestrator
179+
if: github.event_name == 'repository_dispatch'
180+
uses: peter-evans/repository-dispatch@v3
181+
with:
182+
token: ${{ secrets.PAT_DISPATCH }}
183+
repository: Payroll-Engine/PayrollEngine
184+
event-type: lib-published
185+
client-payload: >-
186+
{
187+
"repo": "${{ github.repository }}",
188+
"version": "${{ steps.params.outputs.version }}",
189+
"wave": "${{ github.event.client_payload.wave }}"
190+
}

0 commit comments

Comments
 (0)