Skip to content

Commit

Permalink
Merge pull request #1629 from axodotdev/omnibor-local
Browse files Browse the repository at this point in the history
fix: adjust what things we build omnibor IDs for
  • Loading branch information
mistydemeo authored Dec 12, 2024
2 parents 5822f73 + 335eba2 commit 948219a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 92 deletions.
99 changes: 39 additions & 60 deletions cargo-dist/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,11 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
if checksum != ChecksumStyle::False {
self.add_artifact_checksum(variant_idx, zip_artifact_idx, checksum);
}

if self.inner.config.builds.omnibor {
let omnibor = self.create_omnibor_artifact(zip_artifact_idx, false);
self.add_local_artifact(variant_idx, omnibor);
}
}
}

Expand Down Expand Up @@ -1546,66 +1551,30 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
);
}

fn add_omnibor_artifact_id_file(&mut self, to_release: ReleaseIdx) {
if !self.global_artifacts_enabled() || !self.inner.config.builds.omnibor {
return;
}
fn create_omnibor_artifact(&mut self, artifact_idx: ArtifactIdx, is_global: bool) -> Artifact {
let artifact = self.artifact(artifact_idx);
let id = artifact.id.clone();
let src_path = artifact.file_path.clone();

let release = self.release(to_release).clone();
let global_artifacts = release.global_artifacts;
let local_artifacts: Vec<_> = release
.variants
.into_iter()
.flat_map(|vidx| self.variant(vidx).local_artifacts.clone())
.collect();
let artifacts: Vec<_> = global_artifacts
.into_iter()
.chain(local_artifacts)
.map(|a| self.artifact(a).clone())
.collect();
let extension = src_path
.extension()
.map_or("omnibor".to_string(), |e| format!("{e}.omnibor"));
let dest_path = src_path.with_extension(extension);

for artifact in &artifacts {
let id = artifact.id.clone();
let src_path = artifact.file_path.clone();
match &artifact.kind {
// Things we need to generate OmniBOR Artifact IDs for.
ArtifactKind::ExecutableZip(_)
| ArtifactKind::Installer(_)
| ArtifactKind::SourceTarball(_)
| ArtifactKind::ExtraArtifact(_)
| ArtifactKind::Updater(_) => {
let extension = src_path
.extension()
.map_or("omnibor".to_string(), |e| format!("{e}.omnibor"));
let dest_path = src_path.with_extension(extension);

let new_id = format!("{}.omnibor", id);

self.add_global_artifact(
to_release,
Artifact {
id: ArtifactId::new(new_id),
target_triples: Default::default(),
archive: None,
file_path: dest_path.clone(),
required_binaries: Default::default(),
kind: ArtifactKind::OmniborArtifactId(OmniborArtifactIdImpl {
src_path,
dest_path,
}),
checksum: None,
is_global: true,
},
);
}
let new_id = format!("{}.omnibor", id);

// Things we don't need to generate OmniBOR Artifact IDs for.
ArtifactKind::Symbols(_)
| ArtifactKind::Checksum(_)
| ArtifactKind::UnifiedChecksum(_)
| ArtifactKind::SBOM(_)
| ArtifactKind::OmniborArtifactId(_) => {}
}
Artifact {
id: ArtifactId::new(new_id),
target_triples: Default::default(),
archive: None,
file_path: dest_path.clone(),
required_binaries: Default::default(),
kind: ArtifactKind::OmniborArtifactId(OmniborArtifactIdImpl {
src_path,
dest_path,
}),
checksum: None,
is_global,
}
}

Expand Down Expand Up @@ -1741,6 +1710,11 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
let checksum_idx = self.add_global_artifact(to_release, checksum);
self.artifact_mut(artifact_idx).checksum = Some(checksum_idx);
}

if self.inner.config.builds.omnibor {
let omnibor = self.create_omnibor_artifact(artifact_idx, true);
self.add_global_artifact(to_release, omnibor);
}
}

fn add_artifact_checksum(
Expand Down Expand Up @@ -2493,6 +2467,10 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
if checksum != ChecksumStyle::False {
self.add_artifact_checksum(variant_idx, installer_idx, checksum);
}
if self.inner.config.builds.omnibor {
let omnibor = self.create_omnibor_artifact(installer_idx, false);
self.add_local_artifact(variant_idx, omnibor);
}
}

Ok(())
Expand Down Expand Up @@ -2604,6 +2582,10 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
if checksum != ChecksumStyle::False {
self.add_artifact_checksum(variant_idx, installer_idx, checksum);
}
if self.inner.config.builds.omnibor {
let omnibor = self.create_omnibor_artifact(installer_idx, false);
self.add_local_artifact(variant_idx, omnibor);
}
}

Ok(())
Expand Down Expand Up @@ -2928,9 +2910,6 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
}
}

// Add the OmniBOR Artifact ID.
self.add_omnibor_artifact_id_file(release);

// Add SBOM file, if it exists.
self.add_cyclonedx_sbom_file(info.package_idx, release);

Expand Down
7 changes: 7 additions & 0 deletions cargo-dist/templates/ci/github/release.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ jobs:
- name: Install cargo-auditable
run: ${{ matrix.install_cargo_auditable.run }}
{{%- endif %}}
{{%- if need_omnibor %}}
- name: Install omnibor
# we specify bash to get pipefail; it guards against the `curl` command
# failing. otherwise `sh` won't catch that `curl` return non-0
run: {{{ global_task.install_omnibor.run }}}
shell: bash
{{%- endif %}}
- name: Install dependencies
run: |
${{ matrix.packages_install }}
Expand Down
49 changes: 17 additions & 32 deletions cargo-dist/tests/snapshots/axolotlsay_basic.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 948219a

Please sign in to comment.