Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion scripts/commit-signed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ shift 2
repo="${GITHUB_REPOSITORY:?}"
head="${EXPECTED_HEAD:-$(gh api "repos/$repo/git/ref/heads/$branch" --jq .object.sha)}"

tmp_b64=$(mktemp)
trap 'rm -f "$tmp_b64"' EXIT
repo_root=$(git rev-parse --show-toplevel 2>/dev/null || pwd)

additions='[]'
for path in "$@"; do
additions=$(jq --arg p "$path" --rawfile c <(base64 <"$path" | tr -d '\n') '. + [{path: $p, contents: $c}]' <<<"$additions")
rel_path=$(realpath --relative-to="$repo_root" -- "$path")
[[ $rel_path != .. && $rel_path != ../* && $rel_path != . && $rel_path != /* ]] || { echo "commit-signed.sh: path outside repository: $path" >&2; exit 1; }
base64 <"$path" | tr -d '\n' >"$tmp_b64"
additions=$(jq --arg p "$rel_path" --rawfile c "$tmp_b64" '. + [{path: $p, contents: $c}]' <<<"$additions")
done

jq -n \
Expand Down
6 changes: 5 additions & 1 deletion scripts/open-signed-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ else
gh api "repos/$repo/git/refs" -f ref="refs/heads/$branch" -f sha="$main_sha" >/dev/null
fi

tmp_b64=$(mktemp)
trap 'rm -f "$tmp_b64"' EXIT

additions='[]' deletions='[]'
for path in "$@"; do
if [[ -e $path ]]; then
# Files, not arguments: a file's base64 can be longer than one argument may be.
additions=$(jq --arg p "$path" --rawfile c <(base64 <"$path" | tr -d '\n') '. + [{path: $p, contents: $c}]' <<<"$additions")
base64 <"$path" | tr -d '\n' >"$tmp_b64"
additions=$(jq --arg p "$path" --rawfile c "$tmp_b64" '. + [{path: $p, contents: $c}]' <<<"$additions")
else
deletions=$(jq --arg p "$path" '. + [{path: $p}]' <<<"$deletions")
fi
Expand Down
10 changes: 6 additions & 4 deletions web/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _resolve_cli(explicit: str) -> str | None:
PR_CACHE: dict[str, tuple[float, dict]] = {}
CACHE_LOCK = threading.Lock()
FILE_LOCK = threading.Lock()
CLI_LOCK = threading.Lock()


def _detect_git_root() -> str | None:
Expand Down Expand Up @@ -198,7 +199,8 @@ def fetch_pr_status(pr_number: int, upstream: str = "NixOS/nixpkgs", channel: st
def hold_add_argv(name: str, kind: str, entry: dict, target: str) -> list[str]:
if not valid_name(name):
raise ValueError(f"invalid package name {name!r}")
src = entry.get("from", "current")
default_from = "current" if kind == "fix" else "previous"
src = entry.get("from", default_from)
if isinstance(src, dict):
src = src.get("rev", "")
if not isinstance(src, str) or not src or src.startswith("-"):
Expand Down Expand Up @@ -360,7 +362,7 @@ def _send_json(self, status: int, obj: object, send_body: bool = True) -> None:

def _run_cli(self, argv: list[str], target: str, timeout: int) -> None:
try:
with FILE_LOCK:
with CLI_LOCK:
os.makedirs(os.path.dirname(target), exist_ok=True)
res = subprocess.run(argv, cwd=os.path.dirname(target), capture_output=True, text=True, timeout=timeout, check=False)
except subprocess.TimeoutExpired:
Expand Down Expand Up @@ -484,8 +486,8 @@ def do_POST(self):
target, _ = resolve_file(args.holds, "held-packages.json")
argv = [CLI, "hold", "remove", "--file", target, "--", name]
else:
target, _ = resolve_file(args.holds, "held-packages.json")
argv = [CLI, "release", "--", name, os.path.dirname(target)]
self._send_json(400, {"ok": False, "error": "kind must be hold, fix, or pr"})
return
self._run_cli(argv, target, timeout=30)


Expand Down