Skip to content

Commit 21a3668

Browse files
Add documentation snippets (#3592)
- Use mdsnippets to get code snippets in markdown from compile-validated code. - Use badges for dependency versions in README. - Add dependency of Microsoft.OpenApi to the README. - Put OpenAPI first (and in bold to indicate the default), and 2.0 for Swagger second.
1 parent 2d2067a commit 21a3668

42 files changed

Lines changed: 2351 additions & 517 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.config/dotnet-tools.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"commands": [
88
"dotnet-validate"
99
]
10+
},
11+
"markdownsnippets.tool": {
12+
"version": "27.0.2",
13+
"commands": [
14+
"mdsnippets"
15+
]
1016
}
1117
}
1218
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: update-documentation
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
paths: [ '**/*.md', 'test/WebSites/DocumentationSnippets/**' ]
7+
workflow_dispatch:
8+
9+
permissions: {}
10+
11+
jobs:
12+
update-docs:
13+
name: update-docs
14+
runs-on: ubuntu-latest
15+
if: github.event.repository.fork == false
16+
17+
permissions:
18+
contents: write
19+
pull-requests: write
20+
21+
steps:
22+
23+
- name: Checkout code
24+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
25+
with:
26+
filter: 'tree:0'
27+
persist-credentials: true # zizmor: ignore[artipacked] Needed to push commits
28+
show-progress: false
29+
30+
- name: Setup .NET SDK
31+
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0
32+
33+
- name: Update documentation
34+
id: update-docs
35+
shell: pwsh
36+
env:
37+
DOTNET_CLI_TELEMETRY_OPTOUT: true
38+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
39+
GIT_COMMIT_USER_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com'
40+
GIT_COMMIT_USER_NAME: 'github-actions[bot]'
41+
run: |
42+
$ErrorActionPreference = "Stop"
43+
$ProgressPreference = "SilentlyContinue"
44+
45+
dotnet tool restore
46+
dotnet mdsnippets
47+
48+
$GitStatus = (git status --porcelain)
49+
if ([string]::IsNullOrEmpty($GitStatus)) {
50+
Write-Output "No changes to commit."
51+
exit 0
52+
}
53+
54+
$BranchName = "docs/update-docs"
55+
"branchName=$BranchName" >> ${env:GITHUB_OUTPUT}
56+
57+
git config user.email ${env:GIT_COMMIT_USER_EMAIL} | Out-Null
58+
git config user.name ${env:GIT_COMMIT_USER_NAME} | Out-Null
59+
git remote set-url "${env:GITHUB_SERVER_URL}/${env:GITHUB_REPOSITORY}.git" | Out-Null
60+
git fetch origin | Out-Null
61+
git rev-parse --verify --quiet ("remotes/origin/" + $BranchName) | Out-Null
62+
63+
if ($LASTEXITCODE -eq 0) {
64+
Write-Output "Branch $BranchName already exists."
65+
exit 0
66+
}
67+
68+
git checkout -b $BranchName
69+
git add .
70+
git commit -m "Update the code-snippets in the documentation" -s
71+
git push -u origin $BranchName
72+
"updated-docs=true" >> ${env:GITHUB_OUTPUT}
73+
74+
- name: Create pull request
75+
if: steps.update-docs.outputs.updated-docs == 'true'
76+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
77+
env:
78+
BASE_BRANCH_NAME: ${{ github.event.repository.default_branch }}
79+
HEAD_BRANCH_NAME: ${{ steps.update-docs.outputs.branchName }}
80+
with:
81+
script: |
82+
const { repo, owner } = context.repo;
83+
const workflowUrl = `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
84+
const { data: pr } = await github.rest.pulls.create({
85+
title: 'Update the code-snippets in the documentation',
86+
owner,
87+
repo,
88+
head: process.env.HEAD_BRANCH_NAME,
89+
base: process.env.BASE_BRANCH_NAME,
90+
body: [
91+
'This PR updates the code-snippets in the documentation.',
92+
'',
93+
`This pull request was generated by [GitHub Actions](${workflowUrl}).`
94+
].join('\n')
95+
});
96+
core.notice(`Created pull request ${owner}/${repo}#${pr.number}: ${pr.html_url}`);

README.md

Lines changed: 156 additions & 96 deletions
Large diffs are not rendered by default.

Swashbuckle.AspNetCore.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<Project Path="test/WebSites/CustomDocumentSerializer/CustomDocumentSerializer.csproj" />
6666
<Project Path="test/WebSites/CustomUIConfig/CustomUIConfig.csproj" />
6767
<Project Path="test/WebSites/CustomUIIndex/CustomUIIndex.csproj" />
68+
<Project Path="test/WebSites/DocumentationSnippets/DocumentationSnippets.csproj" />
6869
<Project Path="test/WebSites/GenericControllers/GenericControllers.csproj" />
6970
<Project Path="test/WebSites/MinimalApp/MinimalApp.csproj" />
7071
<Project Path="test/WebSites/MinimalAppWithHostedServices/MinimalAppWithHostedServices.csproj" />

0 commit comments

Comments
 (0)