Skip to content

Commit 4aac60a

Browse files
committed
code + tests and piplines
1 parent 53fb9bf commit 4aac60a

34 files changed

+1404
-347
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CodeQL
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: '0 0 * * 1'
10+
workflow_dispatch:
11+
12+
env:
13+
DOTNET_VERSION: '10.0.x'
14+
15+
jobs:
16+
analyze:
17+
name: Analyze
18+
runs-on: ubuntu-latest
19+
permissions:
20+
actions: read
21+
contents: read
22+
security-events: write
23+
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
language: [ 'csharp' ]
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v5
32+
with:
33+
submodules: true
34+
35+
- name: Setup .NET
36+
uses: actions/setup-dotnet@v4
37+
with:
38+
dotnet-version: ${{ env.DOTNET_VERSION }}
39+
40+
- name: Initialize CodeQL
41+
uses: github/codeql-action/init@v3
42+
with:
43+
languages: ${{ matrix.language }}
44+
45+
- name: Restore dependencies
46+
run: dotnet restore MarkdownLd.Kb.slnx
47+
48+
- name: Build
49+
run: dotnet build MarkdownLd.Kb.slnx --configuration Release --no-restore
50+
51+
- name: Perform CodeQL Analysis
52+
uses: github/codeql-action/analyze@v3

