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
21 changes: 13 additions & 8 deletions .github/workflows/bazel-go.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: Bazel patch compatibility (Go)

# The Go flow of the real-Bazel tests (`go::` in `e2e_bazel_build`): hosted
# mode for a module that gazelle's `go_deps` resolves from `go.mod`, on
# each Bazel release below. bazel-compatibility.yml holds the legs and what
# every ecosystem shares; this file says when the Go legs run and on which
# releases.
# The Go flows of the real-Bazel tests (`go::` in `e2e_bazel_build`):
# hosted, vendored and agent mode for a module that gazelle's `go_deps`
# resolves from `go.mod`, on each Bazel release below.
# bazel-compatibility.yml holds the legs and what every ecosystem shares;
# this file says when the Go legs run and on which releases.
#
# Beyond what every leg needs, a Go leg downloads the Go SDK from
# dl.google.com (about 100 MB, held by its repository cache) and asks go.dev
# for the Go release list on every run. A Go module under test never comes
# from the repository cache: `go` fetches a module into the output base,
# which every test makes anew.
# which every test makes anew. The same holds for the modules gazelle is
# built from, which a test that runs `bazel run //:gazelle` has `go` fetch
# from proxy.golang.org.
#
# Not required for merge: no `merge_group` trigger, and no job here is a
# `needs` of ci.yml's `ci-ok`.
Expand All @@ -20,8 +22,9 @@ on:
types: [opened, synchronize, reopened, ready_for_review]
# What a pull request run covers: the Go flow and its fixture, the
# harness and the workflows that run it, the Bazel installer and its
# pins, and the Go files the flow runs through, as go-compatibility.yml
# lists them. Nothing another ecosystem's flow owns is here, so a change
# pins, the Go files the flow runs through, as go-compatibility.yml
# lists them, and what socket-patch does only in a Bazel workspace
# (`bazel/`). Nothing another ecosystem's flow owns is here, so a change
# to one ecosystem starts that ecosystem's legs only.
#
# What it does not cover: shared engine code (patch/redirect/mod.rs,
Expand All @@ -41,6 +44,7 @@ on:
- 'crates/*/src/**/*golang*'
- 'crates/*/src/**/*golang*/**'
- 'crates/socket-patch-core/src/vendor/go*.rs'
- 'crates/socket-patch-core/src/bazel/**'
push:
branches: [main]
# The pull request paths, and what only a push to main covers: the
Expand All @@ -60,6 +64,7 @@ on:
- 'crates/*/src/**/*golang*'
- 'crates/*/src/**/*golang*/**'
- 'crates/socket-patch-core/src/vendor/go*.rs'
- 'crates/socket-patch-core/src/bazel/**'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
- 'crates/socket-patch-core/src/patch/redirect/**'
- 'crates/socket-patch-core/src/hosted/**'
Expand Down
1 change: 1 addition & 0 deletions crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,7 @@ command's integration tests check its output.
| `redirect_withdrawn_restore_failed` | `warnings[]` (warning; human: `Warning: …` / `Error: …`) | scan `--mode hosted`: a pin whose patch is `withdrawn` / `not_found` could not be restored to its upstream registry entry (the restore refused it, writing the restored files failed, or the apply lock was held). The pin is kept and no `rolledBack` event is recorded for it; the detail names the remedy (`git checkout -- <lockfile>`, or re-run / `socket-patch rollback <purl>`). A write failure is one warning naming every pin it kept. Status and exit unchanged, unless the failed write could not put a file back: see `lockfile_write_failed`. |
| `patch_withdrawn` | `rolledBack` / `verified` (hosted event) | scan `--mode hosted`: the lockfile pinned a patch the server reports `withdrawn` or `not_found`; the pin was restored (dry run: would be) to its upstream registry entry. `reason` names the uuid and status. See "Withdrawn pins". |
| `vendor_prebuilt_stub_invalid` | `failed` | RubyGems: the server stub lacks required attributes or is otherwise invalid; no local stub fallback is permitted. |
| `bazelignore_not_updated` | run-level `warnings[]` | Go vendored and agent mode in a Bazel workspace (additive): the `.bazelignore` at the Bazel root, which keeps Bazel and gazelle out of the module copies under `.socket/vendor/golang` and `.socket/go-patches`, was not updated. It could not be read or written (a symbolic link or a directory in its place, a read-only directory, a read-only file). The detail names the line to add, or says that the lines of a copy that is gone can be deleted; the command's patch or undo stands and its exit code is unchanged. See docs/ecosystems.md "Bazel workspaces: `.bazelignore`". |
| `vendor_*` / `pypi_*` / `gemfile_*` / `lock_*` / `locked_version_mismatch` / `user_authored_*` / `native_extensions_unsupported` / `platform_gem_unsupported` | `failed`/`skipped` | vendor: per-ecosystem refusal + drift vocabulary; see the Vendor command contract section. New tags are additive (MINOR). |

