|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ci-${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +env: |
| 18 | + DOTNET_CLI_TELEMETRY_OPTOUT: "1" |
| 19 | + DOTNET_NOLOGO: "1" |
| 20 | + D2_VERSION: 0.7.1 |
| 21 | + |
| 22 | +jobs: |
| 23 | + build-and-test: |
| 24 | + name: Build and test (${{ matrix.os }}) |
| 25 | + runs-on: ${{ matrix.os }} |
| 26 | + timeout-minutes: 15 |
| 27 | + strategy: |
| 28 | + fail-fast: false |
| 29 | + matrix: |
| 30 | + os: |
| 31 | + - ubuntu-latest |
| 32 | + - windows-latest |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Check out repository |
| 36 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 37 | + with: |
| 38 | + persist-credentials: false |
| 39 | + |
| 40 | + - name: Set up .NET |
| 41 | + uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0 |
| 42 | + with: |
| 43 | + dotnet-version: 10.0.x |
| 44 | + |
| 45 | + - name: Restore |
| 46 | + run: dotnet restore d2lang-cs.sln |
| 47 | + |
| 48 | + - name: Build |
| 49 | + run: dotnet build d2lang-cs.sln --configuration Release --no-restore -p:ContinuousIntegrationBuild=true |
| 50 | + |
| 51 | + - name: Install pinned D2 CLI |
| 52 | + if: runner.os == 'Linux' |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + archive="$RUNNER_TEMP/d2-v${D2_VERSION}-linux-amd64.tar.gz" |
| 56 | + install_dir="$RUNNER_TEMP/d2-cli" |
| 57 | + curl --proto '=https' --tlsv1.2 --location --fail --silent --show-error \ |
| 58 | + "https://github.com/d2lang/d2/releases/download/v${D2_VERSION}/d2-v${D2_VERSION}-linux-amd64.tar.gz" \ |
| 59 | + --output "$archive" |
| 60 | + echo "eb172adf59f38d1e5a70ab177591356754ffaf9bebb84e0ca8b767dfb421dad7 $archive" | sha256sum --check --strict |
| 61 | + mkdir -p "$install_dir" |
| 62 | + tar -xzf "$archive" --strip-components=1 -C "$install_dir" |
| 63 | + echo "$install_dir/bin" >> "$GITHUB_PATH" |
| 64 | +
|
| 65 | + - name: Test with coverage |
| 66 | + run: dotnet test test/Tests.csproj --configuration Release --no-build --logger "trx;LogFileName=tests.trx" --collect "XPlat Code Coverage" --results-directory artifacts/test-results/${{ runner.os }} |
| 67 | + |
| 68 | + - name: Add coverage summary |
| 69 | + if: always() |
| 70 | + shell: pwsh |
| 71 | + run: | |
| 72 | + $coveragePath = Get-ChildItem "artifacts/test-results/${{ runner.os }}" -Filter coverage.cobertura.xml -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 |
| 73 | + if ($null -eq $coveragePath) { |
| 74 | + "## Coverage (${{ runner.os }})`n`nCoverage report was not produced." | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append |
| 75 | + exit 0 |
| 76 | + } |
| 77 | +
|
| 78 | + [xml] $coverage = Get-Content $coveragePath.FullName |
| 79 | + $lineRate = [double]::Parse($coverage.coverage.'line-rate', [Globalization.CultureInfo]::InvariantCulture) |
| 80 | + $branchRate = [double]::Parse($coverage.coverage.'branch-rate', [Globalization.CultureInfo]::InvariantCulture) |
| 81 | + $linePercent = [Math]::Round($lineRate * 100, 2) |
| 82 | + $branchPercent = [Math]::Round($branchRate * 100, 2) |
| 83 | + $summary = "## Coverage (${{ runner.os }})`n`n| Metric | Coverage |`n| --- | ---: |`n| Lines | $linePercent% |`n| Branches | $branchPercent% |" |
| 84 | + $summary | Out-File -FilePath "artifacts/test-results/${{ runner.os }}/coverage-summary.md" |
| 85 | + $summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append |
| 86 | +
|
| 87 | + - name: Upload test results |
| 88 | + if: always() |
| 89 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 90 | + with: |
| 91 | + name: test-results-${{ runner.os }} |
| 92 | + path: artifacts/test-results/${{ runner.os }}/**/*.trx |
| 93 | + if-no-files-found: warn |
| 94 | + retention-days: 14 |
| 95 | + |
| 96 | + - name: Upload coverage report |
| 97 | + if: always() |
| 98 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 99 | + with: |
| 100 | + name: coverage-${{ runner.os }} |
| 101 | + path: | |
| 102 | + artifacts/test-results/${{ runner.os }}/**/coverage.cobertura.xml |
| 103 | + artifacts/test-results/${{ runner.os }}/coverage-summary.md |
| 104 | + if-no-files-found: warn |
| 105 | + retention-days: 14 |
| 106 | + |
| 107 | + - name: Validate generated D2 syntax |
| 108 | + if: runner.os == 'Linux' |
| 109 | + shell: bash |
| 110 | + run: | |
| 111 | + d2 version |
| 112 | + dotnet run --project example/cli/d2-sample-cli.csproj --configuration Release --no-build > artifacts/example.d2 |
| 113 | + d2 validate artifacts/example.d2 |
| 114 | +
|
| 115 | + package: |
| 116 | + name: Validate NuGet package |
| 117 | + needs: build-and-test |
| 118 | + runs-on: ubuntu-latest |
| 119 | + timeout-minutes: 15 |
| 120 | + |
| 121 | + steps: |
| 122 | + - name: Check out repository |
| 123 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 124 | + with: |
| 125 | + persist-credentials: false |
| 126 | + |
| 127 | + - name: Set up .NET |
| 128 | + uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0 |
| 129 | + with: |
| 130 | + dotnet-version: 10.0.x |
| 131 | + |
| 132 | + - name: Restore |
| 133 | + run: dotnet restore src/d2lang-cs.csproj |
| 134 | + |
| 135 | + - name: Pack with package validation |
| 136 | + run: dotnet pack src/d2lang-cs.csproj --configuration Release --no-restore --output artifacts/packages -p:ContinuousIntegrationBuild=true -p:EnablePackageValidation=true |
| 137 | + |
| 138 | + - name: Inspect package contents |
| 139 | + shell: bash |
| 140 | + run: | |
| 141 | + package_path=$(find artifacts/packages -maxdepth 1 -name '*.nupkg' ! -name '*.snupkg' -print -quit) |
| 142 | + test -n "$package_path" |
| 143 | + unzip -l "$package_path" | tee artifacts/package-contents.txt |
| 144 | + grep -q 'lib/net10.0/d2lang-cs.dll' artifacts/package-contents.txt |
| 145 | + grep -q 'README.md' artifacts/package-contents.txt |
| 146 | + grep -q 'd2_logo.png' artifacts/package-contents.txt |
| 147 | +
|
| 148 | + - name: Install package in a clean consumer project |
| 149 | + shell: bash |
| 150 | + run: | |
| 151 | + dotnet new console --framework net10.0 --output artifacts/package-smoke --no-restore |
| 152 | + dotnet add artifacts/package-smoke/package-smoke.csproj package d2lang-cs --source "$PWD/artifacts/packages" |
| 153 | + dotnet build artifacts/package-smoke/package-smoke.csproj --configuration Release --no-restore |
| 154 | +
|
| 155 | + - name: Upload package |
| 156 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 157 | + with: |
| 158 | + name: nuget-package |
| 159 | + path: | |
| 160 | + artifacts/packages/*.nupkg |
| 161 | + artifacts/package-contents.txt |
| 162 | + if-no-files-found: error |
| 163 | + retention-days: 14 |
0 commit comments