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
169 changes: 169 additions & 0 deletions .github/workflows/materialize-global-packages-current-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
name: Materialize global packages on current main

on:
pull_request:
branches:
- main
paths:
- .github/workflows/materialize-global-packages-current-main.yml
- scripts/materialize_global_packages_current_main.py
workflow_dispatch:

permissions:
contents: read

concurrency:
group: materialize-global-packages-current-main-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
PRODUCT_MAIN: 9b8e5f3d3b98845436899b9a8645f3ce19689f85
REVIEWED_FEATURE: c5ed46eb80c348aa5b766e9b00d7c50bfb94e0ab

jobs:
materialize:
name: Current-main product materialization
runs-on: ubuntu-24.04
timeout-minutes: 60
steps:
- name: Check out materializer without credentials
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
persist-credentials: false
show-progress: false

- name: Check out exact product main
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: zed-pkg/zed-cli
ref: ${{ env.PRODUCT_MAIN }}
path: product
fetch-depth: 1
persist-credentials: false
show-progress: false

- name: Check out exact reviewed feature source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: zed-pkg/zed-cli
ref: ${{ env.REVIEWED_FEATURE }}
path: feature
fetch-depth: 1
persist-credentials: false
show-progress: false

- name: Verify immutable inputs
shell: bash
run: |
set -euo pipefail
test "${#PRODUCT_MAIN}" -eq 40
test "${#REVIEWED_FEATURE}" -eq 40
test "$(git -C product rev-parse HEAD)" = "$PRODUCT_MAIN"
test "$(git -C feature rev-parse HEAD)" = "$REVIEWED_FEATURE"

- name: Install repository Rust toolchain
uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30
with:
toolchain: stable
components: rustfmt,clippy

- name: Assemble ordinary current-main source
shell: bash
run: |
set -euo pipefail
# Register the six reviewed new files as intent-to-add before the
# materializer copies their bytes. Ordinary `git diff` then includes
# them in the exact allowlist, patch, and artifact inventory without
# staging any content or mutating the source commit.
while IFS= read -r relative; do
mkdir -p "product/$(dirname "$relative")"
: > "product/$relative"
done <<'EOF'
.github/workflows/global-packages.yml
.zpkg.lock
.zpkg.toml
docs/global-packages.md
src/global.rs
tests/global_cli.rs
EOF
git -C product add -N -- \
.github/workflows/global-packages.yml \
.zpkg.lock \
.zpkg.toml \
docs/global-packages.md \
src/global.rs \
tests/global_cli.rs

python3 -m py_compile scripts/materialize_global_packages_current_main.py
python3 scripts/materialize_global_packages_current_main.py \
--product product \
--feature feature

- name: Verify focused and complete product gates
working-directory: product
shell: bash
run: |
set -euo pipefail
cargo fmt --all --check
cargo test --locked --lib global::tests
cargo test --locked frozen_local_metadata_preserves_lock_identity_and_provenance
cargo test --locked --test global_cli
cargo clippy --locked --all-targets --all-features -- -D warnings
cargo test --locked --all-targets --all-features
cargo build --release --locked --bin zed
./target/release/zed --version

- name: Produce exact ordinary-source artifact
shell: bash
run: |
set -euo pipefail
mkdir -p artifacts
git -C product diff --binary > artifacts/global-packages-current-main.patch
git -C product diff --name-only -z > artifacts/changed-files.zlist
python3 - <<'PY'
import json
import subprocess
from pathlib import Path

product = Path('product')
names = [
item.decode()
for item in subprocess.check_output(
['git', '-C', str(product), 'diff', '--name-only', '-z']
).split(b'\0')
if item
]
Path('artifacts/changed-files.json').write_text(
json.dumps(names, indent=2) + '\n'
)
Path('artifacts/materialization.json').write_text(
json.dumps(
{
'schema': 'zed.global-packages-materialization/v1',
'product_base': '9b8e5f3d3b98845436899b9a8645f3ce19689f85',
'reviewed_feature': 'c5ed46eb80c348aa5b766e9b00d7c50bfb94e0ab',
'changed_files': names,
},
sort_keys=True,
indent=2,
) + '\n'
)
PY
tar --null -czf artifacts/global-packages-current-main-files.tar.gz \
-C product -T artifacts/changed-files.zlist
sha256sum \
artifacts/global-packages-current-main.patch \
artifacts/global-packages-current-main-files.tar.gz \
artifacts/changed-files.json \
artifacts/materialization.json \
> artifacts/SHA256SUMS
test -z "$(git -C feature status --porcelain)"

