Skip to content

Add markdown linter (#3673) #10

Add markdown linter (#3673)

Add markdown linter (#3673) #10

name: update-documentation
on:
push:
branches: [ master ]
paths: [ '**/*.md', 'test/WebSites/DocumentationSnippets/**' ]
workflow_dispatch:
permissions: {}
jobs:
update-docs:
name: update-docs
runs-on: ubuntu-latest
if: github.event.repository.fork == false
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
filter: 'tree:0'
persist-credentials: true # zizmor: ignore[artipacked] Needed to push commits
show-progress: false
- name: Setup .NET SDK
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0
- name: Update documentation
id: update-docs
shell: pwsh
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
GIT_COMMIT_USER_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com'
GIT_COMMIT_USER_NAME: 'github-actions[bot]'
run: |
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
dotnet tool restore
dotnet mdsnippets
$GitStatus = (git status --porcelain)
if ([string]::IsNullOrEmpty($GitStatus)) {
Write-Output "No changes to commit."
exit 0
}
$BranchName = "docs/update-docs"
"branchName=$BranchName" >> ${env:GITHUB_OUTPUT}
git config user.email ${env:GIT_COMMIT_USER_EMAIL} | Out-Null
git config user.name ${env:GIT_COMMIT_USER_NAME} | Out-Null
git remote set-url "${env:GITHUB_SERVER_URL}/${env:GITHUB_REPOSITORY}.git" | Out-Null
git fetch origin | Out-Null
git rev-parse --verify --quiet ("remotes/origin/" + $BranchName) | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Output "Branch $BranchName already exists."
exit 0
}
git checkout -b $BranchName
git add .
git commit -m "Update the code-snippets in the documentation" -s
git push -u origin $BranchName
"updated-docs=true" >> ${env:GITHUB_OUTPUT}
- name: Create pull request
if: steps.update-docs.outputs.updated-docs == 'true'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
BASE_BRANCH_NAME: ${{ github.event.repository.default_branch }}
HEAD_BRANCH_NAME: ${{ steps.update-docs.outputs.branchName }}
with:
script: |
const { repo, owner } = context.repo;
const workflowUrl = `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const { data: pr } = await github.rest.pulls.create({
title: 'Update the code-snippets in the documentation',
owner,
repo,
head: process.env.HEAD_BRANCH_NAME,
base: process.env.BASE_BRANCH_NAME,
body: [
'This PR updates the code-snippets in the documentation.',
'',
`This pull request was generated by [GitHub Actions](${workflowUrl}).`
].join('\n')
});
core.notice(`Created pull request ${owner}/${repo}#${pr.number}: ${pr.html_url}`);