Skip to content

Commit 52836fa

Browse files
committed
feat: optionally apply github-build-setup steps to additional jobs.
For some use cases, such as using private Git crate dependencies in a project's Cargo.toml manifest, Github Actions requires a certain amount of ceremony to alias the private repo's Git URL to to something that can be cloned using an access token. For the `build-local-artifacts` job, this can be accomplished by adding the authentication step in the `github-build-setup` YML file. There are additional jobs that necessitate these credentials be set, mainly the `plan`, `build-global-artifacts`, and `host`. This appears to be due to the fact they invoke `cargo metadata` (which attempts to pull dependencies). Support these use-cases by introducing a `github-build-setup-jobs` collection which allows users to opt-in to including the `github-build-setup` steps in various jobs. Fixes #2065
1 parent 93fbc5c commit 52836fa

File tree

10 files changed

+5183
-4
lines changed

10 files changed

+5183
-4
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Unreleased
22

3+
## `github-build-setup` Job Customization
4+
5+
It's now possible to specify to which jobs `github-build-setup` steps are added.
6+
7+
```toml
8+
github-build-setup = "build-steps.yml"
9+
github-build-setup-jobs = ["plan", "build-local-artifacts", "build-global-artifacts", "host"]
10+
```
11+
12+
If not configured, this defaults to `build-local-artifacts`.
13+
314
# Version 0.30.0 (2025-09-07)
415

516
This release contains several improvements to ZIP archives, the installers and additional build workflow customization options.

