mirror of
https://github.com/tenrok/axios.git
synced 2026-06-05 16:42:32 +03:00
refactor: ci and build (#7340)
* chore: add mise * chore: re-position ci * chore: move sponsors script * chore: fix yml * chore: yml * fix: yml * fix: yml * chore: tweak sponsor yml * chore: implement security suggestion * chore: update templates for issues and PRs and update all workflows * fix: copilot feedback * feat: always run CI * fix: linked resources * chore: cancel run if new run starts * feat: generate release notes with copilot
This commit is contained in:
+30
-19
@@ -1,41 +1,48 @@
|
||||
import fs from "fs/promises";
|
||||
import _axios from '../index.js';
|
||||
import {exec} from "./repo.js";
|
||||
import {colorize} from "./helpers/colorize.js";
|
||||
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'
|
||||
}
|
||||
"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)
|
||||
return await axios.get(url);
|
||||
} catch (err) {
|
||||
if (counter++ >= retries) {
|
||||
throw err;
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, counter ** counter * 1000));
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, counter ** counter * 1000),
|
||||
);
|
||||
return doRequest();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return doRequest();
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
const index = fileContent.indexOf(marker);
|
||||
|
||||
if(index >= 0) {
|
||||
if (index >= 0) {
|
||||
const readmeContent = fileContent.slice(index);
|
||||
|
||||
let {data: sponsorContent} = await getWithRetry(url);
|
||||
sponsorContent += '\n';
|
||||
let { data: sponsorContent } = await getWithRetry(url);
|
||||
sponsorContent += "\n";
|
||||
|
||||
const currentSponsorContent = fileContent.slice(0, index);
|
||||
|
||||
@@ -47,18 +54,22 @@ const updateReadmeSponsors = async (url, path, marker = '<!--<div>marker</div>--
|
||||
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`);
|
||||
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');
|
||||
(async (url) => {
|
||||
const newContent = await updateReadmeSponsors(url, "./README.md");
|
||||
|
||||
await exec(`echo "changed=${newContent ? 'true' : 'false'}" >> $GITHUB_OUTPUT`);
|
||||
await exec(
|
||||
`echo "changed=${newContent ? "true" : "false"}" >> $GITHUB_OUTPUT`,
|
||||
);
|
||||
if (newContent !== false) {
|
||||
await fs.mkdir('./temp').catch(() => {});
|
||||
await fs.writeFile('./temp/sponsors.md', newContent);
|
||||
await fs.mkdir("./temp").catch(() => {});
|
||||
await fs.writeFile("./temp/sponsors.md", newContent);
|
||||
}
|
||||
})('https://axios-http.com/data/sponsors.md');
|
||||
})("https://axios-http.com/data/sponsors.md");
|
||||
|
||||
Reference in New Issue
Block a user