name: Language Stats on: schedule: [{cron: "0 0 * * *"}] workflow_dispatch: jobs: language-stats: runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v4 - name: Generate language SVG env: GH_TOKEN: ${{ secrets.METRICS_TOKEN }} run: | python3 << 'EOF' import urllib.request, json, math token = "${{ secrets.METRICS_TOKEN }}" headers = {"Authorization": f"Bearer {token}", "Accept": "application/vnd.github+json"} def get_repos(url): repos = [] while url: req = urllib.request.Request(url, headers=headers) with urllib.request.urlopen(req) as r: repos += json.loads(r.read()) link = r.headers.get('Link', '') url = None for part in link.split(','): if 'rel="next"' in part: url = part.split(';')[0].strip().strip('<>') return repos # все репы пользователя all_repos = [] all_repos += get_repos("https://api.github.com/user/repos?per_page=100&affiliation=owner,collaborator,organization_member&visibility=all") repo_names = list({r['full_name'] for r in all_repos}) print(f"Found {len(repo_names)} repositories") ignored = {'HTML', 'CSS', 'CMake', 'Dockerfile', 'Makefile', 'YAML', 'JSON', 'XML', 'Markdown', 'Text', 'SVG', 'Batchfile', 'PowerShell', 'EditorConfig', 'Ini', 'TOML', 'Nix', 'SCSS', 'GLSL'} skipped_repos = {'yawaflua/mt7902_temp'} colors = { 'C#': '#178600', 'C++': '#f34b7d', 'JavaScript': '#f1e05a', 'TypeScript': '#3178c6', 'Go': '#00ADD8', 'Python': '#3572A5', 'Java': '#b07219', 'Vue': '#41b883', 'Shell': '#89e051' } langs = {} for repo in repo_names: if repo in skipped_repos: continue try: req = urllib.request.Request(f"https://api.github.com/repos/{repo}/languages", headers=headers) with urllib.request.urlopen(req) as r: data = json.loads(r.read()) for lang, bytes_ in data.items(): if lang not in ignored: langs[lang] = langs.get(lang, 0) + bytes_ except Exception as e: print(f"Skip {repo}: {e}") langs = dict(sorted(langs.items(), key=lambda x: x[1], reverse=True)[:10]) total = sum(langs.values()) if total == 0: print("No data") exit(1) bar_width = 448 row_h = 30 padding = 16 bar_h = 8 header_h = 44 height = header_h + bar_h + padding + math.ceil(len(langs) / 2) * row_h + padding * 2 svg = f'\n' svg += f'\n' svg += f'Most used languages\n' cx = 0 for lang, count in langs.items(): w = count / total * bar_width color = colors.get(lang, '#ededed') svg += f'\n' cx += w for i, (lang, count) in enumerate(langs.items()): col = i % 2 row = i // 2 lx = 16 + col * 232 ly = header_h + bar_h + padding + row * row_h + 14 pct = count / total * 100 color = colors.get(lang, '#ededed') svg += f'\n' svg += f'{lang}\n' svg += f'{pct:.1f}%\n' svg += '' with open('languages.svg', 'w') as f: f.write(svg) print(f"Done: {len(langs)} languages, {total} bytes total") for l, b in langs.items(): print(f" {l}: {b/total*100:.1f}%") EOF - name: Commit SVG run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add languages.svg git diff --staged --quiet || git commit -m "Update languages.svg - [Skip GitHub Action]" git push