forked from polkadot-fellows/RFCs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
88 additions
and
97 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* mdBook relies on the creation of a special SUMMARY.md file | ||
* https://rust-lang.github.io/mdBook/format/summary.html | ||
* This script constructs the summary out of the available source files. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const summaryPath = "mdbook/src/SUMMARY.md" | ||
|
||
module.exports = async ({github, context}) => { | ||
fs.writeFileSync(summaryPath, "# Summary\n\n[Introduction](introduction.md)\n") // Starting point. | ||
|
||
const appendRfcsToSummary = (dirPath) => { | ||
for (const filename of fs.readdirSync(dirPath)) { | ||
if (!filename.endsWith(".md")) continue; | ||
const filePath = dirPath + filename | ||
const text = fs.readFileSync(filePath) | ||
const title = text.toString().split(/\n/) | ||
.find(line => line.startsWith("# ") || line.startsWith(" # ")) | ||
.replace("# ", "") | ||
// Relative path, without the src prefix (format required by mdbook) | ||
const relativePath = filePath.replace("mdbook/src/", "") | ||
fs.appendFileSync(summaryPath, `- [${title}](${relativePath})\n`) | ||
} | ||
} | ||
|
||
fs.appendFileSync(summaryPath, "\n---\n\n# Approved\n\n") | ||
appendRfcsToSummary("mdbook/src/approved/") | ||
|
||
fs.appendFileSync(summaryPath, "\n---\n\n# Newly Proposed\n\n") | ||
appendRfcsToSummary("mdbook/src/new/") | ||
|
||
fs.appendFileSync(summaryPath, "\n---\n\n# Proposed\n\n") | ||
appendRfcsToSummary("mdbook/src/proposed/") | ||
|
||
fs.appendFileSync(summaryPath, "\n---\n\n# Stale\n\n") | ||
appendRfcsToSummary("mdbook/src/stale/") | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* This scripts gathers source markdown files of approved and proposed RFCS in mdbook/src directory. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
|
||
module.exports = async ({github, context}) => { | ||
// Copy the approved (already-merged) RFCs markdown files, first adding a source link at the top and a TOC. | ||
for (const file of fs.readdirSync("text/")) { | ||
if (!file.endsWith(".md")) continue; | ||
const text = `[(source)](https://github.com/polkadot-fellows/RFCs/blob/main/text/${file})\n\n` | ||
+ "**Table of Contents**\n\n<\!-- toc -->\n" | ||
+ fs.readFileSync(`text/${file}`) | ||
fs.writeFileSync(`mdbook/src/approved/${file}`, text) | ||
} | ||
|
||
// Copy the proposed ones (created in previous steps). | ||
for (const status of ["new", "proposed", "stale"]) { | ||
const dirPath = `${status}-rfcs/` | ||
for (const filename of fs.readdirSync(dirPath)) { | ||
if (!filename.endsWith(".md")) continue; | ||
const text = "**Table of Contents**\n\n<\!-- toc -->\n" | ||
+ fs.readFileSync(dirPath + filename) | ||
// Source link is already there (with a link to PR). So we append here. | ||
fs.appendFileSync(`mdbook/src/${status}/${filename}`, text) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,43 +22,42 @@ jobs: | |
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const script = require('.github/download-rfc-prs.js') | ||
console.log(await script({github, context})) | ||
const script = require('.github/scripts/download-rfc-prs.js') | ||
await script({github, context}) | ||
# Create the proposed RFC markdown files from the patches gather in the step above. | ||
# Create the proposed RFC markdown files from the patches gathered in the step above. | ||
- run: | | ||
# We execute the patches, which results in markdown files created in patches/text/*.md | ||
for f in ./patches/*.patch; | ||
do | ||
[ -e "$f" ] || break | ||
git apply $f | ||
done; | ||
# We go over the created markdown files and move (append) them for mdbook to pick up. | ||
for status in {new,proposed,stale} | ||
do | ||
cd ${status}-rfcs/ | ||
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/$status/$f" | ||
done; | ||
cd - | ||
done; | ||
# Gather source files - approved (merged) files, and files created in the previous steps. | ||
- name: Gather markdown files into mdbook source directory | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const script = require('.github/scripts/gather-markdown-files.js') | ||
await script({github, context}) | ||
- name: Build the mdbook SUMMARY.md | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const script = require('.github/scripts/build-mdbook-summary.js') | ||
await script({github, context}) | ||
- name: Setup mdBook binary | ||
uses: peaceiris/actions-mdbook@adeb05db28a0c0004681db83893d56c0388ea9ea # v1.2.0 | ||
with: | ||
mdbook-version: '0.4.36' | ||
- name: Install dependencies | ||
run: | | ||
cargo install [email protected] | ||
# 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 | ||
run: | | ||
cd mdbook | ||
rm -rf ./book/ | ||
mdbook build --dest-dir ./book/ | ||
- name: Deploy to github pages | ||
uses: peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847 # v3.9.3 | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.