Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RFC book #1

Merged
merged 39 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8fdf621
Add mdbook
rzadp Nov 24, 2023
d314c21
Run on CI
rzadp Nov 24, 2023
c44c4fc
Run without token
rzadp Nov 24, 2023
db3377a
Remove url for now
rzadp Nov 24, 2023
e984f1c
built-in token
rzadp Nov 24, 2023
c95e223
Permissions
rzadp Nov 24, 2023
53c2105
preview
rzadp Nov 24, 2023
a999f91
Debug
rzadp Nov 24, 2023
4e3b446
Try it out
rzadp Nov 24, 2023
b4f099e
try
rzadp Nov 24, 2023
5992966
path
rzadp Nov 24, 2023
862d324
Title
rzadp Nov 24, 2023
716467e
Fix grep
rzadp Nov 24, 2023
3702844
html url
rzadp Nov 24, 2023
13262fd
Comments
rzadp Nov 24, 2023
01502e3
Fixes
rzadp Nov 24, 2023
639da93
Try adding images
rzadp Nov 24, 2023
95af365
Start introducing themes
rzadp Nov 28, 2023
0806a5d
typo
rzadp Nov 28, 2023
5bdc628
gitignore
rzadp Nov 28, 2023
5e127a9
rust-custom (default from the start)
rzadp Nov 28, 2023
40ac944
Move it
rzadp Nov 28, 2023
42f04e9
Add fonts
rzadp Nov 28, 2023
275c775
Fun Polkadot brand colors
rzadp Nov 28, 2023
abbd5b0
Fails without it
rzadp Nov 28, 2023
722c8a4
Try to copy fonts
rzadp Nov 28, 2023
709fa65
fonts
rzadp Nov 28, 2023
59e58d3
shebang fix
rzadp Nov 28, 2023
fad5fc9
-e
rzadp Nov 28, 2023
e5c7d5c
Theme changes
rzadp Nov 28, 2023
d500d69
GHA name
rzadp Nov 28, 2023
05ecb88
ci rerun
rzadp Nov 28, 2023
398b1f5
ci rerun
rzadp Nov 28, 2023
2047f16
ci rerun
rzadp Nov 28, 2023
3c5b8c3
Duplicate info
rzadp Nov 28, 2023
9eac65d
Change publish dir location
rzadp Nov 29, 2023
66d6918
Extract script
rzadp Nov 30, 2023
67f0344
Remove numbered labels (because RFCs have numbers of their own
rzadp Nov 30, 2023
c744bd6
Add source to approved as well
rzadp Nov 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/download-rfc-prs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const fs = require('fs')

module.exports = async ({github, context}) => {
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"
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.
*/
fs.writeFileSync(
`mdbook/src/proposed/${rfcFile.filename.replace('text/','')}`,
`[(source)](${pr.html_url})\n\n`
)
}
}
65 changes: 65 additions & 0 deletions .github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: mdBook

on:
push:
branches:
- main
- rzadp/rfc-book

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional or a left over of testing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional for now - as long as we keep it in paritytech-stg or paritytech.
I'll remove it (and uncomment cron) before making a PR to fellows.

# 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 script = require('.github/download-rfc-prs.js')
console.log(await script({github, context}))
# 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: ./mdbook/book
github_token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions mdbook/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
approved/
proposed/
book/
SUMMARY.md
8 changes: 8 additions & 0 deletions mdbook/SUMMARY_preface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Summary

[Introduction](introduction.md)

---

# Approved

53 changes: 53 additions & 0 deletions mdbook/book.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail
cd $(dirname ${BASH_SOURCE[0]})

# This script will gatcher two sets of markdown files:
# - approved RFCs (already merged)
# - proposed RFCs (pending PRs)
mkdir -p src/{approved,proposed}

# mdBook relies on the creation of a special SUMMARY.md file
# https://rust-lang.github.io/mdBook/format/summary.html
cat SUMMARY_preface.md > src/SUMMARY.md

