Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(xtask): Fix nightly action #9042

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading