# ArchSetu CI analysis - for repositories too large for archsetu.com's
# hosted instant analysis (the free "paste a URL" path is capped for its own
# reliability; this workflow has no such limit, since it runs on your own
# GitHub Actions runner, not ArchSetu's server).
#
# Setup:
#   1. Get your API key from https://archsetu.com/dashboard
#   2. Add it as a repository secret named ARCHSETU_API_KEY
#      (Settings -> Secrets and variables -> Actions -> New repository secret)
#   3. Commit this file as .github/workflows/archsetu-analyze.yml
#   4. Push - your report will appear at archsetu.com/r/<owner>/<repo>
#
# Runs on every push to main and on a weekly schedule, so your report stays
# current without needing a human to remember to re-run it. Adjust the
# `on:` triggers below to match how often you actually want it to run.

name: ArchSetu Analysis

on:
  push:
    branches: [main]
  schedule:
    - cron: '0 6 * * 1' # every Monday at 06:00 UTC
  workflow_dispatch: {}

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          # A shallow (depth-1) checkout has no commit history at all, which
          # would silently disable the bus-factor/ownership/churn signals -
          # matching the same bounded-depth tradeoff ArchSetu's own hosted
          # worker uses (see GIT_HISTORY_MAX_COMMITS in packages/core).
          fetch-depth: 300

      - uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install ArchSetu CLI
        run: npm install -g @archsetuweb/cli

      - name: Analyze and submit
        env:
          ARCHSETU_API_KEY: ${{ secrets.ARCHSETU_API_KEY }}
          # GitHub's standard runner has 7GB RAM, but Node.js caps its own
          # heap well below that by default regardless of what's actually
          # available - confirmed directly: analyzing torvalds/linux (6GB,
          # the largest real-world test run so far) crashed with "JavaScript
          # heap out of memory" at ~3.8GB used, on a runner that had 7GB free
          # the whole time. 6144 leaves ~1GB headroom for the OS/git/CLI
          # process overhead rather than claiming the full 7GB.
          NODE_OPTIONS: --max-old-space-size=6144
        run: archsetu submit ${{ github.repository }} .
