id: endoflife-runtime-lifecycle-audit
namespace: company.platform
description: |
Weekly audit of the runtimes and services a codebase pins. Pins come from an
explicit list and, optionally, from a cloned repository. Every pin is checked
against the live endoflife.date API, classified as EOL, EXPIRING or SUPPORTED,
and one GitHub issue is filed per runtime that needs attention.
inputs:
- id: runtimes
type: ARRAY
itemType: STRING
displayName: Pinned runtimes to audit
description: Each entry is product@version, using endoflife.date product names
such as python, nodejs, go, ruby, php, postgresql, mysql, redis, nginx,
mongodb or kubernetes. Merged with anything the optional repository scan
finds.
defaults:
- python@3.9.18
- nodejs@20.11.0
- postgresql@13.4
- kubernetes@1.34.1
- go@1.25.1
- id: repository
type: STRING
required: false
displayName: Repository to scan (optional)
description: HTTPS clone URL of a public repository. When set, pins are
discovered from .python-version, .nvmrc, .node-version, .ruby-version,
.tool-versions, go.mod, Dockerfile* and docker-compose files.
- id: warn_days
type: INT
displayName: Warning window in days
description: A runtime whose end-of-life date falls within this many days is
flagged as EXPIRING instead of SUPPORTED.
defaults: 180
- id: issue_repository
type: STRING
displayName: Repository that receives the issues
description: Where lifecycle issues are opened, in owner/repo form. Only used
when dry_run is false.
defaults: your-org/your-repo
- id: dry_run
type: BOOL
displayName: Dry run
description: Log every issue the flow would open without calling GitHub. Leave
this on until the findings look right.
defaults: true
triggers:
- id: weekly
type: io.kestra.plugin.core.trigger.Schedule
description: Lifecycle dates move on the upstream side, not in your code, so a
pin that was healthy last month can be expiring today. Runs every Monday
at 07:00 with the default inputs.
cron: "0 7 * * 1"
tasks:
- id: checkout_and_audit
type: io.kestra.plugin.core.flow.WorkingDirectory
description: One directory so the checkout, the pin discovery and the audit all
see the same files.
tasks:
- id: clone_repository
type: io.kestra.plugin.git.Clone
description: Shallow clone of the repository to scan. Skipped when no repository
is given, in which case only the runtimes input is audited.
runIf: "{{ (inputs.repository ?? '') != '' }}"
url: "{{ inputs.repository }}"
- id: collect_pins
type: io.kestra.plugin.scripts.python.Script
description: >
Merges the runtimes input with every pin found in the checkout and
writes pins.json. Unparseable values such as lts/* or latest are
counted but never guessed at. Image names and asdf tool names are
mapped to endoflife.date product slugs.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: python:3.12-slim
inputFiles:
runtimes.json: "{{ inputs.runtimes | toJson }}"
script: |
import json
import os
import re
ALIASES = {
"python": "python", "node": "nodejs", "nodejs": "nodejs",
"go": "go", "golang": "go", "ruby": "ruby", "php": "php",
"postgres": "postgresql", "postgresql": "postgresql",
"mysql": "mysql", "mariadb": "mariadb", "redis": "redis",
"nginx": "nginx", "mongo": "mongodb", "mongodb": "mongodb",
"kubernetes": "kubernetes", "terraform": "terraform",
}
SKIP_DIRS = {".git", "node_modules", "vendor", ".venv", "venv", "__pycache__"}
VERSION = re.compile(r"^v?(\d+(?:\.\d+){0,2})")
FROM_LINE = re.compile(r"^\s*FROM\s+(?:--\S+\s+)*(\S+)", re.IGNORECASE)
IMAGE_LINE = re.compile(r"^\s*image:\s*[\"']?([^\s\"']+)")
pins = {}
unparsed = []
def add(product, raw_version, source):
product = ALIASES.get(product.lower().strip(), product.lower().strip())
match = VERSION.match((raw_version or "").strip().replace("ruby-", ""))
if not match:
unparsed.append("{}@{} ({})".format(product, raw_version, source))
return
entry = pins.setdefault((product, match.group(1)), set())
entry.add(source)
def add_image(reference, source):
reference = reference.split("@")[0]
path, _, last = reference.rpartition("/")
if path not in ("", "library", "docker.io/library"):
return
name, _, tag = last.partition(":")
if name.lower() in ALIASES and tag:
add(name, tag, source)
for entry in json.load(open("runtimes.json", encoding="utf-8")):
product, _, version = str(entry).partition("@")
add(product, version, "runtimes input")
for folder, dirs, files in os.walk("."):
dirs[:] = [d for d in dirs if d not in SKIP_DIRS]
for name in files:
path = os.path.join(folder, name)
source = path[2:] if path.startswith("./") else path
lower = name.lower()
try:
lines = open(path, encoding="utf-8", errors="ignore").read().splitlines()
except OSError:
continue
first = next((l.strip() for l in lines if l.strip() and not l.strip().startswith("#")), "")
if lower == ".python-version":
add("python", first, source)
elif lower in (".nvmrc", ".node-version"):
add("nodejs", first, source)
elif lower == ".ruby-version":
add("ruby", first, source)
elif lower == ".tool-versions":
for line in lines:
parts = line.split("#")[0].split()
if len(parts) >= 2:
add(parts[0], parts[1], source)
elif lower == "go.mod":
for line in lines:
found = re.match(r"^go\s+(\d+\.\d+(?:\.\d+)?)", line)
if found:
add("go", found.group(1), source)
elif lower.startswith("dockerfile"):
for line in lines:
found = FROM_LINE.match(line)
if found:
add_image(found.group(1), source)
elif lower.startswith(("docker-compose", "compose")) and lower.endswith((".yml", ".yaml")):
for line in lines:
found = IMAGE_LINE.match(line)
if found:
add_image(found.group(1), source)
result = [
{"product": product, "version": version, "sources": sorted(sources)[:5]}
for (product, version), sources in sorted(pins.items())
]
if not result:
raise SystemExit("No pinned runtime could be parsed. Nothing to audit.")
with open("pins.json", "w", encoding="utf-8") as handle:
json.dump(result, handle)
print("pins found: {}, unparsed values skipped: {}".format(len(result), len(unparsed)))
for item in unparsed[:20]:
print("skipped " + item)
- id: audit_lifecycle
type: io.kestra.plugin.scripts.python.Script
description: >
Calls the endoflife.date v1 API once per product, matches each pin to
its release cycle by longest version prefix, and classifies it. A
product the API does not know, or a version with no matching cycle, is
reported as unresolved rather than treated as healthy. If no product
can be resolved at all the task fails, so an API outage never reads as
a clean audit.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: python:3.12-slim
env:
WARN_DAYS: "{{ inputs.warn_days }}"
script: |
import datetime
import json
import os
import sys
import time
import urllib.error
import urllib.request
WARN_DAYS = int(os.environ.get("WARN_DAYS", "180"))
TODAY = datetime.date.today()
API = "https://endoflife.date/api/v1/products/{}/"
def fetch(product):
request = urllib.request.Request(API.format(product), headers={
"User-Agent": "kestra-endoflife-audit", "Accept": "application/json"})
for attempt in range(1, 4):
try:
with urllib.request.urlopen(request, timeout=20) as response:
return json.load(response)["result"]
except urllib.error.HTTPError as error:
if error.code == 404:
return None
if error.code < 500 or attempt == 3:
raise
except urllib.error.URLError:
if attempt == 3:
raise
time.sleep(2 * attempt)
def match_release(releases, version):
parts = version.split(".")
for size in range(len(parts), 0, -1):
candidate = ".".join(parts[:size])
for release in releases:
if str(release.get("name")) == candidate:
return release
return None
def target_release(releases):
live = [r for r in releases
if not r.get("isEol") and (r.get("releaseDate") or "") <= TODAY.isoformat()]
live.sort(key=lambda r: r.get("releaseDate") or "", reverse=True)
lts = [r for r in live if r.get("isLts")]
return (lts or live or [None])[0]
pins = json.load(open("pins.json", encoding="utf-8"))
catalog = {}
for product in sorted({p["product"] for p in pins}):
catalog[product] = fetch(product)
if not any(catalog.values()):
sys.exit("endoflife.date resolved none of the products: {}".format(sorted(catalog)))
groups, unresolved, rows = {}, [], []
for pin in pins:
product = catalog[pin["product"]]
label = "{} {}".format(pin["product"], pin["version"])
if product is None:
unresolved.append("{} (unknown product)".format(label))
continue
releases = product.get("releases") or []
release = match_release(releases, pin["version"])
if release is None:
unresolved.append("{} (no matching release cycle)".format(label))
continue
eol_from = (release.get("eolFrom") or "")[:10] or None
days_left = (datetime.date.fromisoformat(eol_from) - TODAY).days if eol_from else None
if release.get("isEol"):
verdict = "EOL"
elif days_left is not None and days_left <= WARN_DAYS:
verdict = "EXPIRING"
else:
verdict = "SUPPORTED"
rows.append("| {} | {} | {} | {} |".format(
label, release["name"], verdict, eol_from or "none published"))
# One group per product and release cycle, so 20 and 20.11.0 become one issue.
group = groups.setdefault((pin["product"], str(release["name"])), {
"product": pin["product"],
"cycle": str(release["name"]),
"verdict": verdict,
"eol_from": eol_from or "not published",
"days_left": days_left if days_left is not None else "n/a",
"target": (target_release(releases) or {}).get("name", "unknown"),
"latest_patch": (release.get("latest") or {}).get("name") or "unknown",
"link": "https://endoflife.date/" + pin["product"],
"versions": set(),
"sources": set(),
})
group["versions"].add(pin["version"])
group["sources"].update(pin["sources"])
attention = [g for g in groups.values() if g["verdict"] != "SUPPORTED"]
attention.sort(key=lambda g: (g["verdict"] != "EOL", g["product"], g["cycle"]))
findings = []
for group in attention:
record = dict(group)
record["versions"] = ", ".join(sorted(group["versions"]))
record["sources"] = ", ".join(sorted(group["sources"])[:10])
findings.append(json.dumps(record, sort_keys=True))
eol_count = sum(1 for g in attention if g["verdict"] == "EOL")
expiring_count = len(attention) - eol_count
supported_count = len(groups) - len(attention)
summary = "\n".join([
"Audited {} pin(s) across {} release cycle(s) on {}: {} EOL, {} expiring within {} days, {} supported, {} pin(s) unresolved.".format(
len(pins), len(groups), TODAY.isoformat(), eol_count, expiring_count, WARN_DAYS,
supported_count, len(unresolved)),
"| pin | cycle | verdict | end of life |",
"| --- | --- | --- | --- |",
] + rows + (["Unresolved: " + "; ".join(unresolved)] if unresolved else []))
print(summary)
print("::" + json.dumps({"outputs": {
"pin_count": len(pins),
"eol_count": eol_count,
"expiring_count": expiring_count,
"unresolved_count": len(unresolved),
"has_findings": len(findings) > 0,
"findings": findings,
"summary": summary,
}}) + "::")
- id: report
type: io.kestra.plugin.core.log.Log
description: The full verdict table, so a run with no findings still shows what
was checked.
message: "{{ outputs.audit_lifecycle.vars.summary }}"
- id: handle_findings
type: io.kestra.plugin.core.flow.If
description: Only runtimes that are EOL or expiring leave this branch as work.
condition: "{{ outputs.audit_lifecycle.vars.has_findings }}"
then:
- id: file_issues
type: io.kestra.plugin.core.flow.Loop
description: One pass per finding, serialized so GitHub search results stay
consistent between the lookup and the create.
values: "{{ outputs.audit_lifecycle.vars.findings }}"
concurrencyLimit: 1
tasks:
- id: mode
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.dry_run }}"
then:
- id: would_file
type: io.kestra.plugin.core.log.Log
message: |
DRY RUN would search {{ inputs.issue_repository }} for an issue titled "Runtime lifecycle: {{ fromJson(item.value).product }} {{ fromJson(item.value).cycle }}" (open or closed) and open one when there is none.
verdict: {{ fromJson(item.value).verdict }}, end of life {{ fromJson(item.value).eol_from }} ({{ fromJson(item.value).days_left }} days)
pinned in: {{ fromJson(item.value).sources }}
suggested target cycle: {{ fromJson(item.value).target }}
else:
- id: find_existing_issue
type: io.kestra.plugin.github.issues.Search
description: Open or closed counts as found, so a runtime someone already
triaged is not reported again every Monday.
oauthToken: "{{ secret('GITHUB_TOKEN') }}"
repository: "{{ inputs.issue_repository }}"
query: "in:title \"Runtime lifecycle: {{ fromJson(item.value).product }} {{
fromJson(item.value).cycle }}\""
fetchType: FETCH
- id: create_when_absent
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.find_existing_issue.size == 0 }}"
then:
- id: create_issue
type: io.kestra.plugin.github.issues.Create
description: One issue per runtime cycle, listing every file that pins it.
oauthToken: "{{ secret('GITHUB_TOKEN') }}"
repository: "{{ inputs.issue_repository }}"
title: "Runtime lifecycle: {{ fromJson(item.value).product }} {{
fromJson(item.value).cycle }} is {{
fromJson(item.value).verdict == 'EOL' ? 'end-of-life' :
'nearing end-of-life' }}"
labels:
- dependencies
- lifecycle
body: |
endoflife.date reports that `{{ fromJson(item.value).product }}` release cycle `{{ fromJson(item.value).cycle }}` is **{{ fromJson(item.value).verdict }}**.
| field | value |
| --- | --- |
| Pinned versions | `{{ fromJson(item.value).versions }}` |
| End of life | {{ fromJson(item.value).eol_from }} ({{ fromJson(item.value).days_left }} days) |
| Latest patch in this cycle | {{ fromJson(item.value).latest_patch }} |
| Suggested target cycle | {{ fromJson(item.value).target }} |
| Pinned in | {{ fromJson(item.value).sources }} |
Lifecycle data: {{ fromJson(item.value).link }}
Opened by the Kestra flow `{{ flow.id }}`, execution `{{ execution.id }}`.
else:
- id: already_filed
type: io.kestra.plugin.core.log.Log
message: "{{ fromJson(item.value).product }} {{ fromJson(item.value).cycle }}
already has issue #{{
outputs.find_existing_issue.row.number }} ({{
outputs.find_existing_issue.row.state }}). Nothing
opened."
errors:
- id: audit_failed
type: io.kestra.plugin.core.log.Log
level: ERROR
message: "Runtime lifecycle audit failed in execution {{ execution.id }}. No
verdict was produced, so do not read this run as a clean audit."
outputs:
- id: pin_count
type: INT
description: Distinct product and version pins audited, e.g. 5.
value: "{{ outputs.audit_lifecycle.vars.pin_count }}"
- id: eol_count
type: INT
description: Release cycles that are already end-of-life, e.g. 3.
value: "{{ outputs.audit_lifecycle.vars.eol_count }}"
- id: expiring_count
type: INT
description: Release cycles reaching end-of-life within warn_days, e.g. 1.
value: "{{ outputs.audit_lifecycle.vars.expiring_count }}"
- id: unresolved_count
type: INT
description: Pins that matched no product or release cycle, e.g. 0.
value: "{{ outputs.audit_lifecycle.vars.unresolved_count }}"