book/src/reference/config.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ We're currently in the middle of [a major config migration](https://github.com/a
9595
* [`github-custom-job-permissions`](#github-custom-job-permissions)
9696
* [`github-custom-runners`](#github-custom-runners)
9797
* [`github-build-setup`](#github-build-setup)
98+
* [`github-build-setup-jobs`](#github-build-setup-jobs)
9899
* [`github-action-commits`](#github-action-commits)
99100
* [custom ci jobs](#custom-ci-jobs)
100101
* [`plan-jobs`](#plan-jobs)
@@ -1382,8 +1383,28 @@ These settings are specific to [your dist GitHub CI][github-ci].
13821383
13831384
This configuration value should be a path relative to the repository your `.github/workflows` directory.
13841385
The file located at that path should contain a yaml array of [steps][github-workflow-step] which will be
1385-
performed before we call `dist build`.
1386+
performed before we call `dist build` in the `build-local-artifacts` job. These
1387+
steps can be added to additional jobs by defining
1388+
[`github-build-setup-jobs`](#github-build-setup-jobs).
13861389
1390+
#### `github-build-setup-jobs`
1391+
1392+
> <span style="float:right">since 1.0.0<br>[global-only][]</span>
1393+
> 🔧 this is an experimental feature! \
1394+
> [📖 read the ci customization guide!][github-ci] \
1395+
> default = `<none>`
1396+
>
1397+
> *in your dist-workspace.toml or dist.toml:*
1398+
> ```toml
1399+
> [dist]
1400+
> # Defaults to "build-local-artifacts"
1401+
> github-build-setup-jobs = ["plan", "build-local-artifacts"]
1402+
> ```
1403+
1404+
This configuration value should accompany
1405+
[`github-build-setup`](#github-build-setup). When not specified, it defaults to
1406+
`["build-local-artifacts"]`. Otherwise, the listed jobs will have the steps
1407+
defined in `github-build-setup` added.
13871408
13881409
#### `github-custom-job-permissions`
13891410

cargo-dist/src/backend/ci/github.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ pub struct GithubCiInfo {
100100
pub root_permissions: Option<GithubPermissionMap>,
101101
/// Extra build steps
102102
pub github_build_setup: Vec<GithubJobStep>,
103+
/// The jobs to which the [`GithubCiInfo::github_build_setup`] steps should be prepended
104+
pub github_build_setup_jobs: Vec<String>,
103105
/// Info about making a GitHub Release (if we're making one)
104106
#[serde(flatten)]
105107
pub github_release: Option<GithubReleaseInfo>,
@@ -372,6 +374,7 @@ impl GithubCiInfo {
372374
})
373375
.transpose()?
374376
.unwrap_or_default();
377+
let github_build_setup_jobs = ci_config.build_setup_jobs.clone();
375378

376379
let default_action_versions = [
377380
("actions/checkout", "v4"),
@@ -420,6 +423,7 @@ impl GithubCiInfo {
420423
hosting_providers,
421424
root_permissions,
422425
github_build_setup,
426+
github_build_setup_jobs,
423427
github_release,
424428
actions,
425429
need_cargo_auditable,

cargo-dist/src/config/v0.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,14 @@ pub struct DistMetadata {
539539
#[serde(default, with = "opt_string_or_vec")]
540540
pub install_libraries: Option<Vec<LibraryStyle>>,
541541

542-
/// Any additional steps that need to be performed before building local artifacts
542+
/// Any additional steps that need to be performed before executing certain job steps
543543
#[serde(default)]
544544
pub github_build_setup: Option<String>,
545545

546+
/// The jobs to which the [`DistMetadata::github_build_setup`] steps should be prepended
547+
#[serde(default)]
548+
pub github_build_setup_jobs: Option<Vec<String>>,
549+
546550
/// Configuration specific to Mac .pkg installers
547551
#[serde(skip_serializing_if = "Option::is_none")]
548552
#[serde(default)]
@@ -645,6 +649,7 @@ impl DistMetadata {
645649
package_libraries: _,
646650
install_libraries: _,
647651
github_build_setup: _,
652+
github_build_setup_jobs: _,
648653
mac_pkg_config: _,
649654
min_glibc_version: _,
650655
binaries: _,
@@ -752,6 +757,7 @@ impl DistMetadata {
752757
package_libraries,
753758
install_libraries,
754759
github_build_setup,
760+
github_build_setup_jobs,
755761
mac_pkg_config,
756762
min_glibc_version,
757763
binaries,
@@ -880,6 +886,9 @@ impl DistMetadata {
880886
if github_build_setup.is_some() {
881887
warn!("package.metadata.dist.github-build-setup is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
882888
}
889+
if github_build_setup_jobs.is_some() {
890+
warn!("package.metadata.dist.github-build-setup-jobs is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
891+
}
883892

884893
// Merge non-global settings
885894
if installers.is_none() {

cargo-dist/src/config/v0_to_v1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl DistMetadata {
8888
package_libraries,
8989
install_libraries,
9090
github_build_setup,
91+
github_build_setup_jobs,
9192
min_glibc_version,
9293
binaries,
9394
cargo_auditable,
@@ -165,13 +166,15 @@ impl DistMetadata {
165166
if github_custom_runners.is_some()
166167
|| github_custom_job_permissions.is_some()
167168
|| github_build_setup.is_some()
169+
|| github_build_setup_jobs.is_some()
168170
|| github_action_commits.is_some()
169171
{
170172
Some(GithubCiLayer {
171173
common: CommonCiLayer::default(),
172174
runners: github_custom_runners,
173175
permissions: github_custom_job_permissions,
174176
build_setup: github_build_setup,
177+
build_setup_jobs: github_build_setup_jobs,
175178
action_commits: github_action_commits,
176179
})
177180
} else {

cargo-dist/src/config/v1/ci/github.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ pub struct GithubCiLayer {
2525
#[serde(skip_serializing_if = "Option::is_none")]
2626
pub permissions: Option<SortedMap<String, GithubPermissionMap>>,
2727

28-
/// Custom permissions for jobs
28+
/// Custom steps for jobs
2929
#[serde(skip_serializing_if = "Option::is_none")]
3030
pub build_setup: Option<String>,
3131

32+
/// What jobs to which the [`GithubCiLayer::build_setup`] steps should be prepended
33+
#[serde(skip_serializing_if = "Option::is_none")]
34+
pub build_setup_jobs: Option<Vec<String>>,
35+
3236
/// Use these commits for actions
3337
#[serde(skip_serializing_if = "Option::is_none")]
3438
pub action_commits: Option<SortedMap<String, String>>,
@@ -46,9 +50,12 @@ pub struct GithubCiConfig {
4650
/// Custom permissions for jobs
4751
pub permissions: SortedMap<String, GithubPermissionMap>,
4852

49-
/// Custom permissions for jobs
53+
/// Custom steps for jobs
5054
pub build_setup: Option<String>,
5155

56+
/// What jobs to which the [`GithubCiConfig::build_setup`] steps should be prepended
57+
pub build_setup_jobs: Vec<String>,
58+
5259
/// Use these commits for github actions
5360
pub action_commits: SortedMap<String, String>,
5461
}
@@ -62,6 +69,7 @@ impl GithubCiConfig {
6269
permissions: Default::default(),
6370
action_commits: Default::default(),
6471
build_setup: None,
72+
build_setup_jobs: vec!["build-local-artifacts".to_string()],
6573
}
6674
}
6775
}
@@ -75,6 +83,7 @@ impl ApplyLayer for GithubCiConfig {
7583
runners,
7684
permissions,
7785
build_setup,
86+
build_setup_jobs,
7887
action_commits,
7988
}: Self::Layer,
8089
) {
@@ -143,6 +152,7 @@ impl ApplyLayer for GithubCiConfig {
143152
}));
144153
self.permissions.apply_val(permissions);
145154
self.build_setup.apply_opt(build_setup);
155+
self.build_setup_jobs.apply_val(build_setup_jobs);
146156
self.action_commits.apply_val(action_commits);
147157
}
148158
}
@@ -155,13 +165,15 @@ impl ApplyLayer for GithubCiLayer {
155165
runners,
156166
permissions,
157167
build_setup,
168+
build_setup_jobs,
158169
action_commits,
159170
}: Self::Layer,
160171
) {
161172
self.common.apply_layer(common);
162173
self.runners.apply_opt(runners);
163174
self.permissions.apply_opt(permissions);
164175
self.build_setup.apply_opt(build_setup);
176+
self.build_setup_jobs.apply_opt(build_setup_jobs);
165177
self.action_commits.apply_opt(action_commits);
166178
}
167179
}

cargo-dist/src/init/v0.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ fn get_new_dist_metadata(
252252
package_libraries: None,
253253
install_libraries: None,
254254
github_build_setup: None,
255+
github_build_setup_jobs: None,
255256
mac_pkg_config: None,
256257
min_glibc_version: None,
257258
binaries: None,
@@ -765,6 +766,7 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) {
765766
bin_aliases: _,
766767
system_dependencies: _,
767768
github_build_setup: _,
769+
github_build_setup_jobs: _,
768770
binaries: _,
769771
} = &meta;
770772

0 commit comments

Comments
 (0)