From 3d1cb5e20f7a05314f6fd4261076b0a85546cfe4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 19 Mar 2020 09:32:57 +0100 Subject: Simplify extension tag sniffing --- .github/workflows/release.yaml | 5 +++-- editors/code/package.json | 4 ++-- editors/code/src/config.ts | 20 +++++++------------- editors/code/src/main.ts | 4 ++-- xtask/src/dist.rs | 23 ++++++++++------------- xtask/src/main.rs | 5 +++-- 6 files changed, 27 insertions(+), 34 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0434b6128..13bc172ba 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,6 +6,7 @@ on: push: branches: - release + - nightly jobs: dist: @@ -49,11 +50,11 @@ jobs: - name: Dist if: github.event_name == 'push' - run: cargo xtask dist + run: cargo xtask dist --version 0.2.$GITHUB_RUN_NUMBER --tag $(date --iso --utc) - name: Dist if: github.event_name != 'push' - run: cargo xtask dist --nightly + run: cargo xtask dist --version 0.3.$GITHUB_RUN_NUMBER-nightly --tag nightly - name: Upload artifacts uses: actions/upload-artifact@v1 diff --git a/editors/code/package.json b/editors/code/package.json index 150c36845..9f2fe06f3 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -5,8 +5,8 @@ "preview": true, "private": true, "icon": "icon.png", - "//": "The real version is in release.yaml, this one just needs to be bigger", - "version": "0.2.20200309-nightly", + "version": "0.4.0-dev", + "releaseTag": "nightly", "publisher": "matklad", "repository": { "url": "https://github.com/rust-analyzer/rust-analyzer.git", diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 28698ab8e..54b905303 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -38,23 +38,17 @@ export class Config { ] .map(opt => `${this.rootSection}.${opt}`); - readonly packageJsonVersion = vscode + readonly packageJsonVersion: string = vscode .extensions .getExtension(this.extensionId)! .packageJSON - .version as string; // n.n.YYYYMMDD[-nightly] + .version; - /** - * Either `nightly` or `YYYY-MM-DD` (i.e. `stable` release) - */ - readonly extensionReleaseTag: string = (() => { - if (this.packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG; - - const realVersionRegexp = /^\d+\.\d+\.(\d{4})(\d{2})(\d{2})/; - const [, yyyy, mm, dd] = this.packageJsonVersion.match(realVersionRegexp)!; - - return `${yyyy}-${mm}-${dd}`; - })(); + readonly releaseTag: string = vscode + .extensions + .getExtension(this.extensionId)! + .packageJSON + .releaseTag; private cfg!: vscode.WorkspaceConfiguration; diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index d907f3e6f..5297614a9 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -111,7 +111,7 @@ async function bootstrap(config: Config, state: PersistentState): Promise { if (config.channel === "stable") { - if (config.extensionReleaseTag === NIGHTLY_TAG) { + if (config.releaseTag === NIGHTLY_TAG) { vscode.window.showWarningMessage(`You are running a nightly version of rust-analyzer extension. To switch to stable, uninstall the extension and re-install it from the marketplace`); } @@ -219,7 +219,7 @@ async function getServer(config: Config, state: PersistentState): Promise artifact.name === binaryName); assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index e3dddd9b1..3a14f8a63 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs @@ -7,31 +7,27 @@ use crate::{ project_root, }; -pub fn run_dist(nightly: bool) -> Result<()> { +pub fn run_dist(version: &str, release_tag: &str) -> Result<()> { let dist = project_root().join("dist"); rm_rf(&dist)?; fs2::create_dir_all(&dist)?; if cfg!(target_os = "linux") { - dist_client(nightly)?; + dist_client(version, release_tag)?; } dist_server()?; Ok(()) } -fn dist_client(nightly: bool) -> Result<()> { +fn dist_client(version: &str, release_tag: &str) -> Result<()> { let _d = pushd("./editors/code"); + let nightly = release_tag == "nightly"; - let package_json_path = PathBuf::from("./package.json"); - let mut patch = Patch::new(package_json_path.clone())?; + let mut patch = Patch::new("./package.json")?; - let date = run!("date --utc +%Y%m%d")?; - let version_suffix = if nightly { "-nightly" } else { "" }; - - patch.replace( - r#""version": "0.2.20200309-nightly""#, - &format!(r#""version": "0.1.{}{}""#, date, version_suffix), - ); + patch + .replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version)) + .replace(r#""releaseTag": "nightly""#, &format!(r#""releaseTag": "{}""#, release_tag)); if nightly { patch.replace( @@ -86,7 +82,8 @@ struct Patch { } impl Patch { - fn new(path: PathBuf) -> Result { + fn new(path: impl Into) -> Result { + let path = path.into(); let contents = fs2::read_to_string(&path)?; Ok(Patch { path, original_contents: contents.clone(), contents }) } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 7c8ea9001..aafa73610 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -103,9 +103,10 @@ FLAGS: run_release(dry_run) } "dist" => { - let nightly = args.contains("--nightly"); + let version: String = args.value_from_str("--version")?; + let release_tag: String = args.value_from_str("--tag")?; args.finish()?; - run_dist(nightly) + run_dist(&version, &release_tag) } _ => { eprintln!( -- cgit v1.2.3