`user_patch_conflict` is a `skipped` event and a scan/apply run warning for packages
Expand Down
3 changes: 3 additions & 0 deletions crates/socket-patch-cli/src/commands/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,9 @@ pub(crate) async fn run_locked(
}
}
}
// The copies under `.socket/go-patches` are as this run leaves
// them (a reconcile may have removed the last one).
run_warnings.extend(crate::commands::sync_bazelignore(&args.common, true).await);

// Human per-package report BEFORE the embedded VEX runs, so
// the VEX step's own notes follow the report instead of
Expand Down
58 changes: 58 additions & 0 deletions crates/socket-patch-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,64 @@ pub(crate) fn project_state_in_scope(common: &crate::args::GlobalArgs) -> bool {
!common.is_global()
}

/// In a Bazel workspace the root's `.bazelignore` names the directories of
/// the project's patched Go module copies, so that Bazel and gazelle read
/// no package there (`socket_patch_core::bazel::ignore`). A command that can
/// write or remove such a copy calls this once, after the last step that
/// can change a copy or take one back and before it gives up its apply
/// lock. Nothing is done in a dry run or a `--global` run, and a run whose
/// `--ecosystems` leaves `golang` out only takes away the pair of a copy
/// that is gone. So does the prune pass of a scan, which comes here after
/// its scan has (`adds` false) and can only have removed a copy: a file
/// it cannot write is left to the next command's warning.
///
/// A human run is told here that the file changed, or why it could not be;
/// the result is that warning again, for the command's envelope.
pub(crate) async fn sync_bazelignore(
common: &crate::args::GlobalArgs,
adds: bool,
) -> Vec<crate::json_envelope::RunWarning> {
use socket_patch_core::{bazel::ignore, crawlers::Ecosystem::Golang};
let mut warnings = Vec::new();
if common.dry_run || common.is_global() {
return warnings;
}
// The agent copies are those of `--cwd`, the vendored ones those of
// the manifest's project. A root both are under is named once.
let mut projects = vec![common.cwd.clone()];
if common.manifest_project_is_foreign() {
projects.push(common.project_root());
}
let (loud, mut told) = (!common.json && !common.silent, Vec::new());
for project in projects {
match ignore::sync(&project, adds && common.ecosystem_selected(Golang)).await {
Ok(Some(file)) if loud && !told.contains(&file) => {
let (verb, what) = match file.exists() {
true => (
"Updated",
"the lines that keep patched Go module copies under .socket out of \
Bazel's packages",
),
false => ("Removed", "no patched Go module copy is left under .socket"),
};
println!("{verb} {}: {what}", file.display());
told.push(file);
}
Err(detail) if adds => {
if loud {
eprintln!("Warning: {detail}");
}
warnings.push(crate::json_envelope::RunWarning::new(
ignore::NOT_UPDATED,
detail,
));
}
_ => {}
}
}
warnings
}

