Skip to content

Commit 6bb8304

Browse files
author
Michael Conrad
authored
Merge pull request #4 from MichaCo/copilot/add-basic-repository-features
Fix xunit.v3 test discovery and code coverage in CI (dotnet test / VSTest incompatibility)
2 parents 29cce4b + d5b7afe commit 6bb8304

7 files changed

Lines changed: 689 additions & 3 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags: [ 'v*.*.*' ]
7+
pull_request:
8+
branches: [ main ]
9+
workflow_dispatch:
10+
11+
jobs:
12+
build-and-test:
13+
name: Build and Test (${{ matrix.os }})
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [windows-latest, ubuntu-latest]
19+
permissions:
20+
contents: read
21+
pull-requests: write # needed for sticky-pull-request-comment
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0 # Required for SourceLink
28+
29+
- name: Setup .NET
30+
uses: actions/setup-dotnet@v4
31+
with:
32+
dotnet-version: |
33+
8.0.x
34+
10.0.x
35+
36+
# Windows: restore full solution (includes Windows-only CDT.Viz)
37+
- name: Restore dependencies
38+
if: runner.os == 'Windows'
39+
run: dotnet restore
40+
41+
# Linux: restore only cross-platform projects (CDT.Viz targets Windows only)
42+
- name: Restore dependencies
43+
if: runner.os == 'Linux'
44+
run: |
45+
dotnet restore src/CDT.Core/CDT.Core.csproj
46+
dotnet restore test/CDT.Tests/CDT.Tests.csproj
47+
48+
# Windows: build full solution
49+
- name: Build
50+
if: runner.os == 'Windows'
51+
run: dotnet build --no-restore -c Release
52+
53+
# Linux: build only cross-platform projects
54+
- name: Build
55+
if: runner.os == 'Linux'
56+
run: |
57+
dotnet build --no-restore -c Release src/CDT.Core/CDT.Core.csproj
58+
dotnet build --no-restore -c Release test/CDT.Tests/CDT.Tests.csproj
59+
60+
# Windows: test full solution
61+
- name: Test
62+
if: runner.os == 'Windows'
63+
run: dotnet test --no-build -c Release --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=${{ github.workspace }}/coverage/coverage.cobertura.xml
64+
65+
# Linux: test only CDT.Tests (CDT.Viz has no tests; benchmark is not a test project)
66+
- name: Test
67+
if: runner.os == 'Linux'
68+
run: dotnet test --no-build -c Release --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=${{ github.workspace }}/coverage/coverage.cobertura.xml test/CDT.Tests/CDT.Tests.csproj
69+
70+
- name: Generate coverage report
71+
uses: danielpalme/ReportGenerator-GitHub-Action@5
72+
with:
73+
reports: ${{ github.workspace }}/coverage/coverage.cobertura.xml
74+
targetdir: coveragereport
75+
reporttypes: MarkdownSummaryGithub
76+
77+
- name: Write coverage to job summary (Windows)
78+
if: runner.os == 'Windows'
79+
run: Get-Content coveragereport/SummaryGithub.md >> $env:GITHUB_STEP_SUMMARY
80+
shell: pwsh
81+
82+
- name: Add coverage PR comment
83+
uses: marocchino/sticky-pull-request-comment@v2
84+
if: runner.os == 'Windows' && github.event_name == 'pull_request'
85+
with:
86+
recreate: true
87+
path: coveragereport/SummaryGithub.md
88+
89+
- name: Write coverage to job summary (Linux)
90+
if: runner.os == 'Linux'
91+
run: cat coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
92+
93+
publish:
94+
name: Publish to NuGet
95+
needs: build-and-test
96+
runs-on: windows-latest
97+
if: startsWith(github.ref, 'refs/tags/v')
98+
permissions:
99+
contents: read
100+
101+
steps:
102+
- name: Checkout
103+
uses: actions/checkout@v4
104+
with:
105+
fetch-depth: 0 # Required for SourceLink
106+
107+
- name: Setup .NET
108+
uses: actions/setup-dotnet@v4
109+
with:
110+
dotnet-version: |
111+
8.0.x
112+
10.0.x
113+
114+
- name: Restore dependencies
115+
run: dotnet restore
116+
117+
- name: Build
118+
run: dotnet build --no-restore -c Release
119+
120+
- name: Pack
121+
run: dotnet pack src/CDT.Core/CDT.Core.csproj --no-build -c Release -o ./artifacts
122+
123+
- name: Push to NuGet.org
124+
# Requires a NUGET_API_KEY secret configured in:
125+
# GitHub → Repository Settings → Secrets and variables → Actions → New repository secret
126+
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Upstream Sync
2+
3+
on:
4+
schedule:
5+
# Run daily at 06:00 UTC
6+
- cron: '0 6 * * *'
7+
workflow_dispatch:
8+
9+
jobs:
10+
check-upstream:
11+
name: Check for upstream changes
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write # needed to update .last-sync-commit on main
15+
issues: write # needed to create the issue that triggers Copilot
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
ref: main
22+
23+
- name: Get last synced commit
24+
id: last-sync
25+
run: echo "sha=$(cat .last-sync-commit | tr -d '[:space:]')" >> "$GITHUB_OUTPUT"
26+
27+
- name: Get latest upstream commit
28+
id: upstream
29+
run: |
30+
# git ls-remote reads public repos without any auth or API calls
31+
LATEST=$(git ls-remote https://github.com/artem-ogre/CDT.git refs/heads/master | cut -f1)
32+
if [ -z "$LATEST" ]; then
33+
echo "::error::Could not resolve latest upstream commit SHA"
34+
exit 1
35+
fi
36+
echo "sha=$LATEST" >> "$GITHUB_OUTPUT"
37+
echo "Latest upstream commit: $LATEST"
38+
39+
- name: Create Copilot porting issue
40+
if: steps.last-sync.outputs.sha != steps.upstream.outputs.sha
41+
env:
42+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
run: |
44+
LAST="${{ steps.last-sync.outputs.sha }}"
45+
LATEST="${{ steps.upstream.outputs.sha }}"
46+
DATE=$(date -u +"%Y-%m-%d")
47+
48+
echo "Upstream has new commits since ${LAST:0:7} (latest: ${LATEST:0:7})"
49+
50+
# Shallow-clone the upstream history (metadata only) to build a commit list
51+
git clone --depth 50 --no-checkout https://github.com/artem-ogre/CDT.git /tmp/CDT-upstream
52+
COMMITS=$(git -C /tmp/CDT-upstream log \
53+
--pretty=format:"- [%h](https://github.com/artem-ogre/CDT/commit/%H) %s" \
54+
"${LAST}..${LATEST}" 2>/dev/null || echo "- (see compare link below)")
55+
[ -z "$COMMITS" ] && COMMITS="- (see compare link below)"
56+
57+
# Update .last-sync-commit on main so we don't re-open the issue next run
58+
git config user.name "github-actions[bot]"
59+
git config user.email "github-actions[bot]@users.noreply.github.com"
60+
echo "$LATEST" > .last-sync-commit
61+
git add .last-sync-commit
62+
git commit -m "chore: advance upstream sync marker to ${LATEST:0:7}"
63+
git push origin main
64+
65+
# Ensure the auto-sync label exists
66+
gh label create "auto-sync" \
67+
--description "Automatically generated upstream sync issue" \
68+
--color "0075ca" 2>/dev/null || true
69+
70+
# Create an issue assigned to the Copilot coding agent.
71+
# Assigning to @Copilot triggers the coding agent to pick it up
72+
# and create a PR with the ported C# changes.
73+
ISSUE_BODY=$(cat <<'EOF'
74+
## Upstream Sync Task
75+
76+
@Copilot please port the upstream changes listed below to C# and open a pull request.
77+
78+
New commits have been pushed to [artem-ogre/CDT](https://github.com/artem-ogre/CDT) since the last sync.
79+
80+
**Previous synced commit:** [`LAST_SHA`](https://github.com/artem-ogre/CDT/commit/LAST_FULL)
81+
**New upstream commit:** [`LATEST_SHA`](https://github.com/artem-ogre/CDT/commit/LATEST_FULL)
82+
**Full diff:** https://github.com/artem-ogre/CDT/compare/LAST_FULL...LATEST_FULL
83+
84+
### Upstream commits to port
85+
86+
COMMIT_LIST
87+
88+
### What to port
89+
90+
Please port all upstream C++ changes to C# and open a pull request.
91+
92+
Key files to check in the upstream diff:
93+
- `CDT/include/CDT.h` and `CDT/include/CDT.hpp` → port any algorithm changes to `src/CDT.Core/`
94+
- `CDT/include/Predicates.h` → port to `src/CDT.Core/Predicates.cs`
95+
- `CDT/include/KDTree.h` → port to `src/CDT.Core/KdTree.cs`
96+
- Any new types or utilities → port to `src/CDT.Core/Types.cs` or new files as appropriate
97+
98+
After porting:
99+
1. Run `dotnet test` and ensure all tests pass
100+
2. Update test inputs/expected outputs if needed
101+
EOF
102+
)
103+
# Replace placeholders with actual values
104+
ISSUE_BODY="${ISSUE_BODY//LAST_SHA/${LAST:0:7}}"
105+
ISSUE_BODY="${ISSUE_BODY//LAST_FULL/${LAST}}"
106+
ISSUE_BODY="${ISSUE_BODY//LATEST_SHA/${LATEST:0:7}}"
107+
ISSUE_BODY="${ISSUE_BODY//LATEST_FULL/${LATEST}}"
108+
ISSUE_BODY="${ISSUE_BODY//COMMIT_LIST/$COMMITS}"
109+
110+
gh issue create \
111+
--title "Port upstream CDT changes to C# (${LATEST:0:7}) — ${DATE}" \
112+
--label "auto-sync" \
113+
--assignee "Copilot" \
114+
--body "$ISSUE_BODY"

.last-sync-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7bd85e41a7b2e6e6e3bf82f36bcbc2bcec6441c5

0 commit comments

Comments
 (0)