Skip to content

Commit

Permalink
create cron job to cache cycle data
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 21, 2024
1 parent 359f1d4 commit 5430dd9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 2 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/cacheCycles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: cache EOL data

on:
workflow_dispatch:
schedule:
# https://crontab.guru/#55_11,23_*_*_*
- cron: '55 11,23 * * *'

permissions:
contents: read

jobs:
cache:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: step-security/harden-runner@v1
with:
egress-policy: block
allowed-endpoints: >
github.com:443
nodejs.org:443
prod.api.stepsecurity.io:443
registry.npmjs.org:443
endoflife.date:443
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ljharb/actions/node/install@main

- run: node cacheCycles.mjs

- run: git checkout data

- run: git add -f out

- run: git mv -f out/* ./

- name: GIT commit and push all changed files
env:
CI_COMMIT_MESSAGE: '[cron] update data'
CI_COMMIT_AUTHOR: Github Actions
CI_COMMIT_EMAIL: [email protected]
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
git commit -a -m "${{ env.CI_COMMIT_MESSAGE }}"
git push
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# data output
out/
13 changes: 13 additions & 0 deletions cacheCycles.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mkdir, writeFile } from 'fs/promises';
import { join } from 'path';

import getCycles from './getCycles.mjs';

const cycles = await getCycles();

const outDir = join(process.cwd(), 'out');
const outFile = join(outDir, 'data.json');

await mkdir(outDir, { recursive: true });

await writeFile(outFile, JSON.stringify(cycles, null, '\t'));
14 changes: 14 additions & 0 deletions getCycles.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import getProducts from "./getProducts.mjs";

export default async function getCycles() {
const products = await getProducts();

return Object.fromEntries(
await Promise.all(
products.map(async (product) => [
product,
await fetch(`https://endoflife.date/api/${product}.json`).then(x => x.json())
]),
),
);
};
3 changes: 3 additions & 0 deletions getProducts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function getProjects() {
return fetch('https://endoflife.date/api/all.json').then(x => x.json());
};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"name": "eol-data",
"version": "0.0.0",
"description": "Cache and process EOL data",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -16,5 +15,8 @@
"bugs": {
"url": "https://github.com/herodevs/eol-data/issues"
},
"homepage": "https://github.com/herodevs/eol-data#readme"
"homepage": "https://github.com/herodevs/eol-data#readme",
"engines": {
"node": ">=22"
}
}

0 comments on commit 5430dd9

Please sign in to comment.