This file contains 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
on: | |
push: | |
branches: | |
- main | |
- rzadp/rfc-book | |
# schedule: | |
# - cron: "0 0 * * *" # Once a day | |
jobs: | |
mdbook: | |
runs-on: ubuntu-latest | |
permissions: | |
# For writing to gh-pages branch. | |
contents: write | |
steps: | |
- name: Checkout this repo | |
uses: actions/checkout@v3 | |
- name: Precreate necessary directories | |
run: | | |
mkdir -p mdbook/src/proposed | |
mkdir -p patches/text | |
- name: Download all proposed RFCs (open PRs) | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const owner = 'polkadot-fellows' | |
const repo = 'RFCs' | |
const prs = await github.paginate(github.rest.pulls.list, {owner, repo, state: 'open'}) | |
/* | |
The open PRs are potential proposed RFCs. | |
We iterate over them and filter those that include a new RFC markdown file. | |
*/ | |
for (const pr of prs) { | |
const addedMarkdownFiles = ( | |
await github.rest.pulls.listFiles({ | |
owner, repo, | |
pull_number: pr.number, | |
}) | |
).data.filter( | |
(file) => file.status === "added" && file.filename.startsWith("text/") && file.filename.includes(".md"), | |
); | |
if (addedMarkdownFiles.length !== 1) continue; | |
const [rfcFile] = addedMarkdownFiles; | |
/* | |
The git patches are the only way to get the RFC contents without additional API calls. | |
The alternative would be to download the file contents, one call per PR. | |
The patch in this object is not a full patch with valid syntax, so we need to modify it a bit - add a header. | |
*/ | |
// This header will cause the patch to create a file in patches/text/*.md. | |
const patch = `--- /dev/null\n+++ b/patches/${rfcFile.filename}\n` + rfcFile.patch + "\n" | |
require('fs').writeFileSync(`patches/${rfcFile.filename}.patch`, patch) | |
/* | |
We want to link the proposed RFCs to their respective PRs. | |
While we have it, we add a link to the source to markdown files. | |
Later, we will append the text of the RFCs to those files. | |
*/ | |
require('fs').writeFileSync( | |
`mdbook/src/proposed/${rfcFile.filename.replace('text/','')}`, | |
`[(source)](${pr.html_url})\n\n` | |
) | |
} | |
# Create the proposed RFC markdown files from the patches gather in the step above. | |
- run: | | |
# We execute the patches, which results in markdown files created in patches/text/*.md | |
for f in ./patches/text/*.patch; | |
do | |
[ -e "$f" ] || break | |
git apply $f | |
done; | |
cd patches/text/ | |
# We go over the created markdown files and move them for mdbook to pick up. | |
for f in *.md | |
do | |
[ -e "$f" ] || break | |
# We append the contents - because the links to source already exist there at this point. | |
cat $f >> "../../mdbook/src/proposed/$f" | |
done; | |
- name: Setup mdBook binary | |
uses: peaceiris/actions-mdbook@adeb05db28a0c0004681db83893d56c0388ea9ea # v1.2.0 | |
with: | |
mdbook-version: '0.4.35' | |
# This will: | |
# - gather the proposed RFCs (constructed in the steps above). | |
# - gather the approved RFCs (they exist in this repo in text/ directory) | |
# - generate the mdbook out of it | |
- name: Generate the mdbook | |
run: mdbook/book.sh | |
- name: Deploy to github pages | |
uses: peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847 # v3.9.3 | |
with: | |
publish_dir: ./book | |
github_token: ${{ secrets.GITHUB_TOKEN }} |