Compare commits

...

8 Commits

Author SHA1 Message Date
df82405ed8 Updates workflow (more functional and straightforward)
All checks were successful
Update RSS / update-rss (push) Successful in 5m16s
2024-06-27 16:35:15 +02:00
Bot
39bb5ef62d Updated by bot – pull 2024-06-27 16:34:42 +02:00
Bot
4bbd88a563 Updated by bot – pull 2024-06-27 16:32:57 +02:00
0054ceb6f2 cron daily at 19:39 Prague 2024-06-27 11:09:58 +02:00
add7993460 cron daily at 10:47 Prague 2024-06-27 11:03:28 +02:00
db2af48953 🐛 cron at 9:05 GMT 2024-06-27 11:00:30 +02:00
597e21895a 🐛 adds commit, fixes cron
All checks were successful
Update RSS / update-rss (push) Successful in 5m14s
2024-06-27 10:52:51 +02:00
837cea046d 👮 better cron name
Some checks failed
Update RSS / update-rss (push) Failing after 6m16s
2024-06-26 15:56:05 +02:00
3 changed files with 41 additions and 15 deletions

View File

@ -2,10 +2,10 @@ name: Update RSS
on: on:
workflow_dispatch: workflow_dispatch:
schedule: schedule:
- cron: '0 3 * * *' # daily at 3am - cron: '39 19 * * *' # daily at 19:39 Prague
jobs: jobs:
Explore-Gitea-Actions: update-rss:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: https://gitea.com/actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - uses: https://gitea.com/actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
@ -14,4 +14,4 @@ jobs:
node-version: lts/* node-version: lts/*
cache: 'npm' cache: 'npm'
- run: npm ci - run: npm ci
- run: npx nodejsscript cli.js pull - run: npx nodejsscript cli.mjs pull --git

48
cli.mjs
View File

@ -20,20 +20,44 @@ const { version, description }= s.cat("package.json").xargs(JSON.parse);
* @property {Article[]} articles * @property {Article[]} articles
* @property {Drop[]} drops * @property {Drop[]} drops
* */ * */
/**
* @typedef {Object} State
* @property {Sitemap} json
* @property {string[]} changed Changed files
* */
$.api() $.api()
.version(version) .version(version)
.describe(description) .describe(description)
.command("pull", "Update article list") .command("pull", "Update article list")
.action(async function pull(){ .option("--git", "Update git repository")
const json= await sitemap(); .action(async function pull({ git: is_git= false }){
toRSS(json); const { changed }= await sitemap().then(toRSS);
echo("Changed files:", changed.length ? changed.join(", ") : "—");
if(is_git) gitCommit(changed, "pull");
$.exit(0); $.exit(0);
}) })
.parse(); .parse();
/** @param {Sitemap} json */ function gitCommit(files, des= "not specified"){
async function toRSS(json){ if(!files.length || !s.run`git diff --numstat`.trim())
return echo("Nothig todo");
echo("Diff to save");
s.run`git config user.name "Bot"`;
s.run`git config user.email "${"zc.murtnec@naj.elrdna".split("").reverse().join("")}"`;
s.run`git add ${files}`;
s.run`git commit -m "Updated by bot ${des}"`;
s.run`git push`;
s.run`git config --remove-section user`;
}
/**
* @param {State} state
* @returns {State} state
* */
async function toRSS({ json, changed }){
if(!changed.length) return { json, changed };
const path= "rss.xml"; const path= "rss.xml";
const host= "https://pagenotfound.cz"; const host= "https://pagenotfound.cz";
const articles= json.articles.map(function({ title, perex, author, loc, drop }){ const articles= json.articles.map(function({ title, perex, author, loc, drop }){
@ -61,20 +85,22 @@ async function toRSS(json){
"</channel>", "</channel>",
"</rss>" "</rss>"
].join("\n")).to(path); ].join("\n")).to(path);
return { json, changed: [...changed, path] };
} }
import { JSDOM } from "jsdom"; import { JSDOM } from "jsdom";
/** @returns {Promise<State>} */
async function sitemap(){ async function sitemap(){
const path= "sitemap.json"; const path= "sitemap.json";
/** @type {Sitemap} */ /** @type {Sitemap} */
const json= s.test("-f", path) ? s.cat(path).xargs(JSON.parse) : { drops: [], articles: [] }; const json= s.test("-f", path) ? s.cat(path).xargs(JSON.parse) : { drops: [], articles: [] };
const [ article_last= { drop: "" } ]= json.articles;
await syncDrops(json); await syncDrops(json);
const [ { drop: drop_last } ]= json.drops; const [ { drop: drop_last } ]= json.drops;
if(drop_last === article_last.drop) return json; const [ article_last= { drop: "" } ]= json.articles;
if(drop_last === article_last.drop) return { json, changed: [] };
const res= await fetch(url_drops+drop_last); const res= await fetch(url_drops+drop_last);
if(res.status !== 200) return; if(res.status !== 200) return { json, changed: [] };
const dom= new JSDOM(await res.text()); const dom= new JSDOM(await res.text());
const diff= []; const diff= [];
for(const article of dom.window.document.querySelectorAll("article")){ for(const article of dom.window.document.querySelectorAll("article")){
@ -89,7 +115,7 @@ async function sitemap(){
json.articles.unshift(...diff); json.articles.unshift(...diff);
s.echo(JSON.stringify(json, null, "\t")).to(path); s.echo(JSON.stringify(json, null, "\t")).to(path);
return json; return { json, changed: [ path ] };
} }
/** @param {Sitemap} json */ /** @param {Sitemap} json */
async function syncDrops(json){ async function syncDrops(json){

View File

@ -1,6 +1,6 @@
{ {
"name": "pagenotfound-cli", "name": "pagenotfound-cli",
"version": "1.0.0", "version": "1.1.0",
"description": "Utility primary for generating RSS feed for Pagenotfound", "description": "Utility primary for generating RSS feed for Pagenotfound",
"bin": "cli.js", "bin": "cli.js",
"scripts": { "scripts": {