diff --git a/.github/release-notes/v0.3.0.md b/.github/release-notes/v0.3.0.md new file mode 100644 index 0000000..a58cc17 --- /dev/null +++ b/.github/release-notes/v0.3.0.md @@ -0,0 +1,7 @@ +**actnode v0.3.0** — ergonomics: `--latest`, release-notes links, Action PR mode. + +- **`--latest`**: suggest the newest release that already runs on the target Node (default stays the smallest major jump). Also available as Action input `latest: true`. +- **Release-notes links**: every finding with a suggested bump includes a `release_notes` URL (`https://github.com/{owner}/{repo}/releases/tag/{tag}`). Shown in text (`notes: …`), Markdown (extra column), and JSON. +- **Action PR mode**: set `create-pr: true` (plus optional `pr-branch` / `pr-title`) to apply `--fix` and open or update a pull request when there is a diff. No PR if the diff is empty. Caller needs `contents: write` and `pull-requests: write`. + +Docs: https://blackman99.github.io/actnode/docs/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f37799..edf32e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v0.3.0 — 2026-10-19 +- `--latest` (Action input `latest`): suggest the newest node24-capable release instead of the smallest major jump; default behavior unchanged +- Release-notes links on every suggested bump (`release_notes` in JSON; text `notes:` URL; Markdown column) +- Action optional PR mode: `create-pr` (+ `pr-branch` / `pr-title`) applies `--fix` and opens or updates a PR when there is a diff (needs `contents:write` + `pull-requests:write`) + ## v0.2.0 — 2026-10-12 - Reusable workflows (`uses: org/repo/.github/workflows/x.yml@ref`) scanned recursively (status `workflow` / `wfl`); nested findings show `(inside …)` and are not rewritten by `--fix` - Remote scan without cloning: `actnode --repo owner/name` and `actnode --org owner` (public non-fork repos by default; `--fix` refused) diff --git a/README.md b/README.md index e50dd64..552cd56 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,12 @@ jobs: - uses: actions/checkout@v7 - uses: Blackman99/actnode@v0 with: - fail: true # inputs: path (.), target (24), fail (true), token (github.token) + fail: true # also: path, target, latest, create-pr, pr-branch, pr-title, token ``` -`@v0` is a moving major tag that always points at the latest v0.x release; pin `@v0.2.0` or a SHA if you prefer. +`@v0` is a moving major tag that always points at the latest v0.x release; pin `@v0.3.0` or a SHA if you prefer. + +To open a PR with the `--fix` diff on a schedule, set `create-pr: true` and grant `contents: write` + `pull-requests: write` (see [Action docs](https://blackman99.github.io/actnode/docs/action/)). ## Install (CLI, to fix locally) @@ -38,8 +40,9 @@ Python 3.9+, zero dependencies. Set `GITHUB_TOKEN` (e.g. `export GITHUB_TOKEN=$( ```console $ actnode -[OLD] .github/workflows/ci.yml:7 node20 actions/checkout@v4 -> actions/checkout@v5 -[OLD] .github/workflows/ci.yml:10 node20 actions/upload-artifact@v4 -> actions/upload-artifact@v6 +[OLD] .github/workflows/ci.yml:7 node20 actions/checkout@v4 -> actions/checkout@v5 notes: https://github.com/actions/checkout/releases/tag/v5 +[OLD] .github/workflows/ci.yml:10 node20 actions/upload-artifact@v4 -> actions/upload-artifact@v6 notes: https://github.com/actions/upload-artifact/releases/tag/v6 +$ actnode --latest # newest node24 release instead of the smallest major jump $ actnode --fix # rewrite those uses: lines (SHA pins get a SHA + version comment) $ actnode --fail # exit 1 if anything is still old $ actnode --repo owner/name # API scan, no clone @@ -47,7 +50,7 @@ $ actnode --repo owner/name # API scan, no clone ![demo](site/demo.gif) -It reads each action's real `action.yml` at the exact ref you pin, follows composite actions and reusable workflows, and suggests the **smallest** major bump that runs on Node 24. Scan a remote repo without cloning: `actnode --repo owner/name` (or `--org owner`). +It reads each action's real `action.yml` at the exact ref you pin, follows composite actions and reusable workflows, and suggests the **smallest** major bump that runs on Node 24 (or `--latest` for the newest). Each suggestion includes a release-notes link. Scan a remote repo without cloning: `actnode --repo owner/name` (or `--org owner`). Full docs: [install](https://blackman99.github.io/actnode/docs/install/) · [usage](https://blackman99.github.io/actnode/docs/usage/) · [Action](https://blackman99.github.io/actnode/docs/action/) · [reference](https://blackman99.github.io/actnode/docs/reference/) · [FAQ](https://blackman99.github.io/actnode/docs/faq/) diff --git a/ROADMAP.md b/ROADMAP.md index 4d6feb7..d3db046 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -11,7 +11,7 @@ - Org/repo mode: `actnode --repo owner/name` and `--org owner` without cloning (API only) - Cache tag lookups across runs (`~/.cache/actnode`) -## v0.3 — ergonomics +## v0.3 (2026-10-19) — shipped - `--latest` to suggest the newest node24 release instead of the smallest jump - Show release-notes links for each major bump - Optional PR mode for the Action (open a PR with the `--fix` diff) diff --git a/action.yml b/action.yml index 11d6078..0a47acb 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: "actnode Node 24 runtime audit" -description: "Find workflow steps whose actions still run on Node 20 or older, and the release that moves each one to Node 24." +description: "Find workflow steps whose actions still run on Node 20 or older, suggest (or PR) the release that moves each one to Node 24." author: "Blackman99" branding: icon: "arrow-up-right" @@ -14,13 +14,31 @@ inputs: fail: description: "Fail the step when an old-runtime action is found (true/false)" default: "true" + latest: + description: "Suggest the newest release already on the target Node instead of the smallest major jump (true/false)" + default: "false" + create-pr: + description: "Apply --fix and open a pull request when there is a diff (true/false). Caller needs contents:write and pull-requests:write." + default: "false" + pr-branch: + description: "Branch name for create-pr" + default: "actnode/node-runtime" + pr-title: + description: "Pull request title for create-pr" + default: "chore: bump actions to Node 24 runtime" token: - description: "Token used to list tags of the actions you use" + description: "Token used to list tags (and to push/open a PR when create-pr is true)" default: ${{ github.token }} outputs: report: description: "Path to the JSON report" value: ${{ steps.scan.outputs.report }} + pr-number: + description: "Number of the opened/updated PR when create-pr ran; empty otherwise" + value: ${{ steps.pr.outputs.pr-number }} + pr-url: + description: "URL of the opened/updated PR when create-pr ran; empty otherwise" + value: ${{ steps.pr.outputs.pr-url }} runs: using: composite steps: @@ -33,10 +51,78 @@ runs: IN_PATH: ${{ inputs.path }} IN_TARGET: ${{ inputs.target }} IN_FAIL: ${{ inputs.fail }} + IN_LATEST: ${{ inputs.latest }} + IN_CREATE_PR: ${{ inputs.create-pr }} run: | + set -euo pipefail out="$RUNNER_TEMP/actnode.json" - python3 -m actnode scan "$IN_PATH" --target "$IN_TARGET" --format json -o "$out" + latest=() + [ "$IN_LATEST" = "true" ] && latest=(--latest) + python3 -m actnode scan "$IN_PATH" --target "$IN_TARGET" --format json -o "$out" "${latest[@]}" echo "report=$out" >> "$GITHUB_OUTPUT" - fail=() - [ "$IN_FAIL" = "true" ] && fail=(--fail) - python3 -m actnode scan "$IN_PATH" --target "$IN_TARGET" --format md -o "$GITHUB_STEP_SUMMARY" "${fail[@]}" + python3 -m actnode scan "$IN_PATH" --target "$IN_TARGET" --format md -o "$GITHUB_STEP_SUMMARY" "${latest[@]}" + if [ "$IN_CREATE_PR" = "true" ]; then + python3 -m actnode scan "$IN_PATH" --target "$IN_TARGET" --fix "${latest[@]}" + elif [ "$IN_FAIL" = "true" ]; then + python3 -m actnode scan "$IN_PATH" --target "$IN_TARGET" --fail "${latest[@]}" >/dev/null + fi + - id: pr + if: inputs.create-pr == 'true' + shell: bash + env: + GH_TOKEN: ${{ inputs.token }} + GITHUB_TOKEN: ${{ inputs.token }} + IN_PATH: ${{ inputs.path }} + IN_TARGET: ${{ inputs.target }} + IN_PR_BRANCH: ${{ inputs.pr-branch }} + IN_PR_TITLE: ${{ inputs.pr-title }} + IN_FAIL: ${{ inputs.fail }} + run: | + set -euo pipefail + git_root="${GITHUB_WORKSPACE:-.}" + if [ -d "${IN_PATH}/.git" ]; then + git_root="$IN_PATH" + fi + cd "$git_root" + paths=() + [ -d .github/workflows ] && paths+=(.github/workflows) + [ -f action.yml ] && paths+=(action.yml) + [ -f action.yaml ] && paths+=(action.yaml) + if [ ${#paths[@]} -eq 0 ] || git diff --quiet -- "${paths[@]}"; then + echo "actnode: no workflow changes to propose" + echo "pr-number=" >> "$GITHUB_OUTPUT" + echo "pr-url=" >> "$GITHUB_OUTPUT" + else + branch="$IN_PR_BRANCH" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git checkout -B "$branch" + git add -- "${paths[@]}" + if git diff --cached --quiet; then + echo "actnode: nothing staged for PR" + echo "pr-number=" >> "$GITHUB_OUTPUT" + echo "pr-url=" >> "$GITHUB_OUTPUT" + else + git commit -m "chore: bump GitHub Actions to Node ${IN_TARGET} runtime" + git push -u origin "HEAD:refs/heads/${branch}" --force-with-lease + body_file="$RUNNER_TEMP/actnode-pr-body.md" + python3 "${{ github.action_path }}/pr_body.py" \ + "$RUNNER_TEMP/actnode.json" "$IN_TARGET" > "$body_file" + existing_json=$(gh pr list --head "$branch" --state open --json number,url 2>/dev/null || echo "[]") + num=$(printf '%s' "$existing_json" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d[0]['number'] if d else '')") + url=$(printf '%s' "$existing_json" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d[0]['url'] if d else '')") + if [ -n "$num" ]; then + gh pr edit "$num" --title "$IN_PR_TITLE" --body-file "$body_file" || true + echo "Updated PR #$num" + else + url=$(gh pr create --title "$IN_PR_TITLE" --body-file "$body_file" --head "$branch") + num=$(gh pr view "$branch" --json number --jq .number) + echo "Opened PR #$num → $url" + fi + echo "pr-number=$num" >> "$GITHUB_OUTPUT" + echo "pr-url=$url" >> "$GITHUB_OUTPUT" + fi + fi + if [ "$IN_FAIL" = "true" ]; then + REPORT="$RUNNER_TEMP/actnode.json" python3 -c 'import json,os,pathlib,sys; data=json.loads(pathlib.Path(os.environ["REPORT"]).read_text(encoding="utf-8")); sys.exit(1 if any(f.get("status") in ("old","no-fix") for f in data.get("findings",[])) else 0)' + fi diff --git a/docs/action.md b/docs/action.md index 3f281e7..cdc5f4d 100644 --- a/docs/action.md +++ b/docs/action.md @@ -13,7 +13,7 @@ jobs: fail: true ``` -`@v0` is a moving major tag that always points at the latest v0.x release (pin `@v0.2.0` or a SHA for a fixed version). +`@v0` is a moving major tag that always points at the latest v0.x release (pin `@v0.3.0` or a SHA for a fixed version). The step writes a Markdown table to the job summary and fails if any step uses an action older than Node 24. @@ -24,10 +24,45 @@ The step writes a Markdown table to the job summary and fails if any step uses a | `path` | `.` | repository root to scan | | `target` | `24` | minimum Node major | | `fail` | `true` | fail the step when something old is found | -| `token` | `github.token` | used to list tags of the actions you use | +| `latest` | `false` | suggest the newest release already on the target Node instead of the smallest major jump | +| `create-pr` | `false` | apply `--fix` and open a PR when there is a diff | +| `pr-branch` | `actnode/node-runtime` | branch name for `create-pr` | +| `pr-title` | `chore: bump actions to Node 24 runtime` | PR title for `create-pr` | +| `token` | `github.token` | used to list tags; also to push/open a PR when `create-pr` is true | ## Outputs | Output | Meaning | |---|---| | `report` | path to the JSON report | +| `pr-number` | number of the opened/updated PR when `create-pr` ran (empty otherwise) | +| `pr-url` | URL of that PR (empty otherwise) | + +## Optional PR mode + +For a scheduled (or `workflow_dispatch`) workflow on the default branch, actnode can rewrite `uses:` lines and open a PR: + +```yaml +name: node-runtime-pr +on: + schedule: + - cron: "0 9 * * 1" + workflow_dispatch: +permissions: + contents: write + pull-requests: write +jobs: + bump: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: Blackman99/actnode@v0 + with: + create-pr: true + fail: false # PR opened; don't fail the job after proposing fixes + # latest: true # optional: jump to the newest node24 release +``` + +- No PR is opened when `--fix` produces an empty diff. +- An existing open PR on `pr-branch` is updated (force-with-lease push + title/body edit). +- The calling workflow needs `contents: write` and `pull-requests: write` (and a token that can push — default `github.token` is enough for same-repo PRs). diff --git a/docs/faq.md b/docs/faq.md index 19b9df5..1fc5c49 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -7,7 +7,7 @@ It runs node20 actions on Node 24 today, but the deprecation annotation still fi Dependabot opens version bumps if it's configured for `github-actions`, one PR per action, and doesn't tell you which ones are about the runtime or which are hidden inside composite actions. actnode answers the runtime question across the whole repo in one run, and works where Dependabot isn't set up. **Why the smallest major and not the latest?** -Fewer breaking changes. `actions/checkout@v5` already runs on Node 24; you don't need to jump to v7 to clear the warning. Pick the latest on your own schedule. +Fewer breaking changes. `actions/checkout@v5` already runs on Node 24; you don't need to jump to v7 to clear the warning. Pass `--latest` (or Action input `latest: true`) when you *do* want the newest node24-capable release. **An action has no Node 24 release. Now what?** actnode reports it as `OLD` with "no release on node24 yet". Look for an open issue upstream (many exist: search "Node.js 24" in that repo), fork and change `runs.using`, or replace the action. @@ -23,3 +23,6 @@ Yes: `actnode --repo owner/name` or `actnode --org owner`. Org mode scans public **Where are tags cached?** Under `~/.cache/actnode` (or `$XDG_CACHE_HOME/actnode`), 24h TTL. Use `--no-cache` to bypass. + +**Where do release-notes links come from?** +Each suggested bump includes a `release_notes` URL pointing at `https://github.com/{owner}/{repo}/releases/tag/{tag}` for the suggested tag. Shown in text, Markdown, and JSON output. diff --git a/docs/reference.md b/docs/reference.md index 059fad0..c3b114b 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -3,7 +3,7 @@ ``` actnode [scan] [PATH] [--repo OWNER/NAME] [--org OWNER] [--target N] [--format text|json|md] [-o FILE] - [--fix] [--fail] [--all] [--no-cache] + [--fix] [--latest] [--fail] [--all] [--no-cache] actnode demo actnode --version ``` @@ -17,6 +17,7 @@ actnode --version | `--format` | `text` (default), `json` (every finding), `md` (problem table, for job summaries) | | `-o FILE` | write to a file; `md` appends (so it works with `$GITHUB_STEP_SUMMARY`) | | `--fix` | rewrite direct `uses:` lines to the suggested ref (local PATH only) | +| `--latest` | suggest the newest release already on the target Node (default: smallest major jump) | | `--fail` | exit code 1 if any step uses an older runtime | | `--all` | in text mode, also show `ok`, composite, workflow and docker steps | | `--no-cache` | skip the on-disk tag cache (`~/.cache/actnode` / `$XDG_CACHE_HOME/actnode`) | @@ -40,7 +41,8 @@ Exit codes: `0` ok, `1` old runtime found with `--fail`, `2` usage error or GitH ```json {"target": 24, "findings": [ {"file": ".github/workflows/ci.yml", "line": 7, "uses": "actions/checkout@v4", - "runtime": "node20", "status": "old", "suggest": "actions/checkout@v5", "via": null, "note": ""} + "runtime": "node20", "status": "old", "suggest": "actions/checkout@v5", "via": null, "note": "", + "release_notes": "https://github.com/actions/checkout/releases/tag/v5"} ]} ``` diff --git a/docs/usage.md b/docs/usage.md index d13abb1..4814323 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -32,6 +32,20 @@ Findings are labeled `owner/repo:.github/workflows/ci.yml`. Forks and archived r `PATH`, `--repo`, and `--org` are mutually exclusive. +## Latest vs smallest jump + +By default actnode suggests the **smallest major** that already runs on Node 24 (fewer breaking changes). Pass `--latest` to jump straight to the newest release that is already on the target Node: + +```bash +actnode # -> actions/checkout@v5 (smallest jump) +actnode --latest # -> actions/checkout@v7 (newest on node24) +actnode --latest --fix +``` + +## Release notes + +Every finding with a suggested bump includes a `release_notes` URL (GitHub releases page for that tag). Text mode prints `notes: https://…`; Markdown adds a **Release notes** column; JSON adds a `release_notes` field. + ## Fix ```bash diff --git a/pr_body.py b/pr_body.py new file mode 100644 index 0000000..8dedf9b --- /dev/null +++ b/pr_body.py @@ -0,0 +1,46 @@ +"""Build a markdown PR body from an actnode JSON report. Usage: pr_body.py REPORT.json TARGET > body.md""" +from __future__ import annotations + +import json +import sys +from pathlib import Path + + +def main(argv=None): + argv = list(sys.argv[1:] if argv is None else argv) + report = Path(argv[0]) + target = argv[1] if len(argv) > 1 else "24" + lines = [ + "## actnode Node runtime bump", + "", + "Opened by [actnode](https://github.com/Blackman99/actnode) (`create-pr: true`).", + f"Direct `uses:` lines were rewritten to releases that already run on Node {target}.", + "Major bumps can carry breaking changes — read the release-notes links before merging.", + "", + ] + if report.is_file(): + data = json.loads(report.read_text(encoding="utf-8")) + old = [f for f in data.get("findings", []) if f.get("status") in ("old", "no-fix")] + if not old: + lines.append( + f"All JavaScript actions already run on node{data.get('target', target)} or newer." + ) + else: + lines += [ + "| Where | Action | Runtime | Upgrade to | Release notes |", + "|---|---|---|---|---|", + ] + for f in old: + up = f"`{f['suggest']}`" if f.get("suggest") else (f.get("note") or "") + via = f" (via `{f['via']}`)" if f.get("via") else "" + notes = f"[notes]({f['release_notes']})" if f.get("release_notes") else "" + lines.append( + f"| `{f['file']}:{f['line']}` | `{f['uses']}`{via} | " + f"{f.get('runtime') or ''} | {up} | {notes} |" + ) + sys.stdout.write("\n".join(lines) + "\n") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/pyproject.toml b/pyproject.toml index 829bcca..ba87478 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "actnode" -version = "0.2.0" +version = "0.3.0" description = "Find GitHub Actions steps still running on Node 20 (or older) and the release that moves each one to Node 24; optionally rewrite them." readme = "README.md" requires-python = ">=3.9" diff --git a/src/actnode/__init__.py b/src/actnode/__init__.py index d3ec452..493f741 100644 --- a/src/actnode/__init__.py +++ b/src/actnode/__init__.py @@ -1 +1 @@ -__version__ = "0.2.0" +__version__ = "0.3.0" diff --git a/src/actnode/cli.py b/src/actnode/cli.py index ca47f4a..a91d151 100644 --- a/src/actnode/cli.py +++ b/src/actnode/cli.py @@ -26,6 +26,8 @@ def render_text(findings, target): where = f"{f.file}:{f.line}" rt = f.runtime or "-" extra = f"-> {f.suggest}" if f.suggest else f.note + if f.release_notes: + extra = f"{extra} notes: {f.release_notes}" if extra else f"notes: {f.release_notes}" via = f" (inside {f.via})" if f.via else "" rows.append(f"[{MARK.get(f.status, f.status)}] {where:<34} {rt:<10} {f.uses} {extra}{via}") old = [f for f in findings if f.status in ("old", "no-fix")] @@ -44,11 +46,15 @@ def render_md(findings, target): if not old: out.append(f"All JavaScript actions run on node{target} or newer.") return "\n".join(out) + "\n" - out += ["| Where | Action | Runtime | Upgrade to |", "|---|---|---|---|"] + out += [ + "| Where | Action | Runtime | Upgrade to | Release notes |", + "|---|---|---|---|---|", + ] for f in old: up = f"`{f.suggest}`" if f.suggest else f.note via = f" (via `{f.via}`)" if f.via else "" - out.append(f"| `{f.file}:{f.line}` | `{f.uses}`{via} | {f.runtime} | {up} |") + notes = f"[notes]({f.release_notes})" if f.release_notes else "" + out.append(f"| `{f.file}:{f.line}` | `{f.uses}`{via} | {f.runtime} | {up} | {notes} |") return "\n".join(out) + "\n" @@ -74,6 +80,11 @@ def _add_scan_flags(s): s.add_argument("--format", choices=["text", "json", "md"], default="text") s.add_argument("-o", "--output", help="write report to this file (appends for md)") s.add_argument("--fix", action="store_true", help="rewrite uses: lines to the suggested refs") + s.add_argument( + "--latest", + action="store_true", + help="suggest the newest release already on the target Node instead of the smallest major jump", + ) s.add_argument("--fail", action="store_true", help="exit 1 if any step runs an old Node action") s.add_argument("--all", action="store_true", help="show every step, not only problems") s.add_argument("--no-cache", action="store_true", help="skip disk tag cache (~/.cache/actnode)") @@ -112,7 +123,7 @@ def main(argv=None): print("actnode: --fix requires a local checkout; cannot rewrite remote scans", file=sys.stderr) return 2 - resolver = Resolver(use_cache=not a.no_cache) + resolver = Resolver(use_cache=not a.no_cache, latest=a.latest) try: if a.repo: if "/" not in a.repo or a.repo.count("/") != 1: diff --git a/src/actnode/core.py b/src/actnode/core.py index c0144d5..1c5b11e 100644 --- a/src/actnode/core.py +++ b/src/actnode/core.py @@ -102,6 +102,26 @@ def _ver(tag: str): return tuple(int(x) if x else -1 for x in m.groups()) +def release_notes_url(suggest: str) -> Optional[str]: + """GitHub releases page for the tag in a suggest ref (e.g. owner/repo@v5 → …/releases/tag/v5).""" + if not suggest: + return None + ref_part, _, comment = suggest.partition(" # ") + tag = comment.strip() if comment.strip() else None + if "@" not in ref_part: + return None + spec, _, at = ref_part.rpartition("@") + parts = spec.split("/") + if len(parts) < 2: + return None + owner, repo = parts[0], parts[1] + if tag is None: + tag = at + if not tag or SHA_RE.match(tag): + return None + return f"https://github.com/{owner}/{repo}/releases/tag/{tag}" + + @dataclass class Finding: file: str @@ -112,6 +132,7 @@ class Finding: suggest: Optional[str] = None via: Optional[str] = None # composite/reusable workflow that pulled this in note: str = "" + release_notes: Optional[str] = None # GitHub releases URL for the suggested tag def to_dict(self): return asdict(self) @@ -123,6 +144,7 @@ class Resolver: use_cache: bool = True cache_path: Optional[Path] = None # override for tests; default cache_dir() cache_ttl: int = DEFAULT_CACHE_TTL + latest: bool = False # True → newest node{target} release; False → smallest major jump _yml: dict = field(default_factory=dict) _tags: dict = field(default_factory=dict) _wf: dict = field(default_factory=dict) @@ -214,7 +236,11 @@ def _save_tag_cache(self, owner, repo, tags): pass def suggest(self, owner, repo, sub, ref, target=CURRENT) -> Optional[str]: - """Smallest-surprise replacement ref whose action runs on node>=target, in the same ref style.""" + """Replacement ref whose action runs on node>=target, in the same ref style. + + Default (latest=False): smallest major jump that is already on target Node. + With self.latest=True: newest release that already runs on target Node. + """ tags = self.tags(owner, repo) if not tags: return None @@ -225,7 +251,7 @@ def suggest(self, owner, repo, sub, ref, target=CURRENT) -> Optional[str]: majors.append(mj) cur = _ver(ref)[0] if _ver(ref) else None best = None - for mj in majors[:6]: # newest majors first; keep the smallest jump that is still new enough + for mj in majors[:6]: # newest majors first if cur is not None and mj < cur: break in_major = [(n, s) for n, s in tags if _ver(n)[0] == mj] @@ -239,6 +265,8 @@ def suggest(self, owner, repo, sub, ref, target=CURRENT) -> Optional[str]: break continue best = (mj, in_major, newest_name, newest_sha) + if self.latest: + break # first match is the newest target-Node major if not best: return None mj, in_major, newest_name, newest_sha = best @@ -473,7 +501,10 @@ def _classify(root, rel, line, ref, y, parts, r, target, depth, via): st = "old" if sug else "no-fix" note = "" if sug else ("local action: bump runs.using" if not parts else f"no release on node{target} yet; ask upstream or fork") - out.append(Finding(rel, line, ref, using, st, suggest=sug, via=via, note=note)) + rn = release_notes_url(sug) if sug else None + out.append(Finding( + rel, line, ref, using, st, suggest=sug, via=via, note=note, release_notes=rn, + )) elif using == "composite": out.append(Finding(rel, line, ref, using, "composite", via=via)) if depth > 0: diff --git a/tests/test_core.py b/tests/test_core.py index cd838b2..99beffa 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -10,6 +10,7 @@ list_remote_workflows, node_major, parse_using, + release_notes_url, scan, scan_org, scan_repo, @@ -129,7 +130,9 @@ def test_scan_classifies(tmp_path): fs = scan(repo(tmp_path), Resolver(fetch=fake, use_cache=False)) by = {(f.uses, f.via): f for f in fs} assert by[("acme/js@v4", None)].suggest == "acme/js@v5" # smallest jump that is on node24 + assert by[("acme/js@v4", None)].release_notes == "https://github.com/acme/js/releases/tag/v5" assert by[("acme/js@" + "a" * 40, None)].suggest == f"acme/js@{SHA5} # v5.2.0" + assert by[("acme/js@" + "a" * 40, None)].release_notes == "https://github.com/acme/js/releases/tag/v5.2.0" assert by[("acme/new@v2", None)].status == "ok" assert by[("acme/stuck@v1", None)].status == "no-fix" assert by[("acme/comp@v1", None)].status == "composite" @@ -295,11 +298,12 @@ def test_cli_json_and_fail(tmp_path, monkeypatch, capsys): monkeypatch.setattr(core, "http_get", fake) - def fake_init(self, fetch=None, use_cache=True, cache_path=None, cache_ttl=86400): + def fake_init(self, fetch=None, use_cache=True, cache_path=None, cache_ttl=86400, latest=False): self.fetch = fake self.use_cache = False self.cache_path = cache_path self.cache_ttl = cache_ttl + self.latest = latest self._yml = {} self._tags = {} self._wf = {} @@ -321,11 +325,12 @@ def test_cli_repo_and_fix_refused(tmp_path, monkeypatch, capsys): monkeypatch.setattr(core, "http_get", fake) - def fake_init(self, fetch=None, use_cache=True, cache_path=None, cache_ttl=86400): + def fake_init(self, fetch=None, use_cache=True, cache_path=None, cache_ttl=86400, latest=False): self.fetch = fake self.use_cache = False self.cache_path = cache_path self.cache_ttl = cache_ttl + self.latest = latest self._yml = {} self._tags = {} self._wf = {} @@ -339,3 +344,85 @@ def fake_init(self, fetch=None, use_cache=True, cache_path=None, cache_ttl=86400 assert "local checkout" in err assert main(["--repo", "org/demo", "--org", "org"]) == 2 assert main([".", "--repo", "org/demo"]) == 2 + + +def test_release_notes_url(): + assert release_notes_url("acme/js@v5") == "https://github.com/acme/js/releases/tag/v5" + assert release_notes_url("acme/js/sub@v5.2.0") == "https://github.com/acme/js/releases/tag/v5.2.0" + assert release_notes_url(f"acme/js@{'a'*40} # v5.2.0") == "https://github.com/acme/js/releases/tag/v5.2.0" + assert release_notes_url(f"acme/js@{'a'*40}") is None + assert release_notes_url("") is None + + +def test_suggest_latest(tmp_path): + """Default = smallest jump (v5); --latest / Resolver.latest = newest (v6).""" + r = repo(tmp_path) + fs = scan(r, Resolver(fetch=fake, use_cache=False, latest=False)) + by = {(f.uses, f.via): f for f in fs} + assert by[("acme/js@v4", None)].suggest == "acme/js@v5" + fs_latest = scan(r, Resolver(fetch=fake, use_cache=False, latest=True)) + by_l = {(f.uses, f.via): f for f in fs_latest} + assert by_l[("acme/js@v4", None)].suggest == "acme/js@v6" + assert by_l[("acme/js@v4", None)].release_notes == "https://github.com/acme/js/releases/tag/v6" + assert by_l[("acme/js@" + "a" * 40, None)].suggest == f"acme/js@{'c'*40} # v6.0.0" + + +def test_cli_latest(tmp_path, monkeypatch, capsys): + import actnode.core as core + + monkeypatch.setattr(core, "http_get", fake) + + def fake_init(self, fetch=None, use_cache=True, cache_path=None, cache_ttl=86400, latest=False): + self.fetch = fake + self.use_cache = False + self.cache_path = cache_path + self.cache_ttl = cache_ttl + self.latest = latest + self._yml = {} + self._tags = {} + self._wf = {} + + monkeypatch.setattr(core.Resolver, "__init__", fake_init) + r = repo(tmp_path) + assert main(["scan", str(r), "--format", "json"]) == 0 + data = json.loads(capsys.readouterr().out) + js = next(f for f in data["findings"] if f["uses"] == "acme/js@v4" and not f.get("via")) + assert js["suggest"] == "acme/js@v5" + assert js["release_notes"] == "https://github.com/acme/js/releases/tag/v5" + + assert main(["scan", str(r), "--latest", "--format", "json"]) == 0 + data = json.loads(capsys.readouterr().out) + js = next(f for f in data["findings"] if f["uses"] == "acme/js@v4" and not f.get("via")) + assert js["suggest"] == "acme/js@v6" + assert js["release_notes"] == "https://github.com/acme/js/releases/tag/v6" + + out = tmp_path / "notes.md" + main([str(r), "--format", "md", "-o", str(out)]) + md = out.read_text() + assert "Release notes" in md + assert "https://github.com/acme/js/releases/tag/v5" in md + + +def test_pr_body_helper(tmp_path): + import subprocess + import sys + from pathlib import Path as P + + report = tmp_path / "r.json" + report.write_text(json.dumps({ + "target": 24, + "findings": [{ + "file": ".github/workflows/ci.yml", "line": 7, "uses": "acme/js@v4", + "runtime": "node20", "status": "old", "suggest": "acme/js@v5", + "via": None, "note": "", + "release_notes": "https://github.com/acme/js/releases/tag/v5", + }], + }), encoding="utf-8") + root = P(__file__).resolve().parents[1] + body = subprocess.check_output( + [sys.executable, str(root / "pr_body.py"), str(report), "24"], + text=True, + ) + assert "Release notes" in body + assert "acme/js@v5" in body + assert "https://github.com/acme/js/releases/tag/v5" in body