cron + git

This commit is contained in:
Jan Andrle 2024-06-28 14:01:41 +02:00
parent f33b0fa3c2
commit dcf1a45684
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
2 changed files with 18 additions and 5 deletions

View File

@ -1,8 +1,8 @@
name: Update RSS name: Collect month data
on: on:
workflow_dispatch: workflow_dispatch:
schedule: schedule:
- cron: '39 19 * * *' # daily at 19:39 Prague - cron: '0 12 1 * *' # At 12:00 Prague on the first day of the month
jobs: jobs:
update-rss: update-rss:
@ -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.mjs pull --git - run: npx nodejsscript mastodonCzStats.js --git

View File

@ -9,7 +9,7 @@ $.api("", true)
.version(version) .version(version)
.describe(description) .describe(description)
.option("--git", "Commit changes to git") .option("--git", "Commit changes to git")
.action(async function main(){ .action(async function main({ git: is_git }){
let stats= []; let stats= [];
for(const instance of instances_cz_pre){ for(const instance of instances_cz_pre){
echo.use("-R", "Shromažďuji instance: " + instance); echo.use("-R", "Shromažďuji instance: " + instance);
@ -28,11 +28,24 @@ $.api("", true)
instances_cz: stats.sort((a, b)=> b.registrations-a.registrations), instances_cz: stats.sort((a, b)=> b.registrations-a.registrations),
sum: stats.reduce((acc, stats) => sumStats([acc, stats]), { statuses: 0, logins: 0, registrations: 0, mau: 0, user_count: 0 }) sum: stats.reduce((acc, stats) => sumStats([acc, stats]), { statuses: 0, logins: 0, registrations: 0, mau: 0, user_count: 0 })
}; };
echo(JSON.stringify(out, null, " ")).to("./mastodonCzStats.json"); echo(JSON.stringify(out, null, " ")).to(store);
if(is_git) gitCommit([ store ], "cron");
$.exit(0); $.exit(0);
}) })
.parse(); .parse();
function gitCommit(files, des= "not specified"){
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`;
}
async function* collectStats(instances, weeks = 1) { async function* collectStats(instances, weeks = 1) {
for(const instance of instances){ for(const instance of instances){
const { stats, mau, user_count }= await fetchInstanceStats(instance).catch(e=> ({})); const { stats, mau, user_count }= await fetchInstanceStats(instance).catch(e=> ({}));