Skip to content

Commit

Permalink
Add workflow to auto update SUPPORTERS
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Dec 17, 2022
1 parent 040ab4c commit 0b3a809
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
37 changes: 30 additions & 7 deletions .github/workflows/update-sponsors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs').promises;
const query = `
query {
user(login: "huxingyi") {
Expand All @@ -40,14 +41,15 @@ jobs:
}
`;
const response = await github.graphql(query);
let html = '';
console.log(response);
let sponsorsHtml = '';
for (const node of response.user.sponsorshipsAsMaintainer.nodes) {
html += '<a href="' + node.sponsor.url + '" title="' + node.sponsor.login + (node.sponsor.name ? (' (' + node.sponsor.name + ')') : '') + '" target=_blank><image src="' + node.sponsor.avatarUrl + '" alt="@' + node.sponsor.login + '" width="35" height="35" style="border-radius: 17px;" /></a>\n';
sponsorsHtml += '<a href="' + node.sponsor.url + '" title="' + node.sponsor.login + (node.sponsor.name ? (' (' + node.sponsor.name + ')') : '') + '" target=_blank><image src="' + node.sponsor.avatarUrl + '" alt="@' + node.sponsor.login + '" width="35" height="35" style="border-radius: 17px;" /></a>\n';
}
if ('' !== html) {
html = '\n## Sponsors \n\n' + html + '\n _The list shown represent active sponsors on GitHub and a full list can be viewed at [SUPPORTERS](https://github.com/huxingyi/dust3d/blob/master/SUPPORTERS)._\n';
if ('' !== sponsorsHtml) {
sponsorsHtml = '\n## Sponsors \n\n' + sponsorsHtml + '\n _The list shown represent active sponsors on GitHub and a full list can be viewed at [SUPPORTERS](https://github.com/huxingyi/dust3d/blob/master/SUPPORTERS)._\n';
}
const fs = require('fs').promises;
const readme = await fs.readFile('README.md', 'utf8');
const beginString = '<!-- Sponsors begin -->';
const endString = '<!-- Sponsors end -->';
Expand All @@ -56,20 +58,41 @@ jobs:
startIndex = startIndex + beginString.length;
const endIndex = readme.indexOf(endString);
if (-1 !== endIndex) {
const newContent = readme.substring(0, startIndex) + html + readme.substring(endIndex);
const newContent = readme.substring(0, startIndex) + sponsorsHtml + readme.substring(endIndex);
await fs.writeFile('README.md', newContent);
} else {
throw new Error('Could not find end marker');
}
} else {
throw new Error('Could not find begin marker');
}
const supportersContent = await fs.readFile('SUPPORTERS', 'utf8');
const regGithubId = /https:\/\/github\.com\/([^>]+)>/g;
const matched = [...supportersContent.matchAll(regGithubId)];
const supporters = {};
for (const user of matched) {
supporters[user[1].toLowerCase()] = user[1];
}
let supportersText = '';
for (const node of response.user.sponsorshipsAsMaintainer.nodes) {
if (undefined !== supporters[node.sponsor.login]) {
continue;
}
supportersText += '\n' + node.sponsor.name + ' <' + node.sponsor.url + '>';
}
if ('' !== supportersText) {
const newContent = supportersContent.trim() + supportersText;
await fs.writeFile('SUPPORTERS', newContent);
}
- name: Upload README.md
run: |
if git diff --name-only HEAD | grep -q "README.md"; then
if git diff --name-only HEAD | grep -q "README.md\|SUPPORTERS"; then
git config --global user.email ""
git config --global user.name "bot"
git add README.md
git add SUPPORTERS
timestamp=$(TZ=":Australia/Sydney" date)
git commit -m "Update sponsors at ${timestamp}"
git push origin HEAD
Expand Down
4 changes: 2 additions & 2 deletions SUPPORTERS
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Marcus Hilsdorf
Nick Friess
Christine Garner <https://thimblefolio.com>
wavetro <https://wavetro.net/>
Morgan Hoarau <https://www.morganhoarau.com/>
Morgan Hoarau <https://github.com/Nobuna-no>
Erik Smith
Jairo <https://kidandcat.me/>
Jairo <https://github.com/kidandcat>
Frank O'Hara <https://github.com/fohara>

0 comments on commit 0b3a809

Please sign in to comment.