Skip to content

Commit

Permalink
Wiki: add outline (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
audunsolemdal authored Nov 29, 2023
1 parent a1bd347 commit c57d3e5
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/update-wiki.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: "Update Wiki"
on:
workflow_call: {}

jobs:
update-wiki:
runs-on: ubuntu-latest
name: "Update Wiki"
permissions:
contents: write
steps:
- uses: dawidd6/action-download-artifact@v2
with:
workflow: unused
run_id: ${{ github.event.client_payload.run_id }}
path: outputs

- name: Checkout wiki
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}.wiki
token: ${{ secrets.GITHUB_TOKEN }}
path: wiki
fetch-depth: 0
- name: Ensure wiki folder
run: "[ -d wiki/generated ] || mkdir wiki/generated"
- name: Display structure of retrieved files
run: ls -R

- uses: actions/github-script@v7
id: write-changes
with:
script: |
const { owner, repo } = context.repo;
const { readdir, readFile, writeFile } = require('fs').promises;
const utf8 = { encoding: 'utf-8' };
const msgParts = [];
const newPage = `<!--
Replace this comment with an introduction about the module!
Text and markdown up here will be preserved over time,
while the rest of the wiki page is generated from the release process.
-->
<!-- WARNING: Sections below this comment will be replaced and/or added to automatically. -->
`;
for (const folder of await readdir('outputs', { withFileTypes: true })) {
if (!folder.isDirectory()) continue;
const readText = (name) => readFile(name, utf8).then(x => x.trim());
const wikiPath = `wiki/generated/${folder.name}.md`;
const prevWiki = await readText(wikiPath)
.catch(err => err.code === 'ENOENT' ? newPage : Promise.reject(err));
if (!prevWiki) console.warn('Starting new wiki page for', folder.name);
const newVersion = await readText(`outputs/${folder.name}/new-version.txt`);
const docs = await readText(`outputs/${folder.name}/documentation.md`);
const changelog = await readText(`outputs/${folder.name}/changelog.md`);
let newWiki = prevWiki;
if (!newWiki.match(/^<!-- BEGIN DOCS -->$/m)) {
newWiki += `\n<!-- BEGIN DOCS -->\n<!-- END DOCS -->\n`;
}
newWiki = newWiki.replace(/^<!-- BEGIN DOCS -->$[^]+^<!-- END DOCS -->$/m,
`<!-- BEGIN DOCS -->\n${docs}\n<!-- END DOCS -->`);
if (!newWiki.match(/^<!-- CHANGELOG MARKER -->$/m)) {
newWiki += `\n\n# Changelog\n<!-- CHANGELOG MARKER -->\n`;
}
const changelogHeader = `## ${newVersion} (${new Date().toISOString().split('T')[0]})`
newWiki = newWiki.replace(/^<!-- CHANGELOG MARKER -->$/m,
`<!-- CHANGELOG MARKER -->\n${changelogHeader}\n${changelog}\n`);
await writeFile(wikiPath, newWiki, utf8);
msgParts.push(`${folder.name} @ ${newVersion}`);
console.log(`Updated ${folder.name} @ ${newVersion}`);
}
return msgParts.join(', ');
result-encoding: string

- name: Push changes to wiki
working-directory: wiki
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
git commit -m "${{ steps.write-changes.outputs.result }}"
git push

0 comments on commit c57d3e5

Please sign in to comment.