diff --git a/cargo-dist/src/backend/ci/github.rs b/cargo-dist/src/backend/ci/github.rs index 5a8652e0e..faffa033b 100644 --- a/cargo-dist/src/backend/ci/github.rs +++ b/cargo-dist/src/backend/ci/github.rs @@ -37,6 +37,8 @@ pub struct GithubCiInfo { pub tap: Option, /// publish jobs pub publish_jobs: Vec, + /// user-specified publish jobs + pub user_publish_jobs: Vec, /// whether to create the release or assume an existing one pub create_release: bool, } @@ -90,6 +92,7 @@ impl GithubCiInfo { let tap = dist.tap.clone(); let publish_jobs = dist.publish_jobs.iter().map(|j| j.to_string()).collect(); + let user_publish_jobs = dist.user_publish_jobs.clone(); // Figure out what Local Artifact tasks we need let local_runs = if dist.merge_tasks { @@ -119,6 +122,7 @@ impl GithubCiInfo { fail_fast, tap, publish_jobs, + user_publish_jobs, artifacts_matrix: GithubMatrix { include: tasks }, pr_run_mode, global_task, diff --git a/cargo-dist/src/config.rs b/cargo-dist/src/config.rs index d14c827c1..cfe52b5f5 100644 --- a/cargo-dist/src/config.rs +++ b/cargo-dist/src/config.rs @@ -243,6 +243,11 @@ pub struct DistMetadata { #[serde(rename = "publish-jobs")] pub publish_jobs: Option>, + /// User-supplied extra publish jobs to run in CI + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(rename = "user-publish-jobs")] + pub user_publish_jobs: Option>, + /// Whether to publish prereleases to package managers /// /// (defaults to false) @@ -289,6 +294,7 @@ impl DistMetadata { default_features: _, all_features: _, publish_jobs: _, + user_publish_jobs: _, publish_prereleases: _, create_release: _, pr_run_mode: _, @@ -330,6 +336,7 @@ impl DistMetadata { default_features, all_features, publish_jobs, + user_publish_jobs, publish_prereleases, create_release, pr_run_mode: _, @@ -410,6 +417,9 @@ impl DistMetadata { if publish_jobs.is_none() { *publish_jobs = workspace_config.publish_jobs.clone(); } + if user_publish_jobs.is_none() { + *user_publish_jobs = workspace_config.user_publish_jobs.clone(); + } // This was historically implemented as extend, but I'm not convinced the // inconsistency is worth the inconvenience... diff --git a/cargo-dist/src/init.rs b/cargo-dist/src/init.rs index d8b41ed28..d0b7e9f91 100644 --- a/cargo-dist/src/init.rs +++ b/cargo-dist/src/init.rs @@ -221,6 +221,7 @@ fn get_new_dist_metadata( default_features: None, all_features: None, publish_jobs: None, + user_publish_jobs: None, publish_prereleases: None, create_release: None, pr_run_mode: None, @@ -680,6 +681,7 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) { all_features, default_features, publish_jobs, + user_publish_jobs, publish_prereleases, create_release, pr_run_mode, @@ -840,6 +842,13 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) { publish_jobs.as_ref(), ); + apply_string_list( + table, + "user-publish-jobs", + "# User-defined publish jobs to run in CI\n", + user_publish_jobs.as_ref(), + ); + apply_optional_value( table, "publish-prereleases", diff --git a/cargo-dist/src/tasks.rs b/cargo-dist/src/tasks.rs index a7ec40519..3addb46be 100644 --- a/cargo-dist/src/tasks.rs +++ b/cargo-dist/src/tasks.rs @@ -199,6 +199,8 @@ pub struct DistGraph { pub ci: CiInfo, /// List of publish jobs to run pub publish_jobs: Vec, + /// Extra user-specified publish jobs to run + pub user_publish_jobs: Vec, /// Whether to publish prerelease builds to package managers pub publish_prereleases: bool, /// A GitHub repo to publish the Homebrew formula to @@ -648,6 +650,8 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> { install_path: _, // Only the final value merged into a package_config matters publish_jobs: _, + // Only the final value merged into a package_config matters + user_publish_jobs: _, publish_prereleases, features, default_features: no_default_features, @@ -702,6 +706,10 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> { let templates = Templates::new()?; let publish_jobs = workspace_metadata.publish_jobs.clone().unwrap_or(vec![]); + let user_publish_jobs = workspace_metadata + .user_publish_jobs + .clone() + .unwrap_or(vec![]); let publish_prereleases = publish_prereleases.unwrap_or(false); let allow_dirty = if allow_all_dirty { @@ -740,6 +748,7 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> { pr_run_mode: workspace_metadata.pr_run_mode.unwrap_or_default(), tap: workspace_metadata.tap.clone(), publish_jobs, + user_publish_jobs, publish_prereleases, allow_dirty, }, diff --git a/cargo-dist/templates/ci/github_ci.yml.j2 b/cargo-dist/templates/ci/github_ci.yml.j2 index fc73ccb6f..458f71bf0 100644 --- a/cargo-dist/templates/ci/github_ci.yml.j2 +++ b/cargo-dist/templates/ci/github_ci.yml.j2 @@ -229,6 +229,17 @@ jobs: {{%- endif %}} +{{%- for job in user_publish_jobs %}} + + user-publish-job-{{{ job|safe }}}: + needs: [plan, should-publish] + if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }} + uses: ./.github/workflows/publish-{{{ job|safe }}}.yml + with: + plan: ${{ needs.plan.outputs.val }} + secrets: inherit +{{%- endfor %}} + # Create a Github Release with all the results once everything is done, publish-release: needs: [plan, should-publish]