2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

chore(actions): Add action to update sponsor list in Readme.md; (#6552)

This commit is contained in:
Dmitriy Mozgovoy
2024-08-17 20:13:56 +03:00
committed by GitHub
parent abd24a7367
commit 58eb3b8ae6
3 changed files with 125 additions and 59 deletions
+61
View File
@@ -0,0 +1,61 @@
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: Generate PR
id: sponsors
run: node ./bin/sponsors.js
- name: Notify status
if: ${{ steps.sponsors.outputs.changed }}
run: |
echo "Sponsor block has changed. Creating PR with updates..."
- name: Create pull request
if: ${{ steps.sponsors.outputs.changed }}
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:**
{{ steps.sponsors.outputs.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 }}
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 }}"
+1 -59
View File
@@ -1,62 +1,4 @@
<h3 align="center">
Platinum sponsors
<br>
</h3>
<div align="center">
<a href="https://runalloy.com?utm_source=github&utm_medium=referral&utm_campaign=121423_axios">
<picture>
<source width="400px" media="(prefers-color-scheme: dark)" srcset="https://github.com/axios/axios/assets/4814473/f6067247-7eba-4069-852a-ab1bb85b1780">
<source width="400px" media="(prefers-color-scheme: light)" srcset="https://github.com/axios/axios/assets/4814473/75c37f4d-36e6-44f5-a068-3edd77c00a10">
<img width="400px" src="https://github.com/axios/axios/assets/4814473/75c37f4d-36e6-44f5-a068-3edd77c00a10" />
</picture>
</a>
<p align="center">Alloy is the integration development platform that makes it simple and <br>fast for SaaS companies to launch critical user-facing integrations.</p>
<p align="center">
<a href="https://runalloy.com/signup?utm_source=github&utm_medium=referral&utm_campaign=11823_axios"><b>Sign up free</b></a> •
<a href="https://docs.runalloy.com/docs?utm_source=github&utm_medium=referral&utm_campaign=11823_axios"><b>Documentation</b></a>
</p>
<br><br>
</div>
<h3 align="center">
Gold sponsors
<br><br>
</h3>
<table border="0">
<td align="center">
<a href="https://stytch.com?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=logo&utm_campaign=axios-http">
<picture>
<source width="200px" media="(prefers-color-scheme: dark)" srcset="https://github.com/axios/axios/assets/4814473/538d715a-13c7-4668-ae7d-37a4548423f4">
<source width="200px" media="(prefers-color-scheme: light)" srcset="https://github.com/axios/axios/assets/4814473/b6a9a7bc-9fb1-4b9b-909f-1b4bee1fd142">
<img width="200px" src="https://github.com/axios/axios/assets/4814473/b6a9a7bc-9fb1-4b9b-909f-1b4bee1fd142" />
</picture>
</a>
<p align="center">API-first authentication, authorization, and fraud prevention</p>
<p align="center">
<a href="https://stytch.com?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=website-link&utm_campaign=axios-http"><b>Website</b></a> •
<a href="https://stytch.com/docs?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=docs-link&utm_campaign=axios-http"><b>Documentation</b></a> • <a href="https://github.com/stytchauth/stytch-node?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=node-sdk&utm_campaign=axios-http"><b>Node.js Backend SDK</b></a>
</p>
</td>
<td align="center">
<a href="https://stytch.com?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=logo&utm_campaign=axios-http">
<picture>
<source width="200px" media="(prefers-color-scheme: dark)" srcset="https://github.com/axios/axios/assets/4814473/79f572f3-9d57-488d-80cc-58d674bb98d8">
<source width="200px" media="(prefers-color-scheme: light)" srcset="https://github.com/axios/axios/assets/4814473/18b51893-c4b4-4557-b263-74c2b3de84ab">
<img width="200px" src="https://github.com/axios/axios/assets/4814473/18b51893-c4b4-4557-b263-74c2b3de84ab" />
</picture>
</a>
<p align="center">Drag-and-drop authentication, authorization, and identity management</p>
<p align="center">
<a href="https://www.descope.com/?utm_source=axios&utm_medium=referral&utm_campaign=axios-oss-sponsorship"><b>Website</b></a> •
<a href="https://docs.descope.com/?utm_source=axios&utm_medium=referral&utm_campaign=axios-oss-sponsorship"><b>Documentation</b></a> • <a href="https://www.descope.com/community?utm_source=axios&utm_medium=referral&utm_campaign=axios-oss-sponsorship"><b>Community</b></a>
</p>
</td>
</table>
<!--<div>marker</div>-->
<br><br>
<div align="center">
<a href="https://axios-http.com"><img src="https://axios-http.com/assets/logo.svg" /></a><br>
+63
View File
@@ -0,0 +1,63 @@
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 "tag=${newContent ? 'true' : 'false'}" >> $GITHUB_OUTPUT`);
if (newContent !== false) {
await exec(`echo "content=${newContent}" >> $GITHUB_OUTPUT`);
}
})('https://spontaneous-creponne-3ff312.netlify.app/data/sponsors.md');