Skip to content

Commit 3d1cb5e

Browse files
committed
Simplify extension tag sniffing
1 parent aca3c30 commit 3d1cb5e

File tree

6 files changed

+27
-34
lines changed

6 files changed

+27
-34
lines changed

.github/workflows/release.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
push:
77
branches:
88
- release
9+
- nightly
910

1011
jobs:
1112
dist:
@@ -49,11 +50,11 @@ jobs:
4950

5051
- name: Dist
5152
if: github.event_name == 'push'
52-
run: cargo xtask dist
53+
run: cargo xtask dist --version 0.2.$GITHUB_RUN_NUMBER --tag $(date --iso --utc)
5354

5455
- name: Dist
5556
if: github.event_name != 'push'
56-
run: cargo xtask dist --nightly
57+
run: cargo xtask dist --version 0.3.$GITHUB_RUN_NUMBER-nightly --tag nightly
5758

5859
- name: Upload artifacts
5960
uses: actions/upload-artifact@v1

editors/code/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"preview": true,
66
"private": true,
77
"icon": "icon.png",
8-
"//": "The real version is in release.yaml, this one just needs to be bigger",
9-
"version": "0.2.20200309-nightly",
8+
"version": "0.4.0-dev",
9+
"releaseTag": "nightly",
1010
"publisher": "matklad",
1111
"repository": {
1212
"url": "https://github.com/rust-analyzer/rust-analyzer.git",

editors/code/src/config.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,17 @@ export class Config {
3838
]
3939
.map(opt => `${this.rootSection}.${opt}`);
4040

41-
readonly packageJsonVersion = vscode
41+
readonly packageJsonVersion: string = vscode
4242
.extensions
4343
.getExtension(this.extensionId)!
4444
.packageJSON
45-
.version as string; // n.n.YYYYMMDD[-nightly]
45+
.version;
4646

47-
/**
48-
* Either `nightly` or `YYYY-MM-DD` (i.e. `stable` release)
49-
*/
50-
readonly extensionReleaseTag: string = (() => {
51-
if (this.packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG;
52-
53-
const realVersionRegexp = /^\d+\.\d+\.(\d{4})(\d{2})(\d{2})/;
54-
const [, yyyy, mm, dd] = this.packageJsonVersion.match(realVersionRegexp)!;
55-
56-
return `${yyyy}-${mm}-${dd}`;
57-
})();
47+
readonly releaseTag: string = vscode
48+
.extensions
49+
.getExtension(this.extensionId)!
50+
.packageJSON
51+
.releaseTag;
5852

5953
private cfg!: vscode.WorkspaceConfiguration;
6054

editors/code/src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async function bootstrap(config: Config, state: PersistentState): Promise<string
111111

112112
async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
113113
if (config.channel === "stable") {
114-
if (config.extensionReleaseTag === NIGHTLY_TAG) {
114+
if (config.releaseTag === NIGHTLY_TAG) {
115115
vscode.window.showWarningMessage(`You are running a nightly version of rust-analyzer extension.
116116
To switch to stable, uninstall the extension and re-install it from the marketplace`);
117117
}
@@ -219,7 +219,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
219219
if (userResponse !== "Download now") return dest;
220220
}
221221

222-
const release = await fetchRelease(config.extensionReleaseTag);
222+
const release = await fetchRelease(config.releaseTag);
223223
const artifact = release.assets.find(artifact => artifact.name === binaryName);
224224
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
225225

xtask/src/dist.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,27 @@ use crate::{
77
project_root,
88
};
99

10-
pub fn run_dist(nightly: bool) -> Result<()> {
10+
pub fn run_dist(version: &str, release_tag: &str) -> Result<()> {
1111
let dist = project_root().join("dist");
1212
rm_rf(&dist)?;
1313
fs2::create_dir_all(&dist)?;
1414

1515
if cfg!(target_os = "linux") {
16-
dist_client(nightly)?;
16+
dist_client(version, release_tag)?;
1717
}
1818
dist_server()?;
1919
Ok(())
2020
}
2121

22-
fn dist_client(nightly: bool) -> Result<()> {
22+
fn dist_client(version: &str, release_tag: &str) -> Result<()> {
2323
let _d = pushd("./editors/code");
24+
let nightly = release_tag == "nightly";
2425

25-
let package_json_path = PathBuf::from("./package.json");
26-
let mut patch = Patch::new(package_json_path.clone())?;
26+
let mut patch = Patch::new("./package.json")?;
2727

28-
let date = run!("date --utc +%Y%m%d")?;
29-
let version_suffix = if nightly { "-nightly" } else { "" };
30-
31-
patch.replace(
32-
r#""version": "0.2.20200309-nightly""#,
33-
&format!(r#""version": "0.1.{}{}""#, date, version_suffix),
34-
);
28+
patch
29+
.replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version))
30+
.replace(r#""releaseTag": "nightly""#, &format!(r#""releaseTag": "{}""#, release_tag));
3531

3632
if nightly {
3733
patch.replace(
@@ -86,7 +82,8 @@ struct Patch {
8682
}
8783

8884
impl Patch {
89-
fn new(path: PathBuf) -> Result<Patch> {
85+
fn new(path: impl Into<PathBuf>) -> Result<Patch> {
86+
let path = path.into();
9087
let contents = fs2::read_to_string(&path)?;
9188
Ok(Patch { path, original_contents: contents.clone(), contents })
9289
}

xtask/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ FLAGS:
103103
run_release(dry_run)
104104
}
105105
"dist" => {
106-
let nightly = args.contains("--nightly");
106+
let version: String = args.value_from_str("--version")?;
107+
let release_tag: String = args.value_from_str("--tag")?;
107108
args.finish()?;
108-
run_dist(nightly)
109+
run_dist(&version, &release_tag)
109110
}
110111
_ => {
111112
eprintln!(

0 commit comments

Comments
 (0)