-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90d9414
commit dd1e806
Showing
8 changed files
with
254 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 81 additions & 73 deletions
154
crates/infra/cli/src/commands/publish/changesets/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,104 @@ | ||
//! This repository versions and releases all its artifacts together, generating the same changelog. | ||
//! Unfortunately, changesets does not support combining changelogs from multiple packages into one. | ||
//! | ||
//! So, we let changesets bump the version of the single NPM package we ship, and generate its changelog. | ||
//! Then our build process copies the new version and the single changelog to other packages and crates. | ||
//! | ||
//! Additionally, changesets can only bump versions of packages in the root workspace. | ||
//! However, NAPI platform-specific packages cannot be added to the workspace, because other platforms will fail "npm install". | ||
//! So we have to bump the versions over ourselves anyways. | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use infra_utils::cargo::CargoWorkspace; | ||
use infra_utils::commands::Command; | ||
use infra_utils::paths::{FileWalker, PathExtensions}; | ||
|
||
use crate::toolchains::napi::{NapiConfig, NapiResolver}; | ||
|
||
/// This repository versions and releases all its artifacts together, generating the same changelog. | ||
/// Unfortunately, changesets does not support combining changelogs from multiple packages into one. | ||
/// | ||
/// So, we let changesets bump the version of the single NPM package we ship, and generate its changelog. | ||
/// Then our build process copies the new version and the single changelog to other packages and crates. | ||
/// | ||
/// Additionally, changesets can only bump versions of packages in the root workspace. | ||
/// However, NAPI platform-specific packages cannot be added to the workspace, because other platforms will fail "npm install". | ||
/// So we have to bump the versions over ourselves anyways. | ||
pub fn publish_changesets() -> Result<()> { | ||
let resolver = NapiResolver::Solidity; | ||
let package_dir = resolver.main_package_dir(); | ||
|
||
let package_version = NapiConfig::local_version(&package_dir)?; | ||
println!("Package version: {package_version}"); | ||
|
||
let workspace_version = CargoWorkspace::local_version()?; | ||
println!("Workspace version: {workspace_version}"); | ||
|
||
assert_eq!( | ||
package_version, workspace_version, | ||
"Package version does not match workspace version." | ||
); | ||
|
||
// This command will: | ||
// 1) Consume/delete any changeset files currently in "$REPO_ROOT/.changeset" | ||
// 2) Update the CHANGELOG.md file for the NPM package. | ||
// 3) Bump the version in its package.json accordingly. | ||
|
||
Command::new("changeset").arg("version").run()?; | ||
|
||
let updated_version = NapiConfig::local_version(&package_dir)?; | ||
println!("Updated version: {updated_version}"); | ||
|
||
if package_version == updated_version { | ||
println!("No version changes. Skipping."); | ||
return Ok(()); | ||
} | ||
#[derive(Clone, Debug, Parser)] | ||
pub struct ChangesetsController {} | ||
|
||
impl ChangesetsController { | ||
#[allow(clippy::unused_self)] // for compatibility with other controllers: | ||
pub fn execute(&self) -> Result<()> { | ||
let resolver = NapiResolver::Solidity; | ||
let package_dir = resolver.main_package_dir(); | ||
|
||
let package_version = NapiConfig::local_version(&package_dir)?; | ||
println!("Package version: {package_version}"); | ||
|
||
// Format the updated package files: | ||
let workspace_version = CargoWorkspace::local_version()?; | ||
println!("Workspace version: {workspace_version}"); | ||
|
||
let package_dir = resolver.main_package_dir(); | ||
Command::new("prettier") | ||
.property("--write", package_dir.unwrap_str()) | ||
.run()?; | ||
assert_eq!( | ||
package_version, workspace_version, | ||
"Package version does not match workspace version." | ||
); | ||
|
||
// Update NPM lock file: | ||
// This command will: | ||
// 1) Consume/delete any changeset files currently in "$REPO_ROOT/.changeset" | ||
// 2) Update the CHANGELOG.md file for the NPM package. | ||
// 3) Bump the version in its package.json accordingly. | ||
|
||
Command::new("npm") | ||
.arg("install") | ||
.flag("--package-lock-only") | ||
.run()?; | ||
Command::new("changeset").arg("version").run()?; | ||
|
||
let updated_version = NapiConfig::local_version(&package_dir)?; | ||
println!("Updated version: {updated_version}"); | ||
|
||
if package_version == updated_version { | ||
println!("No version changes. Skipping."); | ||
return Ok(()); | ||
} | ||
|
||
// Update Cargo workspace: | ||
// Format the updated package files: | ||
|
||
println!("Updating Cargo workspace version."); | ||
CargoWorkspace::update_version(&updated_version)?; | ||
let package_dir = resolver.main_package_dir(); | ||
Command::new("prettier") | ||
.property("--write", package_dir.unwrap_str()) | ||
.run()?; | ||
|
||
// Update Cargo lock file: | ||
// Update NPM lock file: | ||
|
||
Command::new("cargo") | ||
.arg("update") | ||
.flag("--workspace") | ||
.run()?; | ||
Command::new("npm") | ||
.arg("install") | ||
.flag("--package-lock-only") | ||
.run()?; | ||
|
||
// Update other CHANGELOG files: | ||
// Update Cargo workspace: | ||
|
||
let source_changelog = package_dir.join("CHANGELOG.md"); | ||
println!("Updating Cargo workspace version."); | ||
CargoWorkspace::update_version(&updated_version)?; | ||
|
||
for destination_changelog in FileWalker::from_repo_root().find(["**/CHANGELOG.md"])? { | ||
if source_changelog != destination_changelog { | ||
println!("Updating: {destination_changelog:?}"); | ||
std::fs::copy(&source_changelog, &destination_changelog)?; | ||
// Update Cargo lock file: | ||
|
||
Command::new("cargo") | ||
.arg("update") | ||
.flag("--workspace") | ||
.run()?; | ||
|
||
// Update other CHANGELOG files: | ||
|
||
let source_changelog = package_dir.join("CHANGELOG.md"); | ||
|
||
for destination_changelog in FileWalker::from_repo_root().find(["**/CHANGELOG.md"])? { | ||
if source_changelog != destination_changelog { | ||
println!("Updating: {destination_changelog:?}"); | ||
std::fs::copy(&source_changelog, &destination_changelog)?; | ||
} | ||
} | ||
} | ||
|
||
Command::new("git") | ||
.args(["stash", "push"]) | ||
.flag("--include-untracked") | ||
.property("--message", "applied changesets") | ||
.run()?; | ||
Command::new("git") | ||
.args(["stash", "push"]) | ||
.flag("--include-untracked") | ||
.property("--message", "applied changesets") | ||
.run()?; | ||
|
||
println!(); | ||
println!("Source files are now updated with the new version, and stored in a 'git stash'."); | ||
println!("The calling CI workflow will now use this stash to create a PR if needed."); | ||
println!(); | ||
println!(); | ||
println!("Source files are now updated with the new version, and stored in a 'git stash'."); | ||
println!("The calling CI workflow will now use this stash to create a PR if needed."); | ||
println!(); | ||
|
||
Ok(()) | ||
Ok(()) | ||
} | ||
} |
50 changes: 30 additions & 20 deletions
50
crates/infra/cli/src/commands/publish/github_release/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
use anyhow::Result; | ||
use clap::{Parser, ValueEnum}; | ||
use infra_utils::cargo::CargoWorkspace; | ||
|
||
use crate::toolchains::mkdocs::Mkdocs; | ||
use crate::utils::DryRun; | ||
|
||
pub fn publish_mkdocs(dry_run: bool) -> Result<()> { | ||
Mkdocs::publish(dry_run) | ||
#[derive(Clone, Debug, Parser)] | ||
pub struct MkdocsController { | ||
/// The target version to publish. | ||
#[arg(long)] | ||
target: PublishTarget, | ||
|
||
#[command(flatten)] | ||
dry_run: DryRun, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, ValueEnum)] | ||
enum PublishTarget { | ||
MainBranch, | ||
LatestRelease, | ||
} | ||
|
||
impl MkdocsController { | ||
pub fn execute(&self) -> Result<()> { | ||
let (version, alias) = match self.target { | ||
PublishTarget::MainBranch => ("main".to_string(), None), | ||
PublishTarget::LatestRelease => { | ||
(CargoWorkspace::local_version()?.to_string(), Some("latest")) | ||
} | ||
}; | ||
|
||
Mkdocs::publish(&version, alias, self.dry_run) | ||
} | ||
} |
Oops, something went wrong.