Skip to content

Generate README

Generate README #1099

name: Generate README
concurrency:
group: generate-readme-${{ github.event.number }}
cancel-in-progress: true
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
schedule:
- cron: "31 1,12 * * *"
push:
branches:
- main
jobs:
generate-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup Deno
uses: denolib/[email protected]
with:
deno-version: v1.44
- name: Download indexes
run: |
URLS=(
https://raw.githubusercontent.com/nanlabs/frontend-reference/main/examples.json
https://raw.githubusercontent.com/nanlabs/devops-reference/main/examples.json
https://raw.githubusercontent.com/nanlabs/backend-reference/main/examples.json
)
# Download files preventing duplicated names (e.g. examples.json)
i=0
for url in "${URLS[@]}"; do
filename=$(basename "$url")
extension="${filename##*.}"
filename="${filename%.*}"
filename="$filename-$i.$extension"
curl -s "$url" -o "$filename"
i=$((i + 1))
done
- name: Generate README
run: |
# Get the list of examples previously downloaded
EXAMPLES=$(ls examples-*.json)
# Remove previous examples.json
rm -f examples.json
# Generate the JSON file
./tools/readme-generator/main.ts --json $(echo $EXAMPLES) > examples-list.json
# Transform the JSON file from the format [{...}, {...}] to
# {
# "$schema": "https://raw.githubusercontent.com/nanlabs/awesome-nan/main/examples.schema.json",
# "list": [{...}, {...}]
# }
# and pretty print it
echo "{ \"\$schema\": \"https://raw.githubusercontent.com/nanlabs/awesome-nan/main/examples.schema.json\", \"list\": $(cat examples-list.json) }" | jq . > examples.json
# Generate the README
./tools/readme-generator/main.ts README.md.tmpl examples.json
# Remove the downloaded files
rm examples-*.json
- name: Run prettier
run: npx prettier --write README.md
- name: Run markdownlint
uses: articulate/actions-markdownlint@v1
with:
fix: true
files: README.md
- name: Run Awesome Lint
run: npx awesome-lint
- name: Commit changes
uses: EndBug/add-and-commit@v7
with:
message: "Update README.md and examples list"