Skip to content

Latest commit

 

History

History
113 lines (88 loc) · 7.25 KB

README.md

File metadata and controls

113 lines (88 loc) · 7.25 KB

API quality scripts

AOI:Android API Standards

Scores every -api module against the mechanical checks of the API quality rules, compares runs, and publishes the weekly report.

Refer to API Quality Rules and Scores on Asana for more information and full list of checks.

File What it does Run by
score.sh + Scorer.java Scores the checked-out code Manual or every workflow
compare.py Diffs two scorer runs by declaration: new, resolved and moved findings, score changes, and whether it regressed Every workflow except the scorecard
asana_sync.py Posts the weekly report to Asana, and one Triage task listing all of the week's new findings Weekly workflow
asana_task.py Creates the one Asana task of a run, or updates it on a re-run Compare workflow
rules.json Each rule's name, why it matters and how to fix it: the single source for the texts in reports, PR comments and Asana tasks compare.py, asana_sync.py

Score your checkout

scripts/api-quality/score.sh

Writes five files to scripts/api-quality/output/ (gitignored), named with today's date. Needs Java 21. The Kotlin compiler jars come from your Gradle cache, or are downloaded once from Maven Central into ~/.cache/api-quality-scorer.

# Argument Default Meaning
1 Output folder scripts/api-quality/output Where the files go
2 Date Today Used in the file names
3 Previous scores CSV None Adds a "Score changes" section to the scorecard

Set REPO_ROOT to score a different checkout, e.g. REPO_ROOT=/tmp/old scripts/api-quality/score.sh /tmp/old-score.

Compare two runs

python3 scripts/api-quality/compare.py --before /tmp/old-score --after scripts/api-quality/output --mode weekly --out-md /tmp/report.md

--mode pr renders the PR comment instead. Both runs must come from the same Scorer.java.

Output files

File Contents
api-quality-scorecard-<date>.md Summary and per-module scores
api-quality-scores-<date>.csv One row per module, with its KDoc counts and failing rules
api-quality-findings-<date>.csv One row per finding
api-quality-declarations-<date>.csv Every counted public declaration, to audit M3 and M4
api-quality-constructors-<date>.csv Every constructor of a public class, any visibility; not counted, only lets compare.py tell a constructor still exists

Asana configuration

The posting scripts read every Asana ID from these repository variables (Settings → Secrets and variables → Actions → Variables), which the workflows pass in as environment variables of the same names. For a local run, export them.

Variable Asana ID of
GH_API_QUALITY_PROJECT_ID The project
GH_API_QUALITY_TRIAGE_SECTION_ID Its Triage section: weekly regressions tasks and compare regression tasks
GH_API_QUALITY_WEEKLY_REPORTS_SECTION_ID Its Weekly Reports section: weekly report tasks
GH_API_QUALITY_GITHUB_RUN_FIELD_KEY_ID The "GitHub run" text field, which lets a re-run find and update its own task
GH_API_QUALITY_STATUS_FIELD_KEY_ID The "API quality status" single-select field
GH_API_QUALITY_STATUS_FIELD_NEEDS_EXPLANATION_VALUE_ID Its "Needs explanation" option: the weekly report counts open tasks still at it after 14 days
GH_API_QUALITY_RULES_URL Optional: the "API quality rules and scores" task, linked at the end of PR comments, reports and regressions tasks

Scheduled weekly runs post once GH_API_QUALITY_PROJECT_ID is set. A run that posts with any variable missing fails and names the missing ones. Posting uses the existing ASANA_ACCESS_TOKEN secret.

Definitions

  • Source: the .kt files of every non-test source set of a module: src/main and any flavor folder such as src/play.
  • Public: no private, internal or protected modifier, inside a public parent. override members are left out, because the contract and KDoc belong to the declaration they override.
  • Declaration: each public type (top-level or nested, including type aliases; not companion objects or enum entries), top-level function or property, and member function or property. Primary-constructor val/var parameters count as properties. The declaration count weights the fleet score.
  • Sealed cases: a class or object declared inside its sealed parent and extending it (Result.Success) needs no KDoc, like an enum entry: it counts as a declaration but not for M3. Its own members still count for M4. A subtype declared outside its parent isn't recognised, since there's no symbol resolution.
  • M3 covers types and top-level functions. M4 covers member functions and properties, and top-level properties. Each fails on any declaration in its group without KDoc. A property is also documented when its class KDoc describes it with an @property/@param tag or a [name] link. KDoc coverage, the share of declarations with KDoc, is reported next to the scores to show progress while a module still fails the checks.
  • Constructors: a val/var parameter is a property, public even behind a private constructor. Other parameters of a public constructor are checked by M2, M6 and M7 as Type.constructor(...); enum and sealed class constructors aren't.
  • M1: a type name ending in Repository, Dao, Entity, ViewModel or Impl, or starting with Real followed by an uppercase letter (RealFoo, not Realm).
  • M2: Toggle anywhere in a signature or supertype, including type arguments such as List<Toggle>. A qualified name such as Toggle.State doesn't count.
  • M5: a function whose declared return type is exactly Intent?, Fragment?, View? or Bundle?.
  • M6: Any, Pair or Triple anywhere in a signature, including type arguments, except equals(other: Any?) and readResolve().
  • M7: a public var whose setter is also public, or a writable type anywhere in a signature: Mutable*, the Java mutable collections (ArrayList, HashMap, HashSet, LinkedHashMap, LinkedHashSet, LinkedList, ConcurrentHashMap, CopyOnWriteArrayList), the Atomic* types, and the coroutines Channel and SendChannel. The last two only count when the file imports them from kotlinx.coroutines.channels or writes their full name, since this repo also has its own Channel class. Arrays aren't checked: they're the usual type for binary data.

Files are parsed with the Kotlin compiler's own parser, so the same code always gives the same score. There is no symbol resolution: types are matched by simple name, and a declaration whose type is inferred isn't checked by M2, M5, M6 or M7.

Changing any definition changes scores across the fleet, so it follows the re-baseline procedure.

Tests

pip install -r scripts/api-quality/requirements.txt
cd scripts/api-quality && python3 -m pytest

test_scorer.py runs the scorer on small Kotlin fixtures, so it needs Java 21; it's skipped without it.