Skip to content

Fix dotnet test

Fix dotnet test #65

name: on-push-do-docs
on:
push:
branches: [main]
paths: [ "src/Snippets/**" ]
workflow_dispatch:
permissions: {}
jobs:
update-docs:
name: update-docs
runs-on: ubuntu-latest
steps:
- name: Generate GitHub application token
id: generate-application-token
uses: peter-murray/workflow-application-token-action@8e1ba3bf1619726336414f1014e37f17fbadf1db # v2.1.0
with:
application_id: ${{ secrets.POLLY_UPDATER_BOT_APP_ID }}
application_private_key: ${{ secrets.POLLY_UPDATER_BOT_KEY }}
permissions: "contents:write, pull_requests:write"
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
token: ${{ steps.generate-application-token.outputs.token }}
- name: Setup .NET SDK
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
- name: Update documentation
id: update-docs
shell: pwsh
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
run: |
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
dotnet tool restore
dotnet mdsnippets
$GitStatus = (git status --porcelain)
if ([string]::IsNullOrEmpty($GitStatus)) {
Write-Host "No changes to commit."
exit 0
}
$TimeStamp = Get-Date -Format "yyyy-MM-dd-HH-mm"
$BranchName = "docs/update-docs-$TimeStamp"
"branchName=$BranchName" >> $env:GITHUB_OUTPUT
$GitEmail = "138034000+polly-updater-bot[bot]@users.noreply.github.com"
$GitUser = "polly-updater-bot[bot]"
git config user.email $GitEmail | Out-Null
git config user.name $GitUser | Out-Null
git remote set-url "${{ github.server_url }}/${{ 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-Host "Branch $BranchName already exists."
exit 0
}
git checkout -b $BranchName
git add .
git commit -m "Update the code-snippets in the documentation"
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@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ steps.generate-application-token.outputs.token }}
script: |
const { repo, owner } = context.repo;
const workflowUrl = `${{ github.server_url }}/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const branchName = "${{ steps.update-docs.outputs.branchName }}";
const result = await github.rest.pulls.create({
title: 'Update the code-snippets in the documentation',
owner,
repo,
head: branchName,
base: 'main',
body: [
'This PR updates the code-snippets in the documentation.',
'',
`This pull request was generated by [GitHub Actions](${workflowUrl}).`
].join('\n')
});