Convert and publish #11
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Convert all Windows protocol specs to markdown, build a clean publish tree, | |
| # 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: | |
| # Required for force-pushing to the orphaned 'publish' branch. | |
| permissions: | |
| contents: write | |
| jobs: | |
| convert-and-publish: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install OpenXML module | |
| shell: pwsh | |
| run: | | |
| Set-PSRepository -Name PSGallery -InstallationPolicy Trusted | |
| Install-Module -Name OpenXML -Force -Scope CurrentUser | |
| - name: Import module and convert all specs | |
| shell: pwsh | |
| working-directory: ${{ github.workspace }} | |
| run: | | |
| Import-Module .\AwakeCoding.OpenSpecs -Force | |
| Get-OpenSpecCatalog -IncludeReferenceSpecs | | |
| Save-OpenSpecDocument -Format DOCX -OutputPath ./downloads-convert -Force | | |
| Where-Object { $_.Status -in 'Downloaded', 'Exists' } | | |
| Convert-OpenSpecToMarkdown -OutputPath ./converted-specs -Force -Parallel -ThrottleLimit 4 | |
| - name: Repair broken links (post-conversion pass) | |
| shell: pwsh | |
| working-directory: ${{ github.workspace }} | |
| run: .\scripts\Repair-AllBrokenLinks.ps1 -Path ./converted-specs | |
| - name: Build publish directory and index | |
| shell: pwsh | |
| working-directory: ${{ github.workspace }} | |
| run: | | |
| Import-Module .\AwakeCoding.OpenSpecs -Force | |
| $converted = Join-Path $PWD 'converted-specs' | |
| $publish = Join-Path $PWD 'publish' | |
| New-Item -Path $publish -ItemType Directory -Force | Out-Null | |
| Get-ChildItem -LiteralPath $converted -Directory | ForEach-Object { | |
| $name = $_.Name | |
| $md = Join-Path $_.FullName "$name.md" | |
| if (-not (Test-Path -LiteralPath $md)) { $md = Join-Path $_.FullName 'README.md' } | |
| if (-not (Test-Path -LiteralPath $md)) { $md = Join-Path $_.FullName 'index.md' } | |
| if (-not (Test-Path -LiteralPath $md)) { return } | |
| $dest = Join-Path $publish $name | |
| New-Item -Path $dest -ItemType Directory -Force | Out-Null | |
| Copy-Item -LiteralPath $md -Destination $dest -Force | |
| $media = Join-Path $_.FullName 'media' | |
| if (Test-Path -LiteralPath $media -PathType Container) { | |
| Copy-Item -LiteralPath $media -Destination $dest -Recurse -Force | |
| } | |
| } | |
| Update-OpenSpecIndex -Path $publish -Title 'Microsoft Open Specifications' | |
| - name: Zip publish contents | |
| shell: pwsh | |
| working-directory: ${{ github.workspace }} | |
| run: | | |
| Compress-Archive -Path .\publish\* -DestinationPath .\publish.zip -Force | |
| - name: Upload publish artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: publish | |
| path: publish.zip | |
| - name: Push to orphaned publish branch | |
| shell: pwsh | |
| working-directory: publish | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| $RemoteRepo = "https://${Env:GITHUB_ACTOR}:${Env:GITHUB_TOKEN}@github.com/${Env:GITHUB_REPOSITORY}.git" | |
| 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" |