-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: create update-readme.yml
#12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
53a19c9
feat: create `update-readme.yml`
lumirlumir ccb4cbb
wip
lumirlumir 1ce0882
Fix string quotes in update-readme.yml
lumirlumir 1657f84
wip
lumirlumir d38d985
wip
lumirlumir 2207c96
wip
lumirlumir a90f383
wip
lumirlumir f0467d9
fix: use here-doc
lumirlumir ae73ee9
wip: add `shopt`
lumirlumir 10c52e8
wip: add `workflow_call` event
lumirlumir 0d42fd5
wip
lumirlumir 4887b76
wip: add sponsors heading
lumirlumir e7ab9a7
wip: use CURL
lumirlumir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| name: update-readme | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 8 * * *" # Runs every day at 08:00 AM UTC | ||
|
|
||
| workflow_dispatch: | ||
|
|
||
| workflow_call: | ||
| secrets: | ||
| workflow_push_bot_token: | ||
| required: true | ||
| description: Token for the workflow bot to push changes | ||
|
|
||
| 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 | ||
| with: | ||
| node-version: "lts/*" | ||
|
|
||
| - name: Copy update-readme script from workflows repository | ||
| run: curl --create-dirs -fsSL https://raw.githubusercontent.com/eslint/workflows/main/tools/update-readme.js -o tools/update-readme.js | ||
|
|
||
| - name: Update README with latest sponsor data | ||
| run: node tools/update-readme.js | ||
|
|
||
| - name: Setup Git | ||
| run: | | ||
| git config user.name "GitHub Actions Bot" | ||
| git config user.email "<[email protected]>" | ||
|
|
||
| - name: Commit README | ||
| run: | | ||
| # Unmatched patterns are dropped to avoid git errors | ||
| shopt -s nullglob | ||
|
|
||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's okay, could this PR include only a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * @fileoverview Script to update the README with sponsors details in all packages. | ||
| * | ||
| * node tools/update-readme.js | ||
| * | ||
| * @author 루밀LuMir(lumirlumir) | ||
| */ | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // Import | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| import { existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'; | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // Data | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| const SPONSORS_URL = 'https://raw.githubusercontent.com/eslint/eslint.org/main/includes/sponsors.md'; | ||
| const PACKAGES_README_FILE_PATHS = existsSync('./packages') | ||
| ? readdirSync('./packages').map(dir => `./packages/${dir}/README.md`) | ||
| : []; | ||
| const README_FILE_PATHS = ['./README.md', ...PACKAGES_README_FILE_PATHS]; | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // Main | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| const response = await fetch(SPONSORS_URL); | ||
| const allSponsors = await response.text(); | ||
|
|
||
| README_FILE_PATHS.forEach(readmeFilePath => { | ||
| const readme = readFileSync(readmeFilePath, 'utf8'); // Read README file | ||
|
|
||
| let newReadme = readme.replace( | ||
| /<!--sponsorsstart-->[\s\S]*?<!--sponsorsend-->/u, | ||
| `<!--sponsorsstart-->\n\n${allSponsors}\n<!--sponsorsend-->`, | ||
| ); | ||
|
|
||
| // replace multiple consecutive blank lines with just one blank line | ||
| newReadme = newReadme.replace(/(?<=^|\n)\n{2,}/gu, '\n'); | ||
|
|
||
| // output to the files | ||
| writeFileSync(readmeFilePath, newReadme, 'utf8'); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.