- name: Upload validated source delta
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: global-packages-current-main-source
path: artifacts/
if-no-files-found: error
retention-days: 3
121 changes: 121 additions & 0 deletions scripts/fix_global_packages_materialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env python3
"""Narrow compatibility repair for the current-main global package assembly.

The main materializer intentionally copies the reviewed feature files before
composing them with current main. This verifier preserves the current lockfile
import surface, normalizes the root-help adapter to the `Result<i32>` contract
expected by the modular dispatcher, boxes the large install payload so the
public command enum remains Clippy-clean, and removes a redundant Zed package
dependency while Cargo still owns that dependency through an immutable Git pin.
It is idempotent and fails on unknown source shapes rather than guessing.
"""

from __future__ import annotations

import argparse
from pathlib import Path


def patch_ops(product: Path) -> None:
path = product / "src/ops.rs"
text = path.read_text()
complete = "use zed_interfaces::lockfile::{LockedPackage, Lockfile};"
legacy = "use zed_interfaces::lockfile::Lockfile;"
if complete in text:
return
if legacy not in text:
raise SystemExit("src/ops.rs has an unknown lockfile import shape")
path.write_text(text.replace(legacy, complete, 1))


def patch_global(product: Path) -> None:
path = product / "src/global.rs"
text = path.read_text()

mapped_arm = "Route::RootHelp => Some(print_root_help().map(|()| 0)),"
direct_arm = "Route::RootHelp => Some(print_root_help()),"
if mapped_arm in text:
text = text.replace(mapped_arm, direct_arm, 1)
elif direct_arm not in text:
raise SystemExit("src/global.rs has an unknown RootHelp dispatch shape")

variants = (
'''fn print_root_help() -> Result<()> {
crate::completion::print_root_help()
}
''',
'''fn print_root_help() -> Result<i32> {
crate::completion::print_root_help()
}
''',
'''fn print_root_help() -> Result<()> {
let mut command = dev::augment_root_command(augment_root_command(crate::cli::Cli::command()));
command.print_help().context("printing zed help")?;
println!();
Ok(())
}
''',
)
replacement = '''fn print_root_help() -> Result<i32> {
crate::completion::print_root_help()?;
Ok(0)
}
'''
if replacement not in text:
for variant in variants:
if variant in text:
text = text.replace(variant, replacement, 1)
break
else:
raise SystemExit("src/global.rs has an unknown print_root_help shape")

boxed_variant = " Install(Box<GlobalInstallArgs>),"
plain_variant = " Install(GlobalInstallArgs),"
if boxed_variant not in text:
if plain_variant not in text:
raise SystemExit("src/global.rs has an unknown GlobalAction::Install shape")
text = text.replace(plain_variant, boxed_variant, 1)

boxed_match = (
" GlobalAction::Install(options) => install(&cfg, &bin_dir, *options),"
)
plain_match = (
" GlobalAction::Install(options) => install(&cfg, &bin_dir, options),"
)
if boxed_match not in text:
if plain_match not in text:
raise SystemExit("src/global.rs has an unknown install dispatch shape")
text = text.replace(plain_match, boxed_match, 1)

path.write_text(text)


def patch_package_manifest(product: Path) -> None:
path = product / ".zpkg.toml"
text = path.read_text()
redundant = '''[dependencies]
"zed-pkg/zed-interfaces" = "^0.1.0"

'''
if redundant in text:
text = text.replace(redundant, "", 1)
elif "zed-pkg/zed-interfaces" in text:
raise SystemExit(".zpkg.toml has an unknown zed-interfaces dependency shape")
path.write_text(text)


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--product", type=Path, required=True)
args = parser.parse_args()
product = args.product.resolve()
patch_ops(product)
patch_global(product)
patch_package_manifest(product)
print(
"preserved current-main imports, normalized root help, boxed the install payload, and aligned package metadata with Cargo"
)


if __name__ == "__main__":
main()
Loading
Loading