/// The vendor-ledger keys (`ledger`, the project's
/// [`VendorState::purl_keys`]) that own this run's installed copies. In
/// project scope that is the whole ledger. Under global scope the ledger
Expand Down
8 changes: 7 additions & 1 deletion crates/socket-patch-cli/src/commands/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,11 @@ pub async fn run(args: RemoveArgs) -> i32 {
// Artifacts the sweep examined (repair's `details.checked`), and the
// passes that failed (`cleanup_failed` run warnings under `--json`).
let mut gc_checked = 0usize;
let mut cleanup_warnings: Vec<(String, String)> = Vec::new();
// The rollback, the vendored revert and the orphan sweep above are
// done with the Go copies.
let ignored = crate::commands::sync_bazelignore(&args.common, true).await;
let mut cleanup_warnings: Vec<(String, String)> =
ignored.into_iter().map(|w| (w.code, w.detail)).collect();
if !args.preserve_state {
let sweep = references.sweep(&socket_dir, args.common.dry_run).await;
// repair's posture: a failed pass (or a pass that could not unlink
Expand Down Expand Up @@ -1860,6 +1864,8 @@ async fn remove_ledger_only(
let mut env = Envelope::new(Command::Remove);
env.dry_run = args.common.dry_run;
env.warnings.extend(commit_recovery);
env.warnings
.extend(crate::commands::sync_bazelignore(&args.common, true).await);
// The reverts ARE the removal: every event is recorded, so
// `summary.removed` counts the reverted entries (`summary.verified`
// the would-be removals on --dry-run).
Expand Down
4 changes: 4 additions & 0 deletions crates/socket-patch-cli/src/commands/repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ pub async fn run(args: RepairArgs) -> i32 {
// client's public-proxy advisory ahead of its own output.
let mut client: Option<ApiClient> = None;
let result = repair_inner(&args, &manifest_path, &mut client, vendor_references).await;
// A vendored Go copy may be back on disk, also when the repair failed.
let ignored = crate::commands::sync_bazelignore(&args.common, true).await;
let auth_fallback = client
.as_ref()
.and_then(crate::commands::vex_sources::api_auth_fallback_warning);
Expand All @@ -224,6 +226,7 @@ pub async fn run(args: RepairArgs) -> i32 {
Ok((mut env, counts)) => {
env.warnings.extend(commit_recovery);
env.warnings.extend(auth_fallback);
env.warnings.extend(ignored);
let had_failure = matches!(env.status, Status::PartialFailure | Status::Error);
if had_failure {
track_patch_repair_failed("One or more artifacts failed to download", &telemetry)
Expand All @@ -248,6 +251,7 @@ pub async fn run(args: RepairArgs) -> i32 {
let mut env =
error_envelope(Command::Repair, args.common.dry_run, &e.code, &e.message);
env.warnings.extend(commit_recovery);
env.warnings.extend(ignored);
crate::ui::print_json(&env.to_value());
} else {
eprintln!("Error: {}", e.message);
Expand Down
3 changes: 3 additions & 0 deletions crates/socket-patch-cli/src/commands/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,9 @@ async fn run_project(args: RollbackArgs, below: BelowNotes) -> i32 {
.iter()
.chain(hosted_leg.warnings.iter())
.for_each(|(code, detail)| run_warnings.push((code.clone(), detail.clone())));
// Every leg and the orphan sweep are done with the Go copies.
let ignored = crate::commands::sync_bazelignore(&args.common, true).await;
run_warnings.extend(ignored.into_iter().map(|w| (w.code, w.detail)));
// A restored package whose ownership could not be put back, or
// whose stale bytecode could not be removed (the engine reports
// it on `error` with `success: true`), is restored but worth a
Expand Down
7 changes: 7 additions & 0 deletions crates/socket-patch-cli/src/commands/scan/hosted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2175,6 +2175,12 @@ async fn run_redirect_selected_untracked(
.push(socket_patch_core::patch::redirect::RewriteWarning { code, detail });
}
}
// A run that took the lock may have removed a vendored Go copy (a
// takeover). One that took none may write no file (`socket.yml`).
let ignored = match &lock {
Some(_) => crate::commands::sync_bazelignore(common, true).await,
None => Vec::new(),
};
let mut warnings: Vec<RunWarning> = engine_warnings
.iter()
.map(|w| RunWarning::new(w.code.as_str(), w.detail.as_str()))
Expand Down Expand Up @@ -2219,6 +2225,7 @@ async fn run_redirect_selected_untracked(
record_hosted_events(&mut env, &confirmed, &unconfirmed, &skipped, common.dry_run);
env.set_extra("redirect", redirect_block(done.rewritten.clone()));
env.warnings.extend(warnings);
env.warnings.extend(ignored);
// Taking the lock may have finished an interrupted run's commit
// (stderr said so then).
env.warnings.extend(
Expand Down
2 changes: 2 additions & 0 deletions crates/socket-patch-cli/src/commands/scan/vendor_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ async fn vendor_under_lock(
env.mark_partial_failure();
}
note_classic_migration_risk(&mut env, &common.cwd, common);
env.warnings
.extend(crate::commands::sync_bazelignore(common, true).await);
Ok((has_errors, env))
}

Expand Down
11 changes: 11 additions & 0 deletions crates/socket-patch-cli/src/commands/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,8 @@ pub async fn run(args: VendorArgs) -> i32 {
}

note_classic_migration_risk(&mut env, &args.common.cwd, &args.common);
env.warnings
.extend(crate::commands::sync_bazelignore(&args.common, true).await);

// Everything below is output and telemetry, so release the lock before
// the telemetry round-trip.
Expand Down Expand Up @@ -2446,6 +2448,10 @@ async fn run_eject(
print_vendor_closing(common, &env, 0, &capture.wired_flavors, true, None);
}
note_classic_migration_risk(&mut env, &common.cwd, common);
// After the rollback, so that the file names no copy the eject made
// and took away again.
env.warnings
.extend(crate::commands::sync_bazelignore(common, true).await);
drop(guard);

// Embedded VEX: same contract as the manifest-driven arm — only on
Expand Down Expand Up @@ -5358,6 +5364,11 @@ pub(crate) async fn run_vendor_gc(
let warning = orphan_removal_failed(unit, e);
out.write_failures.push((warning.code, warning.detail));
}
// A pass that took a vendored copy away may have taken the last Go one,
// after the scan's own step was done with the file: its pair goes too.
if !dry_run && (ledger_dirty || out.orphan_dirs > 0) {
crate::commands::sync_bazelignore(common, false).await;
}
out
}

Expand Down
Loading
Loading