diff --git a/src/validate.rs b/src/validate.rs index f9765bf2b..daecfc2c6 100644 --- a/src/validate.rs +++ b/src/validate.rs @@ -1212,6 +1212,14 @@ fn validate_trusted_publishing(data: &Data, errors: &mut Vec) { )); } + // Validate that the environment referenced in crates-io exists + if !repo.environments.contains_key(&publishing.environment) { + return Err(anyhow::anyhow!( + "Repository `{repo_name}` configures trusted publishing with environment `{}` which is not defined in the repository's environments. Please add an environment with this name in the repository configuration.", + publishing.environment + )); + } + for krate in &publishing.crates { if let Some(prev_repo) = crates.insert(krate.clone(), repo_name.clone()) { return Err(anyhow::anyhow!( diff --git a/tests/static-api/_expected/v1/repos.json b/tests/static-api/_expected/v1/repos.json index fdf43c4dd..ae7d5d782 100644 --- a/tests/static-api/_expected/v1/repos.json +++ b/tests/static-api/_expected/v1/repos.json @@ -103,7 +103,14 @@ ] } ], - "environments": {}, + "environments": { + "deploy": { + "branches": [ + "main" + ], + "tags": [] + } + }, "archived": false, "private": false, "auto_merge_enabled": true diff --git a/tests/static-api/_expected/v1/repos/some_repo.json b/tests/static-api/_expected/v1/repos/some_repo.json index 6e94c23b9..504838674 100644 --- a/tests/static-api/_expected/v1/repos/some_repo.json +++ b/tests/static-api/_expected/v1/repos/some_repo.json @@ -71,7 +71,14 @@ ] } ], - "environments": {}, + "environments": { + "deploy": { + "branches": [ + "main" + ], + "tags": [] + } + }, "archived": false, "private": false, "auto_merge_enabled": true diff --git a/tests/static-api/repos/test-org/some_repo.toml b/tests/static-api/repos/test-org/some_repo.toml index 4ba54187f..0bd6d6673 100644 --- a/tests/static-api/repos/test-org/some_repo.toml +++ b/tests/static-api/repos/test-org/some_repo.toml @@ -11,6 +11,9 @@ pattern = "master" ci-checks = ["CI"] allowed-merge-teams = ["foo"] +[environments.deploy] +branches = ["main"] + [[crates-io]] crates = ["my-crate", "my-crate-2"] publish-workflow = "ci.yml"