Skip to content

Instantly share code, notes, and snippets.

@RichardKanshen
Last active January 2, 2025 17:01
Show Gist options
  • Save RichardKanshen/1b0a64f5333337faea1b7e02182d58a4 to your computer and use it in GitHub Desktop.
Save RichardKanshen/1b0a64f5333337faea1b7e02182d58a4 to your computer and use it in GitHub Desktop.
Update footer with new year
name: Update Year
# PLEASE I SWEAR TO GOD DO NOT USE AN ENDLESS SWITCH CASE OR AN ENDLESS TERNARY OR A FUCKING API TO GET THE YEAR
# EITHER JUST GET THE YEAR USING YOUR LANGUAGE'S DATE API
# OR IF YOUR LANGUAGE DOES NOT HAVE A LANGUAGE API (WHICH IF YOU ARE USING JAVASCRIPT, IT ABSOFUCKINGLUTELY HAS)
# USE THIS CRON TO UPDATE THE YEAR IN YOUR SOURCE CODE ON THE FIRST OF JANUARY
# SERIOUSLY YOU DO *NOT* NEED getfullyear.com (WHICH IS NOT EVEN WORKING AS OF WRITING THIS GIST 😭😭😭)
on:
schedule:
- cron: '0 0 1 1 *'
workflow_dispatch:
jobs:
update-year:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Run year update script
run: node update-year.js
- name: Commit and push changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add src/components/footer.tsx
git commit -m "Update year to $(date +'%Y')"
git push
const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, 'src', 'components', 'footer.tsx');
const fileContent = fs.readFileSync(filePath, 'utf8');
const currentYear = new Date().getFullYear().toString();
// Replace the year in the string
const updatedContent = fileContent.replace(
/{\/\*year\*\/\d{4}\/\*year\*\/}/,
`{/*year*/${currentYear}/*year*/}`
);
if (fileContent !== updatedContent) {
fs.writeFileSync(filePath, updatedContent, 'utf8');
console.log(`Year updated to ${currentYear}`);
} else {
console.log('No changes were made. The year is already up to date.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment