• 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

97.3
/src/python/pants/backend/go/util_rules/embedcfg.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
11✔
5

6
import json
11✔
7
from collections.abc import Iterable, Mapping
11✔
8
from dataclasses import dataclass
11✔
9
from typing import Any
11✔
10

11
from pants.util.frozendict import FrozenDict
11✔
12
from pants.util.strutil import strip_prefix
11✔
13

14

15
@dataclass(frozen=True)
11✔
16
class EmbedConfig:
11✔
17
    patterns: FrozenDict[str, tuple[str, ...]]
11✔
18
    files: FrozenDict[str, str]
11✔
19

20
    def __init__(self, patterns: Mapping[str, Iterable[str]], files: Mapping[str, str]) -> None:
11✔
21
        """Configuration passed to the Go compiler to configure file embedding.
22

23
        The compiler relies entirely on the caller to map embed patterns to actual filesystem
24
        paths. All embed patterns
25
        contained in the package must be mapped. Consult
26
        `FirstPartyPkgAnalysis.embed_patterns` for the embed patterns obtained from analysis.
27

28
        :param patterns: Maps each pattern provided via a //go:embed directive to a list of file
29
          paths relative to the package directory for files to embed for that pattern. When the
30
          embedded variable is an `embed.FS`, those relative file paths define the virtual
31
          directory hierarchy exposed by the embed.FS filesystem abstraction. The relative file
32
          paths are resolved to actual filesystem paths for their content by consulting the
33
          `files` dictionary.
34
        :param files: Maps each virtual, relative file path used as a value in the `patterns`
35
          dictionary to the actual filesystem path with that file's content.
36
        """
37
        object.__setattr__(self, "patterns", FrozenDict({k: tuple(v) for k, v in patterns.items()}))
2✔
38
        object.__setattr__(self, "files", FrozenDict(files))
2✔
39

40
    @classmethod
11✔
41
    def from_json_dict(
11✔
42
        cls, d: dict[str, Any], prefix_to_strip: str | None = None
43
    ) -> EmbedConfig | None:
44
        patterns = d.get("Patterns", {})
2✔
45
        files = d.get("Files", {})
2✔
46
        if prefix_to_strip:
2✔
47
            files = {key: strip_prefix(value, prefix_to_strip) for key, value in files.items()}
2✔
48
        result = cls(
2✔
49
            patterns=FrozenDict({key: tuple(value) for key, value in patterns.items()}),
50
            files=FrozenDict(files),
51
        )
52
        return result if result else None
2✔
53

54
    def to_embedcfg(self) -> bytes:
11✔
55
        data = {
1✔
56
            "Patterns": dict(self.patterns),
57
            "Files": dict(self.files),
58
        }
59
        return json.dumps(data).encode("utf-8")
1✔
60

61
    def __bool__(self) -> bool:
11✔
62
        return bool(self.patterns) or bool(self.files)
2✔
63

64
    def merge(self, other: EmbedConfig) -> EmbedConfig:
11✔
65
        """Merge two EmbedConfig's into one.
66

67
        Overlapping keys must have the same values.
68
        """
69
        overlapping_patterns_keys = set(self.patterns.keys()) & set(other.patterns.keys())
1✔
70
        for key in overlapping_patterns_keys:
1✔
71
            if self.patterns[key] != other.patterns[key]:
1✔
72
                raise AssertionError(
1✔
73
                    "Unable to merge conflicting golang file embed configurations. This should not have occurred. "
74
                    "Please open an issue at https://github.com/pantsbuild/pants/issues/new/choose "
75
                    "with the following information: "
76
                    f"Patterns Key: {key}; Left: {self.patterns[key]}; Right: {other.patterns[key]} "
77
                )
78

79
        overlapping_files_keys = set(self.files.keys()) & set(other.files.keys())
1✔
80
        for key in overlapping_files_keys:
1✔
81
            if self.files[key] != other.files[key]:
1✔
82
                raise AssertionError(
×
83
                    "Unable to merge conflicting golang file embed configurations. This should not have occurred. "
84
                    "Please open an issue at https://github.com/pantsbuild/pants/issues/new/choose "
85
                    "with the following information: "
86
                    f"Files Key: {key}; Left: {self.patterns[key]}; Right: {other.patterns[key]} "
87
                )
88

89
        return EmbedConfig(
1✔
90
            patterns={**self.patterns, **other.patterns},
91
            files={**self.files, **other.files},
92
        )
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