Skip to content

Convert and publish #42

Convert and publish

Convert and publish #42

# Convert all Windows protocol specs to markdown, build a clean publish tree,
# open a PR for the skill corpus, then force-push it to an orphaned 'publish'
# branch (e.g. for GitHub Pages).
# Conversion runs in parallel (PowerShell 7) to reduce run time.
name: Convert and publish
on:
workflow_dispatch:
schedule:
# Weekly refresh: Mondays at 08:00 UTC.
- cron: '0 8 * * 1'
# Required for force-pushing to the orphaned 'publish' branch and opening the
# generated corpus PR against master.
permissions:
contents: write
pull-requests: write
concurrency:
group: convert-and-publish
cancel-in-progress: false
jobs:
convert-and-publish:
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install oxipng
shell: pwsh
run: |
$release = Invoke-RestMethod -Uri 'https://api.github.com/repos/oxipng/oxipng/releases/latest'
$asset = $release.assets | Where-Object { $_.name -match 'x86_64-pc-windows-msvc\.zip$' } | Select-Object -First 1
if (-not $asset) {
throw 'Could not find Windows x86_64 zip asset in latest oxipng release.'
}
$zipPath = Join-Path $env:RUNNER_TEMP $asset.name
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $zipPath
$extractPath = Join-Path $env:RUNNER_TEMP 'oxipng'
if (Test-Path -LiteralPath $extractPath) {
Remove-Item -LiteralPath $extractPath -Recurse -Force
}
Expand-Archive -LiteralPath $zipPath -DestinationPath $extractPath -Force
$binPath = Get-ChildItem -LiteralPath $extractPath -Recurse -File -Filter 'oxipng.exe' | Select-Object -First 1
if (-not $binPath) {
throw 'oxipng.exe was not found after extracting release archive.'
}
$binDir = Split-Path -Path $binPath.FullName -Parent
$env:PATH = "$binDir;$env:PATH"
Add-Content -Path $env:GITHUB_PATH -Value $binDir
& $binPath.FullName --version
- name: Install OpenXML module
shell: pwsh
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name OpenXML -Force -Scope CurrentUser
- name: Build publish tree and windows-protocols.zip
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
if (Test-Path -LiteralPath .\publish) {
Remove-Item -LiteralPath .\publish -Recurse -Force
}
.\scripts\Build-Publish.ps1 -PublishPath publish -ThrottleLimit 4 -AllowPartial
- name: Upload publish artifact
uses: actions/upload-artifact@v7
with:
name: publish
path: windows-protocols.zip
- name: Stage downloadable bundle in publish tree
shell: pwsh
working-directory: ${{ github.workspace }}
run: Copy-Item -LiteralPath .\windows-protocols.zip -Destination .\publish\windows-protocols.zip -Force
- name: Push to orphaned publish branch
shell: pwsh
working-directory: ${{ github.workspace }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$PublishWorktree = Join-Path $Env:RUNNER_TEMP 'windows-protocols-publish'
if (Test-Path -LiteralPath $PublishWorktree) {
Remove-Item -LiteralPath $PublishWorktree -Recurse -Force
}
New-Item -Path $PublishWorktree -ItemType Directory -Force | Out-Null
Get-ChildItem -LiteralPath .\publish -Force |
Copy-Item -Destination $PublishWorktree -Recurse -Force
$RemoteRepo = "https://${Env:GITHUB_ACTOR}:${Env:GITHUB_TOKEN}@github.com/${Env:GITHUB_REPOSITORY}.git"
Push-Location $PublishWorktree
try {
git init
git config user.name "GitHub Actions"
git config user.email "github-actions-bot@users.noreply.github.com"
git add .
git commit -m "Publish converted Open Specs markdown (${Env:GITHUB_REPOSITORY})"
git push --force "${RemoteRepo}" "HEAD:publish"
}
finally {
Pop-Location
}
- name: Replace skill corpus from publish bundle
shell: pwsh
working-directory: ${{ github.workspace }}
run: .\scripts\Replace-WindowsProtocolsCorpus.ps1 -ZipPath .\windows-protocols.zip -SkillPath .\skills\windows-protocols
- name: Create corpus update pull request
id: cpr
uses: peter-evans/create-pull-request@v8
with:
token: ${{ secrets.AUTO_MERGE_TOKEN }}
add-paths: |
skills/windows-protocols
base: master
branch: automation/windows-protocols-weekly
commit-message: Update Windows Protocols corpus
title: Update Windows Protocols corpus
body: |
Automated weekly refresh of the converted Windows Protocols corpus used by the `windows-protocols` skill.
Generated by the scheduled `Convert and publish` workflow.
delete-branch: true
- name: Merge corpus update pull request
if: steps.cpr.outputs.pull-request-number != ''
env:
GH_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }}
run: gh pr merge "${{ steps.cpr.outputs.pull-request-number }}" --squash --admin --delete-branch