Skip to content

Commit 1c11efc

Browse files
Copilotpetesramek
andauthored
Enforce public API analyzers in CI workflows
Agent-Logs-Url: https://github.com/petesramek/polyline-algorithm-csharp/sessions/27e5854c-f2ca-44ac-8491-b6c1f35ec93d Co-authored-by: petesramek <2333452+petesramek@users.noreply.github.com>
1 parent 543938d commit 1c11efc

5 files changed

Lines changed: 80 additions & 6 deletions

File tree

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,6 @@ dotnet_naming_style.underscore_camel_case.capitalization = camel_case
274274
# Public API analyzer
275275

276276
dotnet_public_api_analyzer.require_api_files = true
277+
278+
# RS0017: Symbol removed from public API - always an error (breaking change detection)
279+
dotnet_diagnostic.RS0017.severity = error

.github/actions/source/compile/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ inputs:
1212
file-version:
1313
description: 'Assembly file version.'
1414
required: true
15-
treat-warnins-as-error:
15+
treat-warnings-as-error:
1616
description: 'Treat warnings as errors.'
1717
required: true
1818
project-path:

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
assembly-version: ${{ env.assembly-version }}
131131
assembly-informational-version: ${{ env.assembly-informational-version }}
132132
file-version: ${{ env.file-version }}
133-
treat-warnins-as-error: ${{ needs.workflow-variables.outputs.is-release }}
133+
treat-warnings-as-error: ${{ needs.workflow-variables.outputs.is-release }}
134134

135135
test:
136136
name: 'Run tests'

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120
assembly-version: ${{ env.assembly-version }}
121121
assembly-informational-version: ${{ env.assembly-informational-version }}
122122
file-version: ${{ env.file-version }}
123-
treat-warnins-as-error: ${{ needs.workflow-variables.outputs.is-release }}
123+
treat-warnings-as-error: ${{ needs.workflow-variables.outputs.is-release }}
124124

125125
test:
126126
name: 'Run tests'

.github/workflows/release.yml

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
assembly-version: ${{ env.assembly-version }}
130130
assembly-informational-version: ${{ env.assembly-informational-version }}
131131
file-version: ${{ env.file-version }}
132-
treat-warnins-as-error: ${{ needs.workflow-variables.outputs.is-release }}
132+
treat-warnings-as-error: ${{ needs.workflow-variables.outputs.is-release }}
133133

134134
test:
135135
name: 'Run tests'
@@ -169,6 +169,71 @@ jobs:
169169
- name: Write code coverage report summary
170170
run: cat ${{ steps.code-coverage-report.outputs.code-coverage-report-file }} >> $GITHUB_STEP_SUMMARY
171171

172+
update-api-unshipped:
173+
name: 'Update PublicAPI.Unshipped.txt'
174+
needs: [workflow-variables, build, validate-release]
175+
if: ${{ needs.workflow-variables.outputs.is-preview == 'true' }}
176+
runs-on: ubuntu-latest
177+
steps:
178+
- name: 'Checkout ${{ github.ref }}'
179+
uses: actions/checkout@v6
180+
181+
- name: 'Setup .NET'
182+
uses: actions/setup-dotnet@v5
183+
with:
184+
dotnet-version: ${{ env.dotnet-sdk-version }}
185+
186+
- name: 'Add missing API declarations to PublicAPI.Unshipped.txt'
187+
shell: bash
188+
run: dotnet format analyzers src/PolylineAlgorithm/PolylineAlgorithm.csproj --diagnostics RS0016
189+
190+
- name: 'Configure git identity'
191+
uses: './.github/actions/git/configure-identity'
192+
193+
- name: 'Commit and push updated API files'
194+
shell: bash
195+
run: |
196+
git add src/PolylineAlgorithm/PublicAPI.Unshipped.txt
197+
git diff --staged --quiet || (
198+
git commit -m "Update PublicAPI.Unshipped.txt with new API declarations" &&
199+
git pull --rebase origin ${{ github.ref_name }} &&
200+
git push
201+
)
202+
203+
promote-api-files:
204+
name: 'Promote PublicAPI files (Unshipped -> Shipped)'
205+
needs: [workflow-variables, test, validate-release]
206+
if: ${{ needs.workflow-variables.outputs.is-release == 'true' }}
207+
runs-on: ubuntu-latest
208+
steps:
209+
- name: 'Checkout ${{ github.ref }}'
210+
uses: actions/checkout@v6
211+
212+
- name: 'Promote Unshipped.txt into Shipped.txt'
213+
shell: bash
214+
run: |
215+
UNSHIPPED="src/PolylineAlgorithm/PublicAPI.Unshipped.txt"
216+
SHIPPED="src/PolylineAlgorithm/PublicAPI.Shipped.txt"
217+
218+
# Append every non-blank, non-header line from Unshipped into Shipped
219+
tail -n +2 "$UNSHIPPED" | grep -v '^[[:space:]]*$' >> "$SHIPPED" || true
220+
221+
# Reset Unshipped to just the nullable-enable header (with BOM to match convention)
222+
printf '\xef\xbb\xbf#nullable enable\n' > "$UNSHIPPED"
223+
224+
- name: 'Configure git identity'
225+
uses: './.github/actions/git/configure-identity'
226+
227+
- name: 'Commit and push promoted API files'
228+
shell: bash
229+
run: |
230+
git add src/PolylineAlgorithm/PublicAPI.Shipped.txt src/PolylineAlgorithm/PublicAPI.Unshipped.txt
231+
git diff --staged --quiet || (
232+
git commit -m "Promote PublicAPI.Unshipped.txt into PublicAPI.Shipped.txt for release" &&
233+
git pull --rebase origin ${{ github.ref_name }} &&
234+
git push
235+
)
236+
172237
pack:
173238
name: 'Package binaries'
174239
needs: [versioning, build, test, validate-release]
@@ -219,8 +284,14 @@ jobs:
219284

220285
publish-package:
221286
name: 'Publish package'
222-
needs: [pack, validate-release, publish-documentation]
223-
if: ${{ always() && needs.pack.result == 'success' && needs.validate-release.result == 'success' && (needs.publish-documentation.result == 'success' || needs.publish-documentation.result == 'skipped') }}
287+
needs: [pack, validate-release, publish-documentation, update-api-unshipped, promote-api-files]
288+
if: |
289+
always() &&
290+
needs.pack.result == 'success' &&
291+
needs.validate-release.result == 'success' &&
292+
(needs.publish-documentation.result == 'success' || needs.publish-documentation.result == 'skipped') &&
293+
(needs.promote-api-files.result == 'success' || needs.promote-api-files.result == 'skipped') &&
294+
(needs.update-api-unshipped.result == 'success' || needs.update-api-unshipped.result == 'skipped')
224295
env:
225296
package-artifact-name: ${{ needs.pack.outputs.package-artifact-name }}
226297
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)