Skip to content

Commit

Permalink
Merge branch 'main' into codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Jul 19, 2024
2 parents fd30d3e + 6afa40b commit 7c52731
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 26 deletions.
9 changes: 7 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[env]
CARGO_WORKSPACE_DIR = { value = "", relative = true }

[alias]
codegen = "run --package generate-code --"
xtask = "run --package xtask --"
bump = "run --package swc-releaser -- bump"
codegen = "run --package generate-code --"
releaser = "run --package swc-releaser --"
xtask = "run --package xtask --"

[build]

Expand Down
5 changes: 5 additions & 0 deletions .changeset/calm-snakes-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
dbg-swc: patch
---

chore(ci): Integrate `knope` and changeset
24 changes: 0 additions & 24 deletions .github/workflows/bot.yml

This file was deleted.

15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ members = [
"crates/swc_typescript",
"crates/swc_fast_ts_strip",
"tools/generate-code",
"tools/swc-releaser",
]
resolver = "2"

Expand Down Expand Up @@ -59,6 +60,7 @@ resolver = "2"
bumpalo = "3.16.0"
cargo_metadata = "0.18.1"
cfg-if = "1.0.0"
changesets = "0.2.2"
chrono = "0.4.38"
codspeed-criterion-compat = "2.6.0"
console_error_panic_hook = "0.1.7"
Expand Down
2 changes: 2 additions & 0 deletions knope.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[package]
changelog = "CHANGELOG.md"
12 changes: 12 additions & 0 deletions tools/swc-releaser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
edition = "2021"
license.workspace = true
name = "swc-releaser"
publish = false
repository = { workspace = true }
version = "0.1.0"

[dependencies]
anyhow = { workspace = true }
changesets = { workspace = true }
clap = { version = "4.5.9", features = ["derive"] }
101 changes: 101 additions & 0 deletions tools/swc-releaser/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use std::{
env,
path::{Path, PathBuf},
process::Command,
};

use anyhow::{Context, Result};
use changesets::ChangeType;
use clap::{Parser, Subcommand};

#[derive(Debug, Parser)]
struct CliArs {
#[clap(long)]
pub dry_run: bool,

#[clap(subcommand)]
pub cmd: Cmd,
}

#[derive(Debug, Subcommand)]
enum Cmd {
Bump,
}

fn main() -> Result<()> {
let CliArs { dry_run, cmd } = CliArs::parse();

let workspace_dir = env::var("CARGO_WORKSPACE_DIR")
.map(PathBuf::from)
.context("CARGO_WORKSPACE_DIR is not set")?;

match cmd {
Cmd::Bump => {
run_bump(&workspace_dir, dry_run)?;
}
}

Ok(())
}

fn run_bump(workspace_dir: &Path, dry_run: bool) -> Result<()> {
let changeset_dir = workspace_dir.join(".changeset");

let changeset = changesets::ChangeSet::from_directory(&changeset_dir)
.context("failed to load changeset")?;

if changeset.releases.is_empty() {
eprintln!("No changeset found");
return Ok(());
}

for (pkg_name, release) in changeset.releases {
bump_crate(&pkg_name, release.change_type(), dry_run)
.with_context(|| format!("failed to bump package {}", pkg_name))?;
}

{
eprintln!("Removing changeset files... ");
if !dry_run {
std::fs::remove_dir_all(&changeset_dir).context("failed to remove changeset files")?;
}
}

commit(dry_run).context("failed to commit")?;

Ok(())
}

fn commit(dry_run: bool) -> Result<()> {
let mut cmd = Command::new("git");
cmd.arg("commit").arg("-am").arg("chore: Publish crates");

eprintln!("Running {:?}", cmd);

if dry_run {
return Ok(());
}

cmd.status().context("failed to run git commit")?;

Ok(())
}

fn bump_crate(pkg_name: &str, change_type: Option<&ChangeType>, dry_run: bool) -> Result<()> {
let mut cmd = Command::new("cargo");
cmd.arg("mono").arg("bump").arg(pkg_name);

if let Some(ChangeType::Major) = change_type {
cmd.arg("--breaking");
}

eprintln!("Running {:?}", cmd);

if dry_run {
return Ok(());
}

cmd.status().context("failed to run cargo mono bump")?;

Ok(())
}

0 comments on commit 7c52731

Please sign in to comment.