Skip to content

Commit

Permalink
Add automated job to create es yearly globals (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored Jul 3, 2024
1 parent f6b3978 commit df410c8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/es-yearly-globals.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Create ES yearly globals

on:
workflow_dispatch:
schedule:
# “At 00:00 on day-of-month 1 in July.” https://crontab.guru/#0_0_1_7_*
- cron: "0 0 1 7 *"

jobs:
update:
if: github.event_name != 'schedule' || github.repository == 'sindresorhus/globals'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install
- run: node scripts/create-yearly-es-globals.mjs
- run: npm run build
- uses: peter-evans/create-pull-request@v6
with:
commit-message: Add `es2026` globals
branch: automated-es-yearly-globals
branch-suffix: timestamp
title: Add `es2026` globals
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- run: npm run update
- uses: peter-evans/create-pull-request@v6
with:
commit-message: Update
commit-message: Update globals
branch: automated-update
branch-suffix: timestamp
title: Update globals
21 changes: 21 additions & 0 deletions scripts/create-yearly-es-globals.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import fs from 'node:fs';

const year = new Date().getFullYear();
const dataFile = new URL(`../data/es${year + 1}.mjs`, import.meta.url);
const workflowFile = new URL('../.github/workflows/es-yearly-globals.yml', import.meta.url);

fs.writeFileSync(
dataFile,
`export {default} from './es${year}.mjs';\n`,
);

fs.writeFileSync(
workflowFile,
fs.readFileSync(workflowFile, 'utf8')
.replaceAll(
`Add \`es${year + 1}\` globals`,
`Add \`es${year + 2}\` globals`,
),
);

console.log(`✅ es${year + 1} globals added, see you next year.`);

0 comments on commit df410c8

Please sign in to comment.