Skip to content

Commit 70c03e3

Browse files
authored
Updates for PREVIEW builds (#4108)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> See internal notes ## Description <!--- Describe your changes in detail --> ## Testing <!--- Please describe in detail how you tested your changes --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 44c8ac5 commit 70c03e3

File tree

5 files changed

+96
-41
lines changed

5 files changed

+96
-41
lines changed

tools/ci-build/publisher/src/subcommand/fix_manifests.rs

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
1212
use crate::fs::Fs;
1313
use crate::package::discover_manifests;
14-
use crate::SDK_REPO_NAME;
1514
use anyhow::{bail, Context, Result};
1615
use clap::Parser;
1716
use semver::Version;
18-
use smithy_rs_tool_common::{ci::running_in_ci, package::parse_version};
17+
use smithy_rs_tool_common::{
18+
ci::{is_in_example_dir, is_preview_build, running_in_ci},
19+
package::parse_version,
20+
};
1921
use std::collections::BTreeMap;
20-
use std::ffi::OsStr;
2122
use std::path::{Path, PathBuf};
2223
use toml::value::Table;
2324
use toml::Value;
@@ -64,6 +65,7 @@ pub async fn subcommand_fix_manifests(
6465
Ok(())
6566
}
6667

68+
#[derive(Debug)]
6769
struct Manifest {
6870
path: PathBuf,
6971
metadata: toml::Value,
@@ -82,6 +84,7 @@ impl Manifest {
8284
}
8385
}
8486

87+
#[derive(Debug)]
8588
struct Versions(BTreeMap<String, VersionWithMetadata>);
8689
#[derive(Copy, Clone)]
8790
enum FilterType {
@@ -110,6 +113,7 @@ impl Versions {
110113
}
111114
}
112115

116+
#[derive(Debug)]
113117
struct VersionWithMetadata {
114118
version: Version,
115119
publish: bool,
@@ -205,32 +209,19 @@ fn fix_dep_sets(versions: &VersionView, metadata: &mut toml::Value) -> Result<us
205209
Ok(changed)
206210
}
207211

208-
fn is_example_manifest(manifest_path: impl AsRef<Path>) -> bool {
209-
// Examine parent directories until either `examples/` or `aws-sdk-rust/` is found
210-
let mut path = manifest_path.as_ref();
211-
while let Some(parent) = path.parent() {
212-
path = parent;
213-
if path.file_name() == Some(OsStr::new("examples")) {
214-
return true;
215-
} else if path.file_name() == Some(OsStr::new(SDK_REPO_NAME)) {
216-
break;
217-
}
218-
}
219-
false
220-
}
221-
222212
fn conditionally_disallow_publish(
223213
manifest_path: &Path,
224214
metadata: &mut toml::Value,
225215
) -> Result<bool> {
226-
let is_github_actions = running_in_ci();
227-
let is_example = is_example_manifest(manifest_path);
216+
let is_gh_action_or_smithy_rs_docker = running_in_ci();
217+
let is_example = is_in_example_dir(manifest_path);
218+
let is_preview_build = is_preview_build();
228219

229220
// Safe-guard to prevent accidental publish to crates.io. Add some friction
230221
// to publishing from a local development machine by detecting that the tool
231222
// is not being run from CI, and disallow publish in that case. Also disallow
232-
// publishing of examples.
233-
if !is_github_actions || is_example {
223+
// publishing of examples and Trebuchet preview builds.
224+
if !is_gh_action_or_smithy_rs_docker || is_example || is_preview_build {
234225
if let Some(value) = set_publish_false(manifest_path, metadata, is_example) {
235226
return Ok(value);
236227
}
@@ -293,6 +284,13 @@ async fn fix_manifests(
293284
}
294285

295286
fn fix_manifest(versions: &Versions, manifest: &mut Manifest) -> Result<usize> {
287+
// In the case of a preview build we do not update the examples manifests
288+
// since most SDKs will not be generated so the particular crate referred to
289+
// by an example is unlikely to exist
290+
if is_in_example_dir(&manifest.path) && is_preview_build() {
291+
debug!(package = ?&manifest.path, "Skipping example package for preview build");
292+
return Ok(0);
293+
}
296294
let mut view = versions.published();
297295
if !manifest.publish()? {
298296
debug!(package = ?&manifest.path, "package has publishing disabled, allowing unpublished crates to be used");
@@ -428,21 +426,4 @@ mod tests {
428426
actual_build_deps.to_string()
429427
);
430428
}
431-
432-
#[test]
433-
fn test_is_example_manifest() {
434-
assert!(!is_example_manifest("aws-sdk-rust/sdk/s3/Cargo.toml"));
435-
assert!(!is_example_manifest(
436-
"aws-sdk-rust/sdk/aws-config/Cargo.toml"
437-
));
438-
assert!(!is_example_manifest(
439-
"/path/to/aws-sdk-rust/sdk/aws-config/Cargo.toml"
440-
));
441-
assert!(!is_example_manifest("sdk/aws-config/Cargo.toml"));
442-
assert!(is_example_manifest("examples/foo/Cargo.toml"));
443-
assert!(is_example_manifest("examples/foo/bar/Cargo.toml"));
444-
assert!(is_example_manifest(
445-
"aws-sdk-rust/examples/foo/bar/Cargo.toml"
446-
));
447-
}
448429
}

tools/ci-build/publisher/src/subcommand/generate_version_manifest.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use anyhow::{bail, Context, Result};
99
use clap::Parser;
1010
use semver::Version;
1111
use serde::Deserialize;
12+
use smithy_rs_tool_common::ci::is_preview_build;
1213
use smithy_rs_tool_common::git::{find_git_repository_root, Git, GitCLI};
1314
use smithy_rs_tool_common::package::PackageCategory;
1415
use smithy_rs_tool_common::shell;
@@ -113,8 +114,10 @@ pub async fn subcommand_generate_version_manifest(
113114
crates,
114115
release: None,
115116
};
117+
116118
versions_manifest.release =
117119
generate_release_metadata(&versions_manifest, previous_release_versions)?;
120+
118121
let manifest_file_name = output_location.join("versions.toml");
119122
info!("Writing {:?}...", manifest_file_name);
120123
versions_manifest.write_to_file(&manifest_file_name)?;
@@ -125,14 +128,21 @@ fn generate_release_metadata(
125128
versions_manifest: &VersionsManifest,
126129
maybe_previous_release_versions: &Option<PathBuf>,
127130
) -> Result<Option<Release>> {
128-
if let Some(previous_release_versions) = maybe_previous_release_versions {
131+
// For release builds we generate a real release section
132+
if let (Some(previous_release_versions), false) =
133+
(maybe_previous_release_versions, is_preview_build())
134+
{
129135
let old_versions = VersionsManifest::from_file(previous_release_versions)?;
130136
Ok(Some(Release {
131137
tag: None,
132138
crates: find_released_versions(&old_versions, versions_manifest)?,
133139
}))
140+
// For preview builds we insert an empty section
134141
} else {
135-
Ok(None)
142+
Ok(Some(Release {
143+
tag: None,
144+
crates: BTreeMap::new(),
145+
}))
136146
}
137147
}
138148

tools/ci-build/publisher/src/subcommand/tag_versions_manifest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct TagVersionsManifestArgs {
2121
pub fn subcommand_tag_versions_manifest(
2222
TagVersionsManifestArgs { manifest_path, tag }: &TagVersionsManifestArgs,
2323
) -> Result<()> {
24+
println!("Tagging manifest at: {manifest_path:#?}");
2425
let mut manifest = VersionsManifest::from_file(manifest_path)?;
2526
if let Some(release) = manifest.release.as_mut() {
2627
release.tag = Some(tag.to_string());

tools/ci-build/sdk-versioner/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use anyhow::{bail, Context, Result};
77
use clap::Parser;
8+
use smithy_rs_tool_common::ci::{is_in_example_dir, is_preview_build};
89
use smithy_rs_tool_common::package::{PackageCategory, SDK_PREFIX};
910
use smithy_rs_tool_common::versions_manifest::VersionsManifest;
1011
use std::ffi::OsStr;
@@ -114,6 +115,13 @@ fn main() -> Result<()> {
114115
},
115116
};
116117

118+
// In the case of a preview build we avoid updating the examples directories since
119+
// we only generate the single preview SDK, so most SDKs referred to in the examples
120+
// will be missing
121+
if is_preview_build() && is_in_example_dir(&args.crate_paths()[0]) {
122+
return Ok(());
123+
}
124+
117125
let start_time = Instant::now();
118126
let mut manifest_paths = Vec::new();
119127
for crate_path in args.crate_paths() {
@@ -236,7 +244,7 @@ fn updated_dependency_value(
236244
let dependency_path = sdk_path
237245
.join(crate_path_name(dependency_name))
238246
.canonicalize()
239-
.context("failed to canonicalize dependency path")?;
247+
.context(format!("failed to canonicalize sdk_path: {sdk_path:#?} with dependency_name: {dependency_name}"))?;
240248
if let Some(relative_path) = pathdiff::diff_paths(&dependency_path, &crate_path) {
241249
value["path"] = toml_edit::value(
242250
relative_path

tools/ci-build/smithy-rs-tool-common/src/ci.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,64 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5+
use std::ffi::OsStr;
6+
use std::path::Path;
57

68
/// Returns `true` if this code is being run in CI
79
pub fn running_in_ci() -> bool {
810
std::env::var("GITHUB_ACTIONS").unwrap_or_default() == "true"
911
|| std::env::var("SMITHY_RS_DOCKER_BUILD_IMAGE").unwrap_or_default() == "1"
1012
}
13+
14+
/// The `BUILD_TYPE` env var is only set for Codebuild jobs, will always
15+
/// return `false` in other CI environments
16+
pub fn is_preview_build() -> bool {
17+
let build_type = std::env::var("BUILD_TYPE");
18+
19+
if let Ok(build_type) = build_type {
20+
if build_type.eq_ignore_ascii_case("PREVIEW") {
21+
return true;
22+
}
23+
}
24+
25+
false
26+
}
27+
28+
pub fn is_in_example_dir(manifest_path: impl AsRef<Path>) -> bool {
29+
let mut path = manifest_path.as_ref();
30+
// Check if current dir is examples
31+
if path.ends_with("examples") {
32+
return true;
33+
}
34+
// Examine parent directories until either `examples/` or `aws-sdk-rust/` is found
35+
while let Some(parent) = path.parent() {
36+
path = parent;
37+
if path.file_name() == Some(OsStr::new("examples")) {
38+
return true;
39+
} else if path.file_name() == Some(OsStr::new("aws-sdk-rust")) {
40+
break;
41+
}
42+
}
43+
false
44+
}
45+
46+
#[cfg(test)]
47+
mod tests {
48+
use super::*;
49+
50+
#[test]
51+
fn test_is_in_example_dir() {
52+
assert!(!is_in_example_dir("aws-sdk-rust/sdk/s3/Cargo.toml"));
53+
assert!(!is_in_example_dir("aws-sdk-rust/sdk/aws-config/Cargo.toml"));
54+
assert!(!is_in_example_dir(
55+
"/path/to/aws-sdk-rust/sdk/aws-config/Cargo.toml"
56+
));
57+
assert!(!is_in_example_dir("sdk/aws-config/Cargo.toml"));
58+
assert!(is_in_example_dir("examples/foo/Cargo.toml"));
59+
assert!(is_in_example_dir("examples/foo/bar/Cargo.toml"));
60+
assert!(is_in_example_dir(
61+
"aws-sdk-rust/examples/foo/bar/Cargo.toml"
62+
));
63+
assert!(is_in_example_dir("aws-sdk-rust/examples/"));
64+
}
65+
}

0 commit comments

Comments
 (0)