Skip to content

Commit

Permalink
Dispatch to todayilearned on push
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelazaroff committed Jan 5, 2024
1 parent 20a13a6 commit d6cecfb
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 466 deletions.
160 changes: 0 additions & 160 deletions .github/workflows/build.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Deploy
on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Dispatch to workflows
run: |
curl -H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \
--request POST \
--data '{}' https://api.github.com/repos/jakelazaroff/todayilearned/dispatches
81 changes: 81 additions & 0 deletions .github/workflows/readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# This script creates a nice README.md with an index of all TIL files.
# TIL files are Markdown files named anything other than README.md.
#
# The readme is split into two sections: the "header" and the "index",
# separated by three hyphens on their own line.
# Anything above the three hyphens is the "header" and will be kept as is.
# Anything below will be replaced by the "index".

name: Build README

on:
push:
branches:
- main

jobs:
readme:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v3
with:
fetch-depth: 0 # get full history or else it'll be overwritten

- name: Regenerate README
uses: actions/github-script@v6
with:
script: |
const { readFile, writeFile } = require("node:fs/promises");
console.log("Building index…");
// load readme
let readme = await readFile("README.md").then(file => file.toString());
// add header separator
const separator = "\n---\n";
const index = readme.indexOf(separator);
if (index === -1) readme += separator;
else readme = readme.substring(0, index + separator.length);
// collect entries
const files = await glob.create("./**/*.md").then(globber => globber.glob());
const entries = files
.filter(name => !name.endsWith("/README.md")) // exclude README.md
.sort()
.map(name => name.split("/").slice(-2));
// add summary
readme += `\n${entries.length} TILs so far:\n`;
// create category map
const categories = new Map();
for (const [category, file] of entries) {
const list = categories.get(category) || [];
categories.set(category, [...list, file]);
}
// create a section for each category
for (const [category, entries] of categories.entries()) {
// write category header
readme += `\n## ${category}\n\n`;
// write link for each file
for (const file of entries) {
const filepath = [category, file].join("/");
const contents = await readFile(filepath).then(file => file.toString());
const [, title] = contents.match(/^# (.+)$/m);
readme += `- [${title}](/${filepath})\n`;
}
}
// write readme
await writeFile("README.md", readme);
- name: Commit and push if README changed
run: |-
git config --global user.email "[email protected]"
git config --global user.name "tilbot"
git diff --quiet || git commit --all --message "Update README.md"
git push
Loading

0 comments on commit d6cecfb

Please sign in to comment.