Simplify extension tag sniffing

This commit is contained in:
Aleksey Kladov 2020-03-19 09:32:57 +01:00
parent aca3c3086e
commit 3d1cb5e20f
6 changed files with 27 additions and 34 deletions

View file

@ -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

View file

@ -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",

View file

@ -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;

View file

@ -111,7 +111,7 @@ async function bootstrap(config: Config, state: PersistentState): Promise<string
async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
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<string
if (userResponse !== "Download now") return dest;
}
const release = await fetchRelease(config.extensionReleaseTag);
const release = await fetchRelease(config.releaseTag);
const artifact = release.assets.find(artifact => artifact.name === binaryName);
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);

View file

@ -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<Patch> {
fn new(path: impl Into<PathBuf>) -> Result<Patch> {
let path = path.into();
let contents = fs2::read_to_string(&path)?;
Ok(Patch { path, original_contents: contents.clone(), contents })
}

View file

@ -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!(