Skip to content

Commit 30eea0c

Browse files
authored
Initial commit
0 parents  commit 30eea0c

File tree

13 files changed

+853
-0
lines changed

13 files changed

+853
-0
lines changed

.github/workflows/ci.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: CI (Build, Test, Alpha Publish)
2+
3+
on:
4+
pull_request:
5+
branches: ["**"]
6+
push:
7+
branches: ["**"]
8+
tags-ignore: ["v*"]
9+
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
jobs:
15+
build-test-pack:
16+
runs-on: ubuntu-latest
17+
env:
18+
working-directory: ${{ github.workspace }}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0 # GitVersion needs full history / tags
24+
25+
- name: Setup .NET
26+
uses: actions/setup-dotnet@v4
27+
with:
28+
dotnet-version: 9.0.x
29+
30+
- name: Install GitVersion
31+
uses: gittools/actions/gitversion/setup@v0.9.15
32+
with:
33+
versionSpec: 5.x
34+
35+
- name: Determine Version
36+
id: gitversion
37+
uses: gittools/actions/gitversion/execute@v0.9.15
38+
with:
39+
useConfigFile: true
40+
41+
- name: Display Version
42+
run: |
43+
echo "NuGetVersion: ${{ steps.gitversion.outputs.NuGetVersionV2 }}"
44+
echo "PreReleaseTag: ${{ steps.gitversion.outputs.PreReleaseTag }}"
45+
46+
- name: Restore
47+
run: dotnet restore
48+
working-directory: '${{ env.working-directory }}'
49+
50+
- name: Build
51+
run: dotnet build --configuration Release --no-restore
52+
working-directory: '${{ env.working-directory }}'
53+
54+
- name: Test
55+
run: dotnet test --configuration Release --no-build --collect:"XPlat Code Coverage"
56+
working-directory: '${{ env.working-directory }}'
57+
58+
- name: Pack (Pre-release or Alpha)
59+
if: ${{ steps.gitversion.outputs.PreReleaseTag != '' && github.ref_type == 'branch' && github.ref != 'refs/heads/main' }}
60+
run: |
61+
dotnet pack src/MyLibrary/MyLibrary.csproj \
62+
-c Release -o artifacts \
63+
/p:PackageVersion=${{ steps.gitversion.outputs.NuGetVersionV2 }}
64+
65+
- name: Add GitHub Packages Source
66+
if: ${{ steps.gitversion.outputs.PreReleaseTag != '' && github.ref_type == 'branch' && github.ref != 'refs/heads/main' }}
67+
run: |
68+
dotnet nuget add source \
69+
--username $GITHUB_ACTOR \
70+
--password ${{ secrets.GITHUB_TOKEN }} \
71+
--store-password-in-clear-text \
72+
--name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
73+
74+
- name: Publish Alpha to GitHub Packages
75+
if: ${{ steps.gitversion.outputs.PreReleaseTag != '' && github.ref_type == 'branch' && github.ref != 'refs/heads/main' }}
76+
run: dotnet nuget push "artifacts/*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" --skip-duplicate

.github/workflows/release.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Release (Stable)
2+
3+
on:
4+
push:
5+
branches:
6+
- release/**
7+
- release
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
packages: write
13+
14+
jobs:
15+
release:
16+
runs-on: ubuntu-latest
17+
env:
18+
working-directory: ${{ github.workspace }}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Setup .NET
26+
uses: actions/setup-dotnet@v4
27+
with:
28+
dotnet-version: 9.0.x
29+
30+
- name: Install GitVersion
31+
uses: gittools/actions/gitversion/setup@v0.9.15
32+
with:
33+
versionSpec: 5.x
34+
35+
- name: Determine Version
36+
id: gitversion
37+
uses: gittools/actions/gitversion/execute@v0.9.15
38+
with:
39+
useConfigFile: true
40+
41+
- name: Display Version
42+
run: |
43+
echo "FullSemVer: ${{ steps.gitversion.outputs.FullSemVer }}"
44+
echo "NuGetVersionV2: ${{ steps.gitversion.outputs.NuGetVersionV2 }}"
45+
echo "IsPreRelease? ${{ steps.gitversion.outputs.PreReleaseTag != '' }}"
46+
47+
- name: Fail if Pre-release on main
48+
if: ${{ steps.gitversion.outputs.PreReleaseTag != '' }}
49+
run: |
50+
echo "Unexpected pre-release on main. Check GitVersion config."
51+
exit 1
52+
53+
- name: Restore
54+
run: dotnet restore
55+
working-directory: '${{ env.working-directory }}'
56+
57+
- name: Build
58+
run: dotnet build -c Release --no-restore
59+
working-directory: '${{ env.working-directory }}'
60+
61+
- name: Test
62+
run: dotnet test -c Release --no-build
63+
working-directory: '${{ env.working-directory }}'
64+
65+
- name: Pack Stable
66+
run: |
67+
dotnet pack src/MyLibrary/MyLibrary.csproj \
68+
-c Release -o artifacts \
69+
/p:PackageVersion=${{ steps.gitversion.outputs.NuGetVersionV2 }}
70+
71+
- name: Create Tag (if missing)
72+
run: |
73+
TAG="v${{ steps.gitversion.outputs.MajorMinorPatch }}"
74+
if git rev-parse "$TAG" >/dev/null 2>&1; then
75+
echo "Tag $TAG already exists."
76+
else
77+
git tag "$TAG"
78+
git push origin "$TAG"
79+
fi
80+
81+
- name: Add GitHub Packages Source
82+
run: |
83+
dotnet nuget add source \
84+
--username $GITHUB_ACTOR \
85+
--password ${{ secrets.GITHUB_TOKEN }} \
86+
--store-password-in-clear-text \
87+
--name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
88+
89+
- name: Publish to GitHub Packages
90+
run: dotnet nuget push "artifacts/*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" --skip-duplicate
91+
92+
- name: Publish to NuGet
93+
if: ${{ startsWith(github.head_ref, 'release/')}}
94+
env:
95+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
96+
run: |
97+
dotnet nuget push "artifacts/*.nupkg" \
98+
--api-key "$NUGET_API_KEY" \
99+
--source https://api.nuget.org/v3/index.json \
100+
--skip-duplicate

0 commit comments

Comments
 (0)