Skip to content

Commit

Permalink
fix(xtask): Fix nightly action (#9042)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Jun 12, 2024
1 parent 2ecd550 commit 733dcc6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 72 deletions.
51 changes: 11 additions & 40 deletions xtask/src/npm/nightly.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
use std::process::{Command, Stdio};

use anyhow::{Context, Result};
use anyhow::{ensure, Context, Result};
use chrono::Utc;
use clap::Args;
use semver::{Prerelease, Version};

use crate::{
npm::util::{bump_swc_cli, set_version, update_swc_crates},
npm::util::{bump_swc_cli, set_version},
util::{repository_root, wrap},
};

#[derive(Debug, Args)]
pub(super) struct NightlyCmd {
#[clap(long)]
git: bool,
}
pub(super) struct NightlyCmd {}

impl NightlyCmd {
pub fn run(self) -> Result<()> {
wrap(|| {
let date = Utc::now().format("%Y%m%d").to_string();

update_swc_crates().context("failed to update swc crates")?;

let root_pkg_json = repository_root()?.join("./packages/core/package.json");
let content = serde_json::from_reader::<_, serde_json::Value>(
std::fs::File::open(root_pkg_json)
Expand All @@ -37,38 +32,14 @@ impl NightlyCmd {
set_version(&version).context("failed to set version")?;
bump_swc_cli().context("failed to bump swc-cli")?;

if self.git {
// git add -A
Command::new("git")
.current_dir(repository_root()?)
.arg("add")
.arg("-A")
.stderr(Stdio::inherit())
.status()
.context("git add failed")?;

// git commit --no-verify -m 'chore: Publish $version'

Command::new("git")
.current_dir(repository_root()?)
.arg("commit")
.arg("--no-verify")
.arg("-m")
.arg(format!("chore: Publish {}", version))
.stderr(Stdio::inherit())
.status()
.context("git commit failed")?;

// git tag $version

Command::new("git")
.current_dir(repository_root()?)
.arg("tag")
.arg(format!("v{}", version))
.stderr(Stdio::inherit())
.status()
.context("git tag failed")?;
}
// ./scripts/publish.sh $version
let status = Command::new("sh")
.arg("./scripts/publish.sh")
.arg(format!("{}", version))
.status()
.context("failed to publish")?;

ensure!(status.success(), "failed to publish");

Ok(())
})
Expand Down
32 changes: 0 additions & 32 deletions xtask/src/npm/util.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
use std::process::{Command, Stdio};

use anyhow::{Context, Result};
use cargo_metadata::MetadataCommand;
use semver::Version;

use crate::util::{repository_root, wrap};

/// Get the list of swc crates in the main swc repository.
fn get_swc_crates_of_bindings() -> Result<Vec<String>> {
let md = MetadataCommand::new()
.current_dir(repository_root()?.join("bindings"))
.exec()?;

Ok(md
.packages
.iter()
.filter(|p| p.repository.as_deref() == Some("https://github.com/swc-project/swc.git"))
.map(|p| p.name.clone())
.collect::<Vec<_>>())
}

pub fn update_swc_crates() -> Result<()> {
let mut c = Command::new("cargo");
c.current_dir(repository_root()?.join("bindings"));
c.arg("upgrade")
.arg("--incompatible")
.arg("--recursive")
.arg("false");

for pkg in get_swc_crates_of_bindings()? {
c.arg("--package").arg(pkg);
}

c.status()?;

Ok(())
}

pub fn set_version(version: &Version) -> Result<()> {
wrap(|| {
let mut c = Command::new("npm");
Expand Down

0 comments on commit 733dcc6

Please sign in to comment.