.github/workflows/release.yml

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
env:
9+
DOTNET_VERSION: '10.0.x'
10+
SOLUTION: MarkdownLd.Kb.slnx
11+
ARTIFACTS_DIR: ./artifacts
12+
13+
jobs:
14+
build:
15+
name: Build, test, and pack
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 20
18+
permissions:
19+
contents: read
20+
21+
outputs:
22+
version: ${{ steps.version.outputs.version }}
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v5
27+
with:
28+
submodules: true
29+
30+
- name: Setup .NET
31+
uses: actions/setup-dotnet@v4
32+
with:
33+
dotnet-version: ${{ env.DOTNET_VERSION }}
34+
35+
- name: Extract version from Directory.Build.props
36+
id: version
37+
shell: bash
38+
run: |
39+
set -euo pipefail
40+
VERSION="$(python3 - <<'PY'
41+
import xml.etree.ElementTree as ET
42+
43+
root = ET.parse("Directory.Build.props").getroot()
44+
45+
def read(name: str) -> str:
46+
for element in root.iter():
47+
if element.tag.endswith(name) and element.text and element.text.strip():
48+
return element.text.strip()
49+
return ""
50+
51+
print(read("PackageVersion") or read("Version"))
52+
PY
53+
)"
54+
55+
if [ -z "${VERSION}" ]; then
56+
echo "::error::Could not read <PackageVersion>/<Version> from Directory.Build.props"
57+
exit 1
58+
fi
59+
60+
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
61+
echo "Version from Directory.Build.props: ${VERSION}"
62+
63+
- name: Restore dependencies
64+
run: dotnet restore ${{ env.SOLUTION }}
65+
66+
- name: Verify formatting
67+
run: dotnet format ${{ env.SOLUTION }} --verify-no-changes --no-restore
68+
69+
- name: Build
70+
run: dotnet build ${{ env.SOLUTION }} --configuration Release --no-restore
71+
72+
- name: Test
73+
run: dotnet test --solution ${{ env.SOLUTION }} --configuration Release --no-build --verbosity normal
74+
75+
- name: Pack NuGet packages
76+
run: dotnet pack ${{ env.SOLUTION }} --configuration Release --no-build -p:IncludeSymbols=false -p:SymbolPackageFormat=snupkg --output ${{ env.ARTIFACTS_DIR }}
77+
78+
- name: Upload artifacts
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: nuget-packages
82+
path: ${{ env.ARTIFACTS_DIR }}/*.nupkg
83+
retention-days: 5
84+
85+
publish-nuget:
86+
name: Publish to NuGet
87+
needs: build
88+
runs-on: ubuntu-latest
89+
if: github.ref == 'refs/heads/main'
90+
permissions:
91+
contents: read
92+
93+
outputs:
94+
published: ${{ steps.publish.outputs.published }}
95+
version: ${{ needs.build.outputs.version }}
96+
97+
steps:
98+
- name: Download artifacts
99+
uses: actions/download-artifact@v5
100+
with:
101+
name: nuget-packages
102+
path: ${{ env.ARTIFACTS_DIR }}
103+
104+
- name: Setup .NET
105+
uses: actions/setup-dotnet@v4
106+
with:
107+
dotnet-version: ${{ env.DOTNET_VERSION }}
108+
109+
- name: Publish to NuGet
110+
id: publish
111+
shell: bash
112+
run: |
113+
set -euo pipefail
114+
115+
PUBLISHED=false
116+
shopt -s nullglob
117+
118+
for package in ${{ env.ARTIFACTS_DIR }}/*.nupkg; do
119+
echo "Publishing ${package}..."
120+
set +e
121+
RESULT="$(dotnet nuget push "${package}" \
122+
--api-key "${{ secrets.NUGET_API_KEY }}" \
123+
--source https://api.nuget.org/v3/index.json \
124+
--skip-duplicate 2>&1)"
125+
EXIT_CODE=$?
126+
set -e
127+
echo "${RESULT}"
128+
129+
if [ ${EXIT_CODE} -eq 0 ]; then
130+
PUBLISHED=true
131+
elif echo "${RESULT}" | grep -qi "already exists"; then
132+
echo "Package already exists, skipping ${package}."
133+
else
134+
echo "::error::Failed to publish ${package}"
135+
exit ${EXIT_CODE}
136+
fi
137+
done
138+
139+
echo "published=${PUBLISHED}" >> "${GITHUB_OUTPUT}"
140+
141+
create-release:
142+
name: Create GitHub release and tag
143+
needs: publish-nuget
144+
runs-on: ubuntu-latest
145+
if: needs.publish-nuget.outputs.published == 'true'
146+
permissions:
147+
contents: write
148+
149+
steps:
150+
- name: Checkout
151+
uses: actions/checkout@v5
152+
with:
153+
fetch-depth: 0
154+
token: ${{ secrets.GITHUB_TOKEN }}
155+
156+
- name: Download artifacts
157+
uses: actions/download-artifact@v5
158+
with:
159+
name: nuget-packages
160+
path: ${{ env.ARTIFACTS_DIR }}
161+
162+
- name: Create and push tag
163+
shell: bash
164+
run: |
165+
set -euo pipefail
166+
VERSION="${{ needs.publish-nuget.outputs.version }}"
167+
TAG="v${VERSION}"
168+
169+
git config user.name "github-actions[bot]"
170+
git config user.email "github-actions[bot]@users.noreply.github.com"
171+
172+
if git rev-parse "${TAG}" >/dev/null 2>&1; then
173+
echo "Tag ${TAG} already exists."
174+
else
175+
git tag -a "${TAG}" -m "Release ${VERSION}"
176+
git push origin "${TAG}"
177+
fi
178+
179+
- name: Generate release notes
180+
shell: bash
181+
run: |
182+
set -euo pipefail
183+
VERSION="${{ needs.publish-nuget.outputs.version }}"
184+
TAG="v${VERSION}"
185+
PREVIOUS_TAG="$(git tag --sort=-version:refname | grep -v "^${TAG}$" | head -n1 || true)"
186+
187+
{
188+
echo "# Release ${VERSION}"
189+
echo
190+
echo "Released on $(date +'%Y-%m-%d')"
191+
echo
192+
193+
if [ -n "${PREVIOUS_TAG}" ]; then
194+
echo "## Changes since ${PREVIOUS_TAG}"
195+
echo
196+
git log --pretty=format:"- %s (%h)" "${PREVIOUS_TAG}..HEAD" || true
197+
else
198+
echo "## Initial release"
199+
echo
200+
git log --pretty=format:"- %s (%h)" --max-count=20 || true
201+
fi
202+
203+
echo
204+
echo "## NuGet packages"
205+
echo
206+
shopt -s nullglob
207+
for package in ${{ env.ARTIFACTS_DIR }}/*.nupkg; do
208+
file="$(basename "${package}")"
209+
base="${file%.nupkg}"
210+
package_id="${base%.${VERSION}}"
211+
echo "- [${package_id} ${VERSION}](https://www.nuget.org/packages/${package_id}/${VERSION})"
212+
done
213+
} > release_notes.md
214+
215+
- name: Create GitHub Release
216+
uses: softprops/action-gh-release@v2
217+
with:
218+
tag_name: v${{ needs.publish-nuget.outputs.version }}
219+
name: v${{ needs.publish-nuget.outputs.version }}
220+
body_path: release_notes.md
221+
files: ${{ env.ARTIFACTS_DIR }}/*.nupkg
222+
draft: false
223+
prerelease: false
224+
env:
225+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/validation.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: PR validation
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
env:
11+
DOTNET_VERSION: '10.0.x'
12+
13+
jobs:
14+
validate:
15+
name: Build, test, and pack
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 15
18+
permissions:
19+
contents: read
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v5
24+
with:
25+
submodules: true
26+
27+
- name: Setup .NET
28+
uses: actions/setup-dotnet@v4
29+
with:
30+
dotnet-version: ${{ env.DOTNET_VERSION }}
31+
32+
- name: Restore dependencies
33+
run: dotnet restore MarkdownLd.Kb.slnx
34+
35+
- name: Verify formatting
36+
run: dotnet format MarkdownLd.Kb.slnx --verify-no-changes --no-restore
37+
38+
- name: Build
39+
run: dotnet build MarkdownLd.Kb.slnx --configuration Release --no-restore
40+
41+
- name: Test with coverage
42+
run: dotnet test --solution MarkdownLd.Kb.slnx --configuration Release --no-build --verbosity normal --coverlet --coverlet-output-format cobertura --coverlet-include '[ManagedCode.MarkdownLd.Kb]*' --results-directory TestResults/CoverletMtpFiltered
43+
44+
- name: Pack
45+
run: dotnet pack MarkdownLd.Kb.slnx --configuration Release --no-build -p:IncludeSymbols=false -p:SymbolPackageFormat=snupkg --output ./artifacts
46+
47+
- name: Upload coverage artifact
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: coverage
51+
path: TestResults/CoverletMtpFiltered/**/coverage.cobertura.xml
52+
retention-days: 5
53+
54+
- name: Upload package artifact
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: nuget-validation-packages
58+
path: ./artifacts/*.nupkg
59+
retention-days: 5

Directory.Build.props

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<DotNetVersion>10.0.x</DotNetVersion>
6+
<LangVersion>14</LangVersion>
7+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
8+
<DebugType>embedded</DebugType>
9+
<Nullable>enable</Nullable>
10+
<ImplicitUsings>enable</ImplicitUsings>
11+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
12+
</PropertyGroup>
13+
14+
<PropertyGroup>
15+
<Authors>ManagedCode</Authors>
16+
<Copyright>Copyright (c) 2026 ManagedCode</Copyright>
17+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
18+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
19+
<IncludeSymbols>true</IncludeSymbols>
20+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
21+
<RepositoryType>git</RepositoryType>
22+
<RepositoryUrl>https://github.com/managedcode/markdown-ld-kb</RepositoryUrl>
23+
<PackageProjectUrl>https://github.com/managedcode/markdown-ld-kb</PackageProjectUrl>
24+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
25+
<PackageReadmeFile>README.md</PackageReadmeFile>
26+
<EnablePackageValidation>true</EnablePackageValidation>
27+
<Product>Markdown-LD Knowledge Bank</Product>
28+
<Version>0.0.1</Version>
29+
<PackageVersion>0.0.1</PackageVersion>
30+
</PropertyGroup>
31+
32+
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
33+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
34+
</PropertyGroup>
35+
36+
<ItemGroup>
37+
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" Visible="false" PackagePath="\" />
38+
</ItemGroup>
39+
40+
<ItemGroup>
41+
<PackageReference Include="DotNet.ReproducibleBuilds">
42+
<PrivateAssets>all</PrivateAssets>
43+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
44+
</PackageReference>
45+
</ItemGroup>
46+
47+
</Project>

0 commit comments

Comments
 (0)