# Copy the approved RFCs markdown files, first adding a source link at the top.
cd ../text/
for f in *.md;
do
[ -e "$f" ] || break
echo -e "[(source)](https://github.com/polkadot-fellows/RFCs/blob/main/text/$f)\n" > "../mdbook/src/approved/$f"
cat "$f" >> "../mdbook/src/approved/$f"
done
cd -

# This will append links to all RFCs into the SUMMARY.md,
# forming a sidebar of all contents.
append_rfc_to_summary () {
local file="$1"
local title=$(head -n 3 $file | grep '# ') # Grab the title from the contents of the file
local title=${title#\# } # Remove the "# " prefix
local path=${file#./src/} # Relative path, without the src prefix (format required by mdbook)
echo "- [$title]($path)" >> src/SUMMARY.md;
}

for f in ./src/approved/*.md;
do
[ -e "$f" ] || break
append_rfc_to_summary "$f"
done

# Add a section header, and start adding proposed RFCs.
echo -e "\n---\n\n# Proposed\n\n" >> src/SUMMARY.md

for f in ./src/proposed/*.md;
do
[ -e "$f" ] || break
append_rfc_to_summary "$f"
done

echo -e "Preview of the generated SUMMARY.md:\n"
cat src/SUMMARY.md

rm -rf ./book/
mdbook build --dest-dir ./book/
18 changes: 18 additions & 0 deletions mdbook/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[book]
title = "Polkadot Fellowship RFCs"
description = "An online book of RFCs approved or proposed within the Polkadot Fellowship."
src = "src"

[build]
create-missing = false

[output.html]
additional-css = ["theme/polkadot.css"]
default-theme = "polkadot"
preferred-dark-theme = "polkadot"
copy-fonts = true
no-section-label = true

[output.html.font]
enable = true
woff = true
1 change: 1 addition & 0 deletions mdbook/src/images/Polkadot_Logo_Horizontal_Pink_Black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mdbook/src/images/github-mark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions mdbook/src/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p><img width="30%" src="images/Polkadot_Logo_Horizontal_Pink_Black.svg" alt="Polkadot logo" /></p>

# Introduction

This book contains the Polkadot Fellowship Requests for Comments (RFCs)
detailing proposed changes to the technical implementation of the Polkadot network.

<p><img width="2%" src="images/github-mark.svg" alt="GitHub logo" />&nbsp;<a href="https://github.com/polkadot-fellows/RFCs/">polkadot-fellows/RFCs</a></p>
Binary file added mdbook/theme/fonts/Unbounded-Black.woff2
Binary file not shown.
Binary file added mdbook/theme/fonts/Unbounded-Bold.woff2
Binary file not shown.
Binary file added mdbook/theme/fonts/Unbounded-ExtraLight.woff2
Binary file not shown.
Binary file added mdbook/theme/fonts/Unbounded-Light.woff2
Binary file not shown.
Binary file added mdbook/theme/fonts/Unbounded-Medium.woff2
Binary file not shown.
Binary file added mdbook/theme/fonts/Unbounded-Regular.woff2
Binary file not shown.
42 changes: 42 additions & 0 deletions mdbook/theme/fonts/fonts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@font-face {
font-family:Unbounded;
src:url(./Unbounded-ExtraLight.woff2) format("woff2");
font-weight:200;
font-style:normal;
font-display:block
}
@font-face {
font-family:Unbounded;
src:url(./Unbounded-Light.woff2) format("woff2");
font-weight:300;
font-style:normal;
font-display:block
}
@font-face {
font-family:Unbounded;
src:url(./Unbounded-Regular.woff2) format("woff2");
font-weight:400;
font-style:normal;
font-display:block
}
@font-face {
font-family:Unbounded;
src:url(./Unbounded-Medium.woff2) format("woff2");
font-weight:500;
font-style:normal;
font-display:block
}
@font-face {
font-family:Unbounded;
src:url(./Unbounded-Bold.woff2) format("woff2");
font-weight:700;
font-style:normal;
font-display:block
}
@font-face {
font-family:Unbounded;
src:url(./Unbounded-Black.woff2) format("woff2");
font-weight:900;
font-style:normal;
font-display:block
}
Loading