• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 25441711719

06 May 2026 02:31PM UTC coverage: 92.915%. Remained the same
25441711719

push

github

web-flow
use sha pin (with comment) format for generated actions (#23312)

Per the GitHub Action best practices we recently enabled at #23249, we
should pin each action to a SHA so that the reference is actually
immutable.

This will -- I hope -- knock out a large chunk of the 421 alerts we
currently get from zizmor. The next followup would then be upgrades and
harmonizing the generated and none-generated pins.

Notice: This idea was suggested by Claude while going over pinact output
and I was surprised to see that post processing the yaml wasn't too
gross.

92206 of 99237 relevant lines covered (92.91%)

4.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/python/pants/backend/openapi/goals/tailor.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
3✔
5

6
import itertools
3✔
7
from collections.abc import Iterable
3✔
8
from dataclasses import dataclass
3✔
9

10
from pants.backend.openapi.dependency_inference import ParseOpenApiSources, parse_openapi_sources
3✔
11
from pants.backend.openapi.subsystems.openapi import OpenApiSubsystem
3✔
12
from pants.backend.openapi.target_types import (
3✔
13
    OPENAPI_FILE_EXTENSIONS,
14
    OpenApiDocumentGeneratorTarget,
15
    OpenApiSourceGeneratorTarget,
16
)
17
from pants.core.goals.tailor import (
3✔
18
    AllOwnedSources,
19
    PutativeTarget,
20
    PutativeTargets,
21
    PutativeTargetsRequest,
22
)
23
from pants.engine.fs import PathGlobs
3✔
24
from pants.engine.intrinsics import path_globs_to_digest, path_globs_to_paths
3✔
25
from pants.engine.rules import Rule, collect_rules, rule
3✔
26
from pants.engine.unions import UnionRule
3✔
27
from pants.util.dirutil import group_by_dir
3✔
28
from pants.util.logging import LogLevel
3✔
29

30

31
@dataclass(frozen=True)
3✔
32
class PutativeOpenApiTargetsRequest(PutativeTargetsRequest):
3✔
33
    pass
3✔
34

35

36
@rule(level=LogLevel.DEBUG, desc="Determine candidate OpenAPI targets to create")
3✔
37
async def find_putative_targets(
3✔
38
    req: PutativeOpenApiTargetsRequest,
39
    all_owned_sources: AllOwnedSources,
40
    openapi_subsystem: OpenApiSubsystem,
41
) -> PutativeTargets:
42
    if not openapi_subsystem.tailor_targets:
1✔
43
        return PutativeTargets()
1✔
44

45
    all_openapi_files = await path_globs_to_paths(
1✔
46
        req.path_globs(*(f"**/openapi{ext}" for ext in OPENAPI_FILE_EXTENSIONS))
47
    )
48
    targets = {*all_openapi_files.files}
1✔
49
    paths = tuple(targets)
1✔
50

51
    while paths:
1✔
52
        digest = await path_globs_to_digest(PathGlobs(paths))
1✔
53
        result = await parse_openapi_sources(
1✔
54
            ParseOpenApiSources(
55
                sources_digest=digest,
56
                paths=tuple(paths),
57
            )
58
        )
59

60
        targets.update(result.dependencies.keys())
1✔
61
        paths = tuple(v for v in itertools.chain(*result.dependencies.values()) if v not in targets)
1✔
62

63
    unowned_openapi_documents = set(all_openapi_files.files) - set(all_owned_sources)
1✔
64
    unowned_openapi_sources = targets - set(all_owned_sources)
1✔
65
    classified_unowned_openapi_files = {
1✔
66
        OpenApiDocumentGeneratorTarget: unowned_openapi_documents,
67
        OpenApiSourceGeneratorTarget: unowned_openapi_sources,
68
    }
69

70
    putative_targets = []
1✔
71
    for tgt_type, filepaths in classified_unowned_openapi_files.items():
1✔
72
        for dirname, filenames in group_by_dir(filepaths).items():
1✔
73
            name = "openapi" if tgt_type == OpenApiDocumentGeneratorTarget else None
1✔
74
            putative_targets.append(
1✔
75
                PutativeTarget.for_target_type(
76
                    tgt_type, path=dirname, name=name, triggering_sources=sorted(filenames)
77
                )
78
            )
79

80
    return PutativeTargets(putative_targets)
1✔
81

82

83
def rules() -> Iterable[Rule | UnionRule]:
3✔
84
    return (
3✔
85
        *collect_rules(),
86
        UnionRule(PutativeTargetsRequest, PutativeOpenApiTargetsRequest),
87
    )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc