Skip to content

Commit

Permalink
feat(ci): allow adding user-created publish jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Sep 11, 2023
1 parent 88013df commit 1221dc2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cargo-dist/src/backend/ci/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct GithubCiInfo {
pub tap: Option<String>,
/// publish jobs
pub publish_jobs: Vec<String>,
/// user-specified publish jobs
pub user_publish_jobs: Vec<String>,
/// whether to create the release or assume an existing one
pub create_release: bool,
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -119,6 +122,7 @@ impl GithubCiInfo {
fail_fast,
tap,
publish_jobs,
user_publish_jobs,
artifacts_matrix: GithubMatrix { include: tasks },
pr_run_mode,
global_task,
Expand Down
10 changes: 10 additions & 0 deletions cargo-dist/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ pub struct DistMetadata {
#[serde(rename = "publish-jobs")]
pub publish_jobs: Option<Vec<PublishStyle>>,

/// 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<Vec<String>>,

/// Whether to publish prereleases to package managers
///
/// (defaults to false)
Expand Down Expand Up @@ -289,6 +294,7 @@ impl DistMetadata {
default_features: _,
all_features: _,
publish_jobs: _,
user_publish_jobs: _,
publish_prereleases: _,
create_release: _,
pr_run_mode: _,
Expand Down Expand Up @@ -330,6 +336,7 @@ impl DistMetadata {
default_features,
all_features,
publish_jobs,
user_publish_jobs,
publish_prereleases,
create_release,
pr_run_mode: _,
Expand Down Expand Up @@ -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...
Expand Down
9 changes: 9 additions & 0 deletions cargo-dist/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions cargo-dist/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ pub struct DistGraph {
pub ci: CiInfo,
/// List of publish jobs to run
pub publish_jobs: Vec<PublishStyle>,
/// Extra user-specified publish jobs to run
pub user_publish_jobs: Vec<String>,
/// Whether to publish prerelease builds to package managers
pub publish_prereleases: bool,
/// A GitHub repo to publish the Homebrew formula to
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
Expand Down
11 changes: 11 additions & 0 deletions cargo-dist/templates/ci/github_ci.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 1221dc2

Please sign in to comment.