Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Artifacts API update #12210

Merged
merged 22 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: ide cleanup
4e6 committed Jan 31, 2025
commit 8518c0e60e47c90efd76343e97fff6b5d55305d5
26 changes: 0 additions & 26 deletions build_tools/build/src/project.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ use crate::source::WithDestination;
use ide_ci::actions::artifacts;
use ide_ci::cache;
use ide_ci::cache::Cache;
use ide_ci::ok_ready_boxed;
use ide_ci::programs::git;
use octocrab::models::repos::Asset;

@@ -167,48 +166,23 @@ pub trait IsTarget: Clone + Debug + Sized + Send + Sync + 'static {
job: BuildTargetJob<Self>,
) -> BoxFuture<'static, Result<Self::Artifact>> {
let span = debug_span!("Building.", ?self, ?context, ?job).entered();
let upload_artifacts = job.should_upload_artifact;
let artifact_fut = self.build_internal(context, job.map(|job| job.input));
let this = self.clone();
async move {
let artifact = artifact_fut.await.context(format!("Failed to build {this:?}."))?;
// We upload only built artifacts. There would be no point in uploading something that
// we've just downloaded. That's why the uploading code is here.
if upload_artifacts {
this.perhaps_upload_artifact(&artifact).await?;
}
Ok(artifact)
}
.instrument(span.exit())
.boxed()
}

fn perhaps_upload_artifact(&self, artifact: &Self::Artifact) -> BoxFuture<'static, Result> {
let should_upload_artifact = ide_ci::actions::workflow::is_in_env();
trace!("Got target {:?}, should it be uploaded? {}", self, should_upload_artifact);
if should_upload_artifact {
self.upload_artifact(ready(Ok(artifact.clone())))
} else {
ok_ready_boxed(())
}
}

/// Produce an artifact from build inputs.
fn build_internal(
&self,
context: Context,
job: WithDestination<Self::BuildInput>,
) -> BoxFuture<'static, Result<Self::Artifact>>;

/// Upload artifact to the current GitHub Actions run.
fn upload_artifact(
&self,
output: impl Future<Output = Result<Self::Artifact>> + Send + 'static,
) -> BoxFuture<'static, Result> {
let name = self.artifact_name();
async move { artifacts::upload_compressed_directory(output.await?, name).await }.boxed()
}

fn download_artifact(
&self,
context: Context,
18 changes: 0 additions & 18 deletions build_tools/build/src/project/ide.rs
Original file line number Diff line number Diff line change
@@ -4,10 +4,6 @@ use crate::prelude::*;
use crate::project::gui::ide_desktop_from_context;
use crate::project::Context;

use ide_ci::actions::artifacts::upload_compressed_directory;
use ide_ci::actions::artifacts::upload_single_file;
use ide_ci::actions::workflow::is_in_env;



#[derive(Clone, Debug)]
@@ -47,20 +43,6 @@ impl Artifact {
}
}

pub async fn upload_as_ci_artifact(&self, prefix: impl AsRef<str>) -> Result {
if is_in_env() {
let prefix = prefix.as_ref();
upload_compressed_directory(&self.unpacked, format!("{prefix}-unpacked-{TARGET_OS}"))
.await?;
let packed_artifact_name = format!("{prefix}-{TARGET_OS}");
upload_single_file(&self.image, &packed_artifact_name).await?;
upload_single_file(&self.image_checksum, &packed_artifact_name).await?;
} else {
info!("Not in the CI environment, will not upload the artifacts.")
}
Ok(())
}

pub fn start_unpacked(
&self,
extra_ide_options: impl IntoIterator<Item: AsRef<OsStr>>,
2 changes: 0 additions & 2 deletions build_tools/build/src/source.rs
Original file line number Diff line number Diff line change
@@ -29,8 +29,6 @@ impl ExternalSource {
pub struct BuildSource<Target: IsTarget> {
/// Data needed to build the target.
pub input: Target::BuildInput,
/// Whether to upload the resulting artifact as CI artifact.
pub should_upload_artifact: bool,
}

/// Describes how to get a target.
17 changes: 3 additions & 14 deletions build_tools/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -134,11 +134,10 @@ impl Processor {
{
let span = info_span!("Resolving.", ?target, ?source).entered();
let destination = source.output_path.output_path;
let should_upload_artifact = source.build_args.upload_artifact;
let source = match source.source {
arg::SourceKind::Build => T::resolve(self, source.build_args.input)
.map_ok(move |input| {
Source::BuildLocally(BuildSource { input, should_upload_artifact })
Source::BuildLocally(BuildSource { input })
})
.boxed(),
arg::SourceKind::Local =>
@@ -209,13 +208,12 @@ impl Processor {
&self,
job: BuildJob<T>,
) -> BoxFuture<'static, Result<BuildTargetJob<T>>> {
let BuildJob { input: BuildDescription { input, upload_artifact }, output_path } = job;
let BuildJob { input: BuildDescription { input, .. }, output_path } = job;
let input = self.resolve_inputs::<T>(input);
async move {
Ok(WithDestination::new(
BuildSource {
input: input.await?,
should_upload_artifact: upload_artifact,
},
output_path.output_path,
))
@@ -551,16 +549,7 @@ impl Processor {
};

let target = Ide { target_os: self.triple.os, target_arch: self.triple.arch };
let artifact_name_prefix = input.artifact_name.clone();
let build_job = target.build(&self.context, input, output_path);
async move {
let artifacts = build_job.await?;
if is_in_env() {
artifacts.upload_as_ci_artifact(artifact_name_prefix).await?;
}
Ok(artifacts)
}
.boxed()
target.build(&self.context, input, output_path)
}

pub fn target<Target: Resolvable>(&self) -> Result<Target> {