diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index ee984ed..96d0986 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -1,34 +1,13 @@ -name: Data Fetch +name: update-readme on: schedule: - - cron: "0 8 * * *" # Every day at 1am PDT + - cron: "0 8 * * *" # Runs every day at 08:00 AM UTC + workflow_dispatch: jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Check out repo - uses: actions/checkout@v5 - with: - token: ${{ secrets.WORKFLOW_PUSH_BOT_TOKEN }} - - - name: Set up Node.js - uses: actions/setup-node@v5 - - - name: Install npm packages - run: npm install - - - name: Update README with latest sponsor data - run: npm run build:readme - - - name: Setup Git - run: | - git config user.name "GitHub Actions Bot" - git config user.email "" - - - name: Save updated files - run: | - chmod +x ./tools/commit-readme.sh - ./tools/commit-readme.sh + update-readme: + uses: eslint/workflows/.github/workflows/update-readme.yml@main + secrets: + workflow_push_bot_token: ${{ secrets.WORKFLOW_PUSH_BOT_TOKEN }} diff --git a/.gitignore b/.gitignore index 3e758d1..af50801 100644 --- a/.gitignore +++ b/.gitignore @@ -65,4 +65,7 @@ dist package-lock.json # Build -src/build \ No newline at end of file +src/build + +# Automatically generated files by GitHub Actions workflow +tools/update-readme.js diff --git a/package.json b/package.json index 463bb98..adff14c 100644 --- a/package.json +++ b/package.json @@ -62,11 +62,11 @@ "build:cts": "node tools/build-cts.js", "build:rules": "node tools/build-rules.js", "build": "npm run build:rules && rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts", - "build:readme": "node tools/update-readme.js", "build:update-rules-docs": "node tools/update-rules-docs.js", "prepare": "npm run build", "pretest": "npm run build", "lint": "eslint", + "lint:fix": "eslint --fix", "fmt": "prettier --write .", "fmt:check": "prettier --check .", "test": "mocha \"tests/**/*.test.js\"", @@ -94,7 +94,6 @@ "eslint": "^9.35.0", "eslint-config-eslint": "^13.0.0", "eslint-plugin-eslint-plugin": "^6.3.2", - "got": "^14.4.2", "lint-staged": "^15.2.7", "mdast-util-from-markdown": "^2.0.2", "mocha": "^11.3.0", diff --git a/tools/commit-readme.sh b/tools/commit-readme.sh deleted file mode 100644 index dcbc986..0000000 --- a/tools/commit-readme.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -#------------------------------------------------------------------------------ -# Commits the data files if any have changed -#------------------------------------------------------------------------------ - -if [ -z "$(git status --porcelain)" ]; then - echo "Data did not change." -else - echo "Data changed!" - - # commit the result - git add README.md - git commit -m "docs: Update README sponsors" - - # push back to source control - git push origin HEAD -fi diff --git a/tools/update-readme.js b/tools/update-readme.js deleted file mode 100644 index 1c9aa22..0000000 --- a/tools/update-readme.js +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @fileoverview Script to update the README with sponsors details in all packages. - * - * node tools/update-readme.js - * - * @author Milos Djermanovic - */ - -//----------------------------------------------------------------------------- -// Requirements -//----------------------------------------------------------------------------- - -import { readFileSync, writeFileSync } from "node:fs"; -import got from "got"; - -//----------------------------------------------------------------------------- -// Data -//----------------------------------------------------------------------------- - -const SPONSORS_URL = - "https://raw.githubusercontent.com/eslint/eslint.org/main/includes/sponsors.md"; - -const README_FILE_PATH = "./README.md"; - -//----------------------------------------------------------------------------- -// Helpers -//----------------------------------------------------------------------------- - -/** - * Fetches the latest sponsors from the website. - * @returns {Promise} Prerendered sponsors markdown. - */ -async function fetchSponsorsMarkdown() { - return got(SPONSORS_URL).text(); -} - -//----------------------------------------------------------------------------- -// Main -//----------------------------------------------------------------------------- - -const allSponsors = await fetchSponsorsMarkdown(); - -// read readme file -const readme = readFileSync(README_FILE_PATH, "utf8"); - -let newReadme = readme.replace( - /[\s\S]*?/u, - `\n\n${allSponsors}\n`, -); - -// replace multiple consecutive blank lines with just one blank line -newReadme = newReadme.replace(/(?<=^|\n)\n{2,}/gu, "\n"); - -// output to the files -writeFileSync(README_FILE_PATH, newReadme, "utf8");