Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 33 additions & 71 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
pull_request:
branches: [main]

env:
RUST_TOOLCHAIN: "1.94.0"

jobs:
build-test:
name: Build & Test (${{ matrix.os }})
Expand All @@ -22,17 +19,17 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
# SonarCloud needs the parent branch information.
fetch-depth: 0

- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Set up Rust
uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30 # stable
with:
toolchain: "1.94.0"
targets: wasm32-wasip1
uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1

- name: Cache wasm build
uses: actions/cache@v4
Expand All @@ -41,7 +38,7 @@ jobs:
~/.cargo/registry
~/.cargo/git
.wasm-build
key: wasm-${{ runner.os }}-${{ hashFiles('scripts/build-wasm.sh') }}
key: wasm-${{ runner.os }}-${{ hashFiles('scripts/build-wasm.sh', 'rust-toolchain.toml') }}

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -56,7 +53,7 @@ jobs:

- name: Build node harness
shell: bash
run: npm ci && npm run build
run: npm ci --ignore-scripts && npm rebuild sqlite3 && npm run build
working-directory: tests/node-harness
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -68,7 +65,29 @@ jobs:
run: dotnet build KeetaNet.Anchor.slnx -c Release --no-restore

- name: Test
run: dotnet test KeetaNet.Anchor.slnx -c Release --no-build
run: >
dotnet test KeetaNet.Anchor.slnx -c Release --no-build
-- --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml

# Run SonarCloud on the coverage this test run
- name: Convert coverage to SonarQube format
if: matrix.os == 'ubuntu-latest-l' && github.repository == 'KeetaNetwork/anchor-csharp'
run: |
dotnet tool install --global dotnet-reportgenerator-globaltool
reportgenerator \
"-reports:**/TestResults/**/coverage.cobertura.xml" \
"-targetdir:.sonar-coverage" \
"-reporttypes:SonarQube"

- name: SonarCloud Scan
if: matrix.os == 'ubuntu-latest-l' && github.repository == 'KeetaNetwork/anchor-csharp'
uses: SonarSource/sonarqube-scan-action@689fb39b34b9aa95ebc5f8f119343ddd51542402 # v4.2.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dproject.settings=./sonar-project.properties

lint:
name: Lint
Expand All @@ -92,7 +111,7 @@ jobs:
scope: "@keetanetwork"

- name: Check formatting and linting
run: make lint
run: make do-lint-ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -108,10 +127,7 @@ jobs:
global-json-file: global.json

- name: Set up Rust
uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30 # stable
with:
toolchain: "1.94.0"
targets: wasm32-wasip1
uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1

- name: Cache wasm build
uses: actions/cache@v4
Expand All @@ -120,13 +136,13 @@ jobs:
~/.cargo/registry
~/.cargo/git
.wasm-build
key: wasm-${{ runner.os }}-${{ hashFiles('scripts/build-wasm.sh') }}
key: wasm-${{ runner.os }}-${{ hashFiles('scripts/build-wasm.sh', 'rust-toolchain.toml') }}

- name: Build wasm core
run: bash scripts/build-wasm.sh

- name: Pack
run: dotnet pack src/KeetaNet.Anchor/KeetaNet.Anchor.csproj -c Release -o artifacts
run: dotnet pack KeetaNet.Anchor.slnx -c Release -o artifacts

- name: Upload package
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -155,57 +171,3 @@ jobs:
echo "::error::Vulnerable packages found"
exit 1
fi

sonar:
name: SonarCloud
runs-on: ubuntu-latest-l
if: github.repository == 'KeetaNetwork/anchor-csharp'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Set up Rust
uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30 # stable
with:
toolchain: "1.94.0"
targets: wasm32-wasip1

- name: Cache wasm build
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
.wasm-build
key: wasm-${{ runner.os }}-${{ hashFiles('scripts/build-wasm.sh') }}

- name: Build wasm core
run: bash scripts/build-wasm.sh

