2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

feat: update sponsors script and how this works for more consistency (#10582)

This commit is contained in:
Jay
2026-03-30 12:52:55 +02:00
committed by GitHub
parent 7173706380
commit 4950ff6017
3 changed files with 28 additions and 12 deletions
+12 -4
View File
@@ -33,18 +33,26 @@ jobs:
run: npm ci run: npm ci
- name: Check if sponsors require updates - name: Check if sponsors require updates
id: sponsors-requires-update id: sponsors-requires-update
run: node ./bin/sponsors.js run: node ./scripts/sponsors/update-readme-sponsors.mjs
- name: Check tracked README sponsor diff
id: readme-tracked-change
run: |
if git diff --quiet -- README.md; then
echo "readme_changed=false" >> "$GITHUB_OUTPUT"
else
echo "readme_changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Read sponsors.md file content - name: Read sponsors.md file content
run: | run: |
echo 'CONTENT<<EOF' >> $GITHUB_ENV echo 'CONTENT<<EOF' >> $GITHUB_ENV
cat ./temp/sponsors.md >> $GITHUB_ENV cat ./temp/sponsors.md >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV echo 'EOF' >> $GITHUB_ENV
shell: bash shell: bash
if: steps.sponsors-requires-update.outputs.changed == 'true' if: steps.sponsors-requires-update.outputs.changed == 'true' && steps.readme-tracked-change.outputs.readme_changed == 'true'
- name: Echo sponsors content - name: Echo sponsors content
run: | run: |
echo "$CONTENT" echo "$CONTENT"
if: steps.sponsors-requires-update.outputs.changed == 'true' if: steps.sponsors-requires-update.outputs.changed == 'true' && steps.readme-tracked-change.outputs.readme_changed == 'true'
- name: Create pull request - name: Create pull request
uses: peter-evans/create-pull-request@v8 uses: peter-evans/create-pull-request@v8
with: with:
@@ -61,4 +69,4 @@ jobs:
type::automated-pr type::automated-pr
signoff: false signoff: false
draft: false draft: false
if: steps.sponsors-requires-update.outputs.changed == 'true' if: steps.sponsors-requires-update.outputs.changed == 'true' && steps.readme-tracked-change.outputs.readme_changed == 'true'
+1
View File
@@ -14,3 +14,4 @@ backup/
dist/ dist/
.vscode/ .vscode/
docs/ docs/
openspec/
@@ -1,7 +1,5 @@
import fs from 'fs/promises'; import fs from 'fs/promises';
import _axios from '../index.js'; import _axios from '../../index.js';
import { exec } from './repo.js';
import { colorize } from './helpers/colorize.js';
const axios = _axios.create({ const axios = _axios.create({
headers: { headers: {
@@ -27,6 +25,15 @@ const getWithRetry = (url, retries = 3) => {
return doRequest(); return doRequest();
}; };
const setGithubOutput = async (key, value) => {
if (!process.env.GITHUB_OUTPUT) {
console.warn(`GITHUB_OUTPUT is not set; skipping output ${key}=${value}`);
return;
}
await fs.appendFile(process.env.GITHUB_OUTPUT, `${key}=${value}\n`);
};
const updateReadmeSponsors = async (url, path, marker = '<!--<div>marker</div>-->') => { const updateReadmeSponsors = async (url, path, marker = '<!--<div>marker</div>-->') => {
let fileContent = (await fs.readFile(path)).toString(); let fileContent = (await fs.readFile(path)).toString();
@@ -41,14 +48,14 @@ const updateReadmeSponsors = async (url, path, marker = '<!--<div>marker</div>--
const currentSponsorContent = fileContent.slice(0, index); const currentSponsorContent = fileContent.slice(0, index);
if (currentSponsorContent !== sponsorContent) { if (currentSponsorContent !== sponsorContent) {
console.log(colorize()`Sponsor block in [${path}] is outdated`); console.log(`Sponsor block in [${path}] is outdated`);
await fs.writeFile(path, sponsorContent + readmeContent); await fs.writeFile(path, sponsorContent + readmeContent);
return sponsorContent; return sponsorContent;
} else {
console.log(colorize()`Sponsor block in [${path}] is up to date`);
} }
console.log(`Sponsor block in [${path}] is up to date`);
} else { } else {
console.warn(colorize()`Can not find marker (${marker}) in ${path} to inject sponsor block`); console.warn(`Can not find marker (${marker}) in ${path} to inject sponsor block`);
} }
return false; return false;
@@ -57,7 +64,7 @@ const updateReadmeSponsors = async (url, path, marker = '<!--<div>marker</div>--
(async (url) => { (async (url) => {
const newContent = await updateReadmeSponsors(url, './README.md'); const newContent = await updateReadmeSponsors(url, './README.md');
await exec(`echo "changed=${newContent ? 'true' : 'false'}" >> $GITHUB_OUTPUT`); await setGithubOutput('changed', newContent ? 'true' : 'false');
if (newContent !== false) { if (newContent !== false) {
await fs.mkdir('./temp').catch(() => {}); await fs.mkdir('./temp').catch(() => {});
await fs.writeFile('./temp/sponsors.md', newContent); await fs.writeFile('./temp/sponsors.md', newContent);