diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index 2963572e..96d09866 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: update-readme: - 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 --force - - - name: Update README with latest team and 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 + 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 f767ea93..94c26894 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ _test.js .eslint-release-info.json yarn.lock package-lock.json + +# Automatically generated files by GitHub Actions workflow +tools/update-readme.js diff --git a/package.json b/package.json index ebb3d5f1..1a47d83c 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,8 @@ "scripts": { "test": "npm test --workspaces --if-present", "build": "npm run build --workspaces --if-present", - "build:readme": "node tools/update-readme.js", - "lint": "eslint .", - "lint:fix": "eslint --fix ." + "lint": "eslint", + "lint:fix": "eslint --fix" }, "workspaces": [ "packages/*" @@ -27,7 +26,6 @@ "eslint-config-eslint": "^13.0.0", "eslint-plugin-chai-friendly": "^1.0.0", "globals": "^16.0.0", - "got": "^14.4.1", "lint-staged": "^15.2.0", "mocha": "^11.1.0", "yorkie": "^2.0.0" diff --git a/tools/commit-readme.sh b/tools/commit-readme.sh deleted file mode 100644 index baa69a50..00000000 --- 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 packages/**/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 0a00db1b..00000000 --- a/tools/update-readme.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @fileoverview Script to update the README with sponsors details in all packages. - * - * node tools/update-readme.js - * - * @author Nitin Kumar - */ - -//----------------------------------------------------------------------------- -// Requirements -//----------------------------------------------------------------------------- - -import { readFileSync, readdirSync, 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_PATHS = [ - "./README.md", - ...readdirSync("./packages").map(dir => `./packages/${dir}/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(); - -README_FILE_PATHS.forEach(filePath => { - - // read readme file - const readme = readFileSync(filePath, "utf8"); - - let newReadme = readme.replace( - /[\s\S]*?/u, - `\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(filePath, newReadme, "utf8"); -});