- name: Test with coverage
run: >
dotnet test tests/KeetaNet.Anchor.Tests/KeetaNet.Anchor.Tests.csproj -c Release
-- --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml

- name: Convert coverage to SonarQube format
run: |
dotnet tool install --global dotnet-reportgenerator-globaltool
reportgenerator \
"-reports:**/TestResults/**/coverage.cobertura.xml" \
"-targetdir:.sonar-coverage" \
"-reporttypes:SonarQube"

- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@689fb39b34b9aa95ebc5f8f119343ddd51542402 # v4.2.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dproject.settings=./sonar-project.properties
11 changes: 5 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ jobs:
global-json-file: global.json

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.94.0"
targets: wasm32-wasip1
uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1

- name: Build wasm core
run: bash scripts/build-wasm.sh
Expand All @@ -41,7 +38,7 @@ jobs:

- name: Pack
run: >
dotnet pack src/KeetaNet.Anchor/KeetaNet.Anchor.csproj -c Release -o artifacts
dotnet pack KeetaNet.Anchor.slnx -c Release -o artifacts
${{ startsWith(github.ref, 'refs/tags/releases/v') && format('-p:Version={0}', steps.version.outputs.value) || '' }}

- name: Attest build provenance
Expand All @@ -50,8 +47,10 @@ jobs:
subject-path: "artifacts/*.nupkg"

- name: Push
env:
NUGET_API_KEY: ${{ secrets.GITHUB_TOKEN }}
run: >
dotnet nuget push "artifacts/*.nupkg"
--source "https://nuget.pkg.github.com/KeetaNetwork/index.json"
--api-key "${{ secrets.GITHUB_TOKEN }}"
--api-key "$NUGET_API_KEY"
--skip-duplicate
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
1. Install the .NET SDK matching [`global.json`](global.json) and Rust with the `wasm32-wasip1` target (`rustup target add wasm32-wasip1`).
2. Run `make developer` to restore, build, and test. The first build runs `make wasm` to produce the embedded wasm core from the pinned crates.io release.
3. Make changes. Use hard tabs for indentation (spaces only where the format requires them, ex. YAML).
4. Run `make lint` and `make test` before opening a pull request.
4. Run `make do-lint` and `make test` before opening a pull request.

Always drive tasks through the `Makefile`, never raw `dotnet`.

Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

<ItemGroup>
<PackageVersion Include="Wasmtime" Version="44.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.2" />
</ItemGroup>

<ItemGroup Label="Test">
<PackageVersion Include="xunit.v3" Version="3.2.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.2" />
<!--
Must stay on the Microsoft.Testing.Platform 1.x line: xunit.v3 stable
ships an MTP v1 adapter (xunit.v3.core.mtp-v1 -> MTP 1.9.1), and the
Expand Down
1 change: 1 addition & 0 deletions KeetaNet.Anchor.slnx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Solution>
<Folder Name="/src/">
<Project Path="src/KeetaNet.Anchor/KeetaNet.Anchor.csproj" />
<Project Path="src/KeetaNet.Anchor.Extensions.DependencyInjection/KeetaNet.Anchor.Extensions.DependencyInjection.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/KeetaNet.Anchor.Tests/KeetaNet.Anchor.Tests.csproj" />
Expand Down
43 changes: 20 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
.PHONY: help developer restore build rebuild format lint test coverage pack clean wasm node-harness release
.PHONY: help developer restore build rebuild do-lint do-lint-ci test pack clean wasm node-harness release

# Build configuration (Debug or Release)
CONFIG ?= Release

# Solution under build
SLN := KeetaNet.Anchor.slnx

# Unit test project
UNIT_TESTS := tests/KeetaNet.Anchor.Tests/KeetaNet.Anchor.Tests.csproj

