diff --git a/.github/workflows/update-libraries.yaml b/.github/workflows/update-libraries.yaml new file mode 100644 index 00000000..ce1303db --- /dev/null +++ b/.github/workflows/update-libraries.yaml @@ -0,0 +1,36 @@ +name: Update libraries stars count (test) +on: + push: + branches: [stars-ci-test] + workflow_dispatch: + + +jobs: + update-stars: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Install dependencies + run: npm install node-fetch@2 + - name: Update stars in libraries-next.json + run: node scripts/updateStars.js + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Commit and push changes + run: | + git config --global user.name 'javier-okta' + git config --global user.email 'javiersebastian.tinocomachado@okta.com' + git add . + git commit -m "chore: update stars count [skip ci]" || echo "No changes to commit" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/scripts/example-repos.json b/scripts/example-repos.json new file mode 100644 index 00000000..8c244f47 --- /dev/null +++ b/scripts/example-repos.json @@ -0,0 +1,158 @@ +{ + "dot-net": { + "id": "dot-net", + "name": ".NET", + "uniqueClass": "net", + "image": "/img/1.svg", + "bgColor": "rgb(42, 168, 229)", + "libs": [ + { + "minimumVersion": null, + "support": { + "sign": true, + "verify": true, + "iss": true, + "sub": true, + "aud": true, + "exp": true, + "nbf": true, + "iat": true, + "jti": true, + "hs256": true, + "hs384": true, + "hs512": true, + "rs256": true, + "rs384": true, + "rs512": true, + "es256": true, + "es384": true, + "es512": true, + "ps256": true, + "ps384": true, + "ps512": true + }, + "authorUrl": "https://www.microsoft.com", + "authorName": "Microsoft", + "gitHubRepoPath": "AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet", + "repoUrl": "https://github.com/MSOpenTech/azure-activedirectory-identitymodel-extensions-for-dotnet", + "installCommandMarkdown": [ + "Install-Package", + "[System.IdentityModel.Tokens.Jwt](https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/)" + ], + "stars": 1115 + }, + { + "minimumVersion": null, + "support": { + "sign": true, + "verify": true, + "iss": true, + "sub": true, + "aud": true, + "exp": true, + "nbf": true, + "iat": true, + "jti": false, + "hs256": true, + "hs384": true, + "hs512": true, + "rs256": true, + "rs384": true, + "rs512": true, + "es256": true, + "es384": true, + "es512": true, + "ps256": false, + "ps384": false, + "ps512": false + }, + "authorUrl": "https://github.com/jwt-dotnet/jwt", + "authorName": "Alexander Batishchev", + "gitHubRepoPath": "jwt-dotnet/jwt", + "repoUrl": "https://github.com/jwt-dotnet/jwt", + "installCommandMarkdown": [ + "Install-Package", + "[JWT.NET](https://www.nuget.org/packages/JWT)" + ], + "stars": 2109 + } + ] + }, + "swift": { + "id": "swift", + "name": "Swift", + "uniqueClass": "swift", + "image": "/img/15.svg", + "bgColor": "rgb(234, 45, 46)", + "libs": [ + { + "minimumVersion": null, + "support": { + "sign": true, + "verify": true, + "iss": true, + "sub": false, + "aud": true, + "exp": true, + "nbf": true, + "iat": true, + "jti": false, + "hs256": true, + "hs384": true, + "hs512": true, + "rs256": false, + "rs384": false, + "rs512": false, + "es256": false, + "es384": false, + "es512": false, + "ps256": false, + "ps384": false, + "ps512": false + }, + "authorUrl": "https://github.com/kylef", + "authorName": "Kyle Fuller", + "gitHubRepoPath": "kylef/JSONWebToken.swift", + "repoUrl": "https://github.com/kylef/JSONWebToken.swift", + "installCommandMarkdown": [ + "pod 'JSONWebToken'" + ], + "stars": 751 + }, + { + "minimumVersion": null, + "support": { + "sign": true, + "verify": true, + "iss": true, + "sub": true, + "aud": true, + "exp": true, + "nbf": true, + "iat": true, + "jti": true, + "hs256": true, + "hs384": true, + "hs512": true, + "rs256": true, + "rs384": true, + "rs512": true, + "es256": true, + "es384": true, + "es512": true, + "ps256": false, + "ps384": false, + "ps512": false + }, + "authorUrl": "https://github.com/vapor", + "authorName": "Vapor", + "gitHubRepoPath": "vapor/jwt-kit", + "repoUrl": "https://github.com/vapor/jwt-kit", + "installCommandMarkdown": [ + ".package(url: \"https://github.com/vapor/jwt-kit.git\", from: \"4.0.0\")" + ], + "stars": 250 + } + ] + } +} diff --git a/scripts/updateStars.js b/scripts/updateStars.js new file mode 100644 index 00000000..3b456edc --- /dev/null +++ b/scripts/updateStars.js @@ -0,0 +1,36 @@ +import fs from "fs" +import path from "path" + +const filePath = path.join(process.cwd(), "/scripts/example-repos.json") +const reposGroup = JSON.parse(fs.readFileSync(filePath, "utf-8")) + +async function getStars(repoUrl) { + const match = repoUrl.match(/github\.com\/([^/]+)\/([^/]+)(?:\/|$)/) + if(!match) throw new Error(`Invalid github repo URL: ${repoUrl}`) + const [, owner, repo] = match + const res = await fetch(`https://api.github.com/repos/${owner}/${repo}`, { + headers: { + Accept: "application/vnd.github+json" + } + }) + if(!res.ok) throw new Error(`${repoUrl} -> ${res.status} ${res.statusText}`) + const data = await res.json() + return data.stargazers_count ?? null +} + +(async () => { + const objectEntries = Object.values(reposGroup) + for(const group of objectEntries) { + for(const lib of group.libs) { + try { + const stars = await getStars(lib.repoUrl) + lib.stars = stars + console.log(`✅ ${lib.repoUrl} -> ${stars}`) + } catch(e) { + lib.stars = null + console.error(`❌ ${lib.repoUrl}: ${e.message}`) + } + } + } + fs.writeFileSync(filePath, JSON.stringify(reposGroup, null, 2) + "\n") +})() \ No newline at end of file