-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,362 additions
and
758 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,72 @@ | ||
name: Update Readme sponsor list | ||
on: | ||
workflow_dispatch: | ||
repository_dispatch: | ||
types: | ||
- webhook | ||
schedule: | ||
# Run at 0000 daily | ||
- cron: '0 1 * * *' | ||
jobs: | ||
sponsors: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: git config | ||
run: | | ||
git config user.name "${GITHUB_ACTOR}" | ||
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | ||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
cache: npm | ||
- run: npm ci | ||
- name: Check sponsors updates | ||
id: sponsors | ||
run: node ./bin/sponsors.js | ||
- name: Notify status | ||
if: ${{ steps.sponsors.outputs.changed == 'true'}} | ||
run: | | ||
echo "Sponsor block has changed. Creating PR with updates..." | ||
- name: Read sponsors.md file content | ||
if: ${{ steps.sponsors.outputs.changed == 'true'}} | ||
id: read_file | ||
run: | | ||
echo 'CONTENT<<EOF' >> $GITHUB_ENV | ||
cat ./temp/sponsors.md >> $GITHUB_ENV | ||
echo 'EOF' >> $GITHUB_ENV | ||
shell: bash | ||
- name: Echo | ||
run: | | ||
echo "$CONTENT" | ||
- name: Create pull request | ||
if: ${{ steps.sponsors.outputs.changed == 'true'}} | ||
uses: peter-evans/create-pull-request@v6 | ||
id: cpr | ||
with: | ||
branch: sponsors | ||
delete-branch: true | ||
commit-message: 'chore(sponsor): update sponsor block' | ||
title: '[Chore] Update sponsor block' | ||
body: | | ||
**New sponsor block update:** | ||
${{ env.CONTENT }} | ||
labels: | | ||
readme | ||
automated pr | ||
automerge | ||
signoff: false | ||
#team-reviewers: | | ||
# owners | ||
# maintainers | ||
#assignees: jasonsaayman | ||
#reviewers: jasonsaayman | ||
draft: false | ||
- name: Show PR link | ||
if: ${{ steps.sponsors.outputs.changed == 'true'}} | ||
run: | | ||
echo "Sponsor block has changed. Creating PR..." | ||
echo "Axios Release v${{ steps.package-version.outputs.current-version}}' pull request - ${{ steps.cpr.outputs.pull-request-url }}" |
This file contains 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 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 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 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,64 @@ | ||
import fs from "fs/promises"; | ||
import _axios from '../index.js'; | ||
import {exec} from "./repo.js"; | ||
import {colorize} from "./helpers/colorize.js"; | ||
|
||
const axios = _axios.create({ | ||
headers: { | ||
"User-Agent": 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36' | ||
} | ||
}); | ||
|
||
const getWithRetry = (url, retries = 3) => { | ||
let counter = 0; | ||
const doRequest = async () => { | ||
try { | ||
return await axios.get(url) | ||
} catch (err) { | ||
if (counter++ >= retries) { | ||
throw err; | ||
} | ||
await new Promise(resolve => setTimeout(resolve, counter ** counter * 1000)); | ||
return doRequest(); | ||
} | ||
} | ||
|
||
return doRequest(); | ||
}; | ||
|
||
const updateReadmeSponsors = async (url, path, marker = '<!--<div>marker</div>-->') => { | ||
let fileContent = (await fs.readFile(path)).toString(); | ||
|
||
const index = fileContent.indexOf(marker); | ||
|
||
if(index >= 0) { | ||
const readmeContent = fileContent.slice(index); | ||
|
||
let {data: sponsorContent} = await getWithRetry(url); | ||
sponsorContent += '\n'; | ||
|
||
const currentSponsorContent = fileContent.slice(0, index); | ||
|
||
if (currentSponsorContent !== sponsorContent) { | ||
console.log(colorize()`Sponsor block in [${path}] is outdated`); | ||
await fs.writeFile(path, sponsorContent + readmeContent); | ||
return sponsorContent; | ||
} else { | ||
console.log(colorize()`Sponsor block in [${path}] is up to date`); | ||
} | ||
} else { | ||
console.warn(colorize()`Can not find marker (${marker}) in ${path} to inject sponsor block`); | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
(async(url) => { | ||
const newContent = await updateReadmeSponsors(url, './README.md'); | ||
|
||
await exec(`echo "changed=${newContent ? 'true' : 'false'}" >> $GITHUB_OUTPUT`); | ||
if (newContent !== false) { | ||
await fs.mkdir('./temp').catch(() => {}); | ||
await fs.writeFile('./temp/sponsors.md', newContent); | ||
} | ||
})('https://axios-http.com/data/sponsors.md'); |
This file contains 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
Oops, something went wrong.