diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 084af85901..0e14b48433 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,8 +26,6 @@ env: - synchronize - reopened - labeled - branches: - - main push: branches: - main @@ -292,5 +290,13 @@ jobs: RUSTFLAGS: ${{ env.RUSTFLAGS }} POSTHOG_API_SECRET: ${{secrets.POSTHOG_API_SECRET}} APP_VERSION: ${{ needs.draft_release_pr.outputs.crate_release_name }} + - name: Copy Binary + run: cp ${{ matrix.binary_path }} ${{ matrix.binary_name }} + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.binary_name }} + path: ${{ matrix.binary_name }} + retention-days: 7 concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/crates/forge_ci/src/jobs/release_build_job.rs b/crates/forge_ci/src/jobs/release_build_job.rs index edd3a0662c..8197ec31ab 100644 --- a/crates/forge_ci/src/jobs/release_build_job.rs +++ b/crates/forge_ci/src/jobs/release_build_job.rs @@ -1,5 +1,6 @@ use derive_setters::Setters; use gh_workflow::*; +use serde_json::json; use crate::release_matrix::ReleaseMatrix; use crate::steps::setup_protoc; @@ -10,13 +11,16 @@ pub struct ReleaseBuilderJob { // Required to burn into the binary pub version: String, - // When provide the generated release will be uploaded + // When provided the generated release will be uploaded pub release_id: Option, + + // When true, upload built binaries as GitHub Actions artifacts + pub upload_artifact: Option, } impl ReleaseBuilderJob { pub fn new(version: impl AsRef) -> Self { - Self { version: version.as_ref().to_string(), release_id: None } + Self { version: version.as_ref().to_string(), release_id: None, upload_artifact: None } } pub fn into_job(self) -> Job { @@ -98,6 +102,25 @@ impl From for Job { ); } + if value.upload_artifact == Some(true) { + job = job + // Rename binary to target name for artifact upload + .add_step( + Step::new("Copy Binary") + .run("cp ${{ matrix.binary_path }} ${{ matrix.binary_name }}"), + ) + // Upload as GitHub Actions artifact + .add_step( + Step::new("Upload Artifact") + .uses("actions", "upload-artifact", "v4") + .with(Input::from(indexmap::indexmap! { + "name".to_string() => json!("${{ matrix.binary_name }}"), + "path".to_string() => json!("${{ matrix.binary_name }}"), + "retention-days".to_string() => json!(7), + })), + ); + } + job } } diff --git a/crates/forge_ci/src/workflows/ci.rs b/crates/forge_ci/src/workflows/ci.rs index 2b5d81174f..2af31bce71 100644 --- a/crates/forge_ci/src/workflows/ci.rs +++ b/crates/forge_ci/src/workflows/ci.rs @@ -39,11 +39,11 @@ pub fn generate_ci_workflow() { .add_type(PullRequestType::Opened) .add_type(PullRequestType::Synchronize) .add_type(PullRequestType::Reopened) - .add_type(PullRequestType::Labeled) - .add_branch("main"), + .add_type(PullRequestType::Labeled), ); let build_release_pr_job = ReleaseBuilderJob::new("${{ needs.draft_release_pr.outputs.crate_release_name }}") + .upload_artifact(true) .into_job() .add_needs("draft_release_pr") .cond(Expression::new(