# TypeScript interop harness (reference anchor + in-memory test node)
HARNESS_DIR := tests/node-harness
HARNESS_SOURCES := $(wildcard $(HARNESS_DIR)/src/*.ts)
Expand All @@ -32,38 +29,37 @@ build: restore $(WASM_DEST)
# Clean then build
rebuild: clean build

# Apply formatting fixes
format:
# Lint code (applies formatting fixes; C# + the TypeScript harness, one command)
do-lint: node-harness
dotnet format $(SLN)
npx --yes cspell --config cspell.yaml --no-progress "src/**/*.cs" "tests/**/*.cs" "tests/node-harness/src/**" "scripts/**" "Makefile" "*.md"
cd $(HARNESS_DIR) && npm run lint

# Verify formatting, spelling, and the harness lint without writing changes
lint: node-harness
# Lint code for CI (check only, no fixes)
do-lint-ci: node-harness
dotnet format $(SLN) --verify-no-changes
npx --yes cspell --config cspell.yaml --no-progress "src/**/*.cs" "tests/**/*.cs" "tests/node-harness/src/**" "scripts/**" "Makefile" "*.md"
cd $(HARNESS_DIR) && npm run lint

# Run all tests: unit + e2e against the live TypeScript reference anchor
# Run all tests (unit + e2e against the live TypeScript reference anchor)
# with code coverage (cobertura, for SonarCloud conversion)
test: build node-harness
dotnet test $(SLN) -c $(CONFIG) --no-build
dotnet test $(SLN) -c $(CONFIG) --no-build \
-- --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml

# Build the TypeScript harnesses (installs deps + compiles every entry)
$(HARNESS_DIR)/node_modules/.package-lock.json: $(HARNESS_DIR)/package-lock.json
cd $(HARNESS_DIR) && npm ci
cd $(HARNESS_DIR) && npm ci --ignore-scripts && npm rebuild sqlite3

$(HARNESS_DIR)/dist/.built: $(HARNESS_DIR)/node_modules/.package-lock.json $(HARNESS_SOURCES)
cd $(HARNESS_DIR) && npm run build
touch $@

node-harness: $(HARNESS_DIR)/dist/.built

# Run unit tests with code coverage (cobertura, for SonarCloud conversion)
coverage: build
dotnet test $(UNIT_TESTS) -c $(CONFIG) --no-build \
-- --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml

# Produce the NuGet package (.nupkg + .snupkg)
# Produce the NuGet packages (.nupkg + .snupkg)
pack: build
dotnet pack src/KeetaNet.Anchor/KeetaNet.Anchor.csproj -c Release --no-build -o $(ARTIFACTS)
dotnet pack $(SLN) -c Release --no-build -o $(ARTIFACTS)

# Build the P1 wasm core from the pinned crates.io release
wasm:
Expand Down Expand Up @@ -102,14 +98,15 @@ help:
@echo " make restore - Restore NuGet dependencies"
@echo " make build - Build the solution (CONFIG=$(CONFIG))"
@echo " make rebuild - Clean then build"
@echo " make test - Run all tests (builds node-harness; unit + e2e)"
@echo " make test - Run all tests with coverage (builds node-harness; unit + e2e)"
@echo " make node-harness - Install + build the TypeScript interop harnesses"
@echo " make coverage - Run unit tests with code coverage"
@echo " make format - Apply formatting fixes"
@echo " make lint - Verify formatting + spelling"
@echo " make pack - Produce the NuGet package into $(ARTIFACTS)/"
@echo " make do-lint - Lint code with formatting fixes (C# + harness + spelling)"
@echo " make pack - Produce the NuGet packages into $(ARTIFACTS)/"
@echo " make wasm - Build the P1 wasm core from the pinned crates.io release"
@echo " make clean - Remove build outputs"
@echo ""
@echo "CI Commands:"
@echo " make do-lint-ci - Lint code for CI (check only, no fixes)"
@echo ""
@echo "Release commands:"
@echo " make release vX.Y.Z - Create a signed releases/vX.Y.Z tag"
Loading
Loading