From 3d1275b0024d1e1876d0b982083aafa9bd2ee56b Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 15:01:52 +0100 Subject: [PATCH 01/12] improve cross-compatibility of xtasks --- xtask/src/commands/copy_lsp.rs | 10 ++++++++-- xtask/src/commands/copy_lsp_release.rs | 10 ++++++++-- xtask/src/commands/install.rs | 10 ++++++++-- xtask/src/commands/package.rs | 10 ++++++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/xtask/src/commands/copy_lsp.rs b/xtask/src/commands/copy_lsp.rs index a28d32c6..6792f967 100644 --- a/xtask/src/commands/copy_lsp.rs +++ b/xtask/src/commands/copy_lsp.rs @@ -1,7 +1,7 @@ use xshell::{Shell, cmd}; -const SRC: &str = "./target/debug/witcherscript-lsp.exe"; +const SRC: &str = "./target/debug/witcherscript-lsp"; const DST: &str = "./editors/vscode/server/bin"; pub fn copy_lsp() -> anyhow::Result<()> { @@ -10,7 +10,13 @@ pub fn copy_lsp() -> anyhow::Result<()> { println!("Building the LSP..."); cmd!(sh, "cargo build --package witcherscript-lsp").run()?; - sh.copy_file(SRC, DST)?; + let src = if cfg!(unix) { + SRC.to_string() + } else { + format!("{SRC}.exe") + }; + + sh.copy_file(src, DST)?; println!("Copied debug LSP into {}", DST); Ok(()) diff --git a/xtask/src/commands/copy_lsp_release.rs b/xtask/src/commands/copy_lsp_release.rs index c0c81b24..88b12aa6 100644 --- a/xtask/src/commands/copy_lsp_release.rs +++ b/xtask/src/commands/copy_lsp_release.rs @@ -1,7 +1,7 @@ use xshell::{Shell, cmd}; -const SRC: &str = "./target/release/witcherscript-lsp.exe"; +const SRC: &str = "./target/release/witcherscript-lsp"; const DST: &str = "./editors/vscode/server/bin"; pub fn copy_lsp_release() -> anyhow::Result<()> { @@ -10,7 +10,13 @@ pub fn copy_lsp_release() -> anyhow::Result<()> { println!("Building the LSP..."); cmd!(sh, "cargo build --package witcherscript-lsp --release").run()?; - sh.copy_file(SRC, DST)?; + let src = if cfg!(unix) { + SRC.to_string() + } else { + format!("{SRC}.exe") + }; + + sh.copy_file(src, DST)?; println!("Copied release LSP into {}", DST); Ok(()) diff --git a/xtask/src/commands/install.rs b/xtask/src/commands/install.rs index 10652182..0698716a 100644 --- a/xtask/src/commands/install.rs +++ b/xtask/src/commands/install.rs @@ -2,7 +2,7 @@ use anyhow::{Context, bail}; use xshell::{Shell, cmd}; -const LSP_SRC: &str = "./target/release/witcherscript-lsp.exe"; +const LSP_SRC: &str = "./target/release/witcherscript-lsp"; const LSP_DST: &str = "./editors/vscode/server/bin"; const EXT_DIR: &str = "./editors/vscode"; const VSIX_NAME: &str = "witcherscript-ide.vsix"; @@ -13,7 +13,13 @@ pub fn install() -> anyhow::Result<()> { println!("Building LSP release..."); cmd!(sh, "cargo build --package witcherscript-lsp --release").run()?; - sh.copy_file(LSP_SRC, LSP_DST)?; + let lsp_src = if cfg!(unix) { + LSP_SRC.to_string() + } else { + format!("{LSP_SRC}.exe") + }; + + sh.copy_file(lsp_src, LSP_DST)?; println!("Copied LSP into {}", LSP_DST); sh.change_dir(EXT_DIR); diff --git a/xtask/src/commands/package.rs b/xtask/src/commands/package.rs index eb03c7e7..ee4ae244 100644 --- a/xtask/src/commands/package.rs +++ b/xtask/src/commands/package.rs @@ -2,7 +2,7 @@ use anyhow::Context; use xshell::{Shell, cmd}; -const LSP_SRC: &str = "./target/release/witcherscript-lsp.exe"; +const LSP_SRC: &str = "./target/release/witcherscript-lsp"; const LSP_DST: &str = "./editors/vscode/server/bin"; const EXT_DIR: &str = "./editors/vscode"; const VSIX_NAME: &str = "witcherscript-ide.vsix"; @@ -13,7 +13,13 @@ pub fn package() -> anyhow::Result<()> { println!("Building LSP release..."); cmd!(sh, "cargo build --package witcherscript-lsp --release").run()?; - sh.copy_file(LSP_SRC, LSP_DST)?; + let lsp_src = if cfg!(unix) { + LSP_SRC.to_string() + } else { + format!("{LSP_SRC}.exe") + }; + + sh.copy_file(lsp_src, LSP_DST)?; println!("Copied LSP into {}", LSP_DST); From 39c378be7b92180a66bd194f55150a0efac05ea5 Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 15:34:46 +0100 Subject: [PATCH 02/12] output_dir arg in package xtask + delete vsix after install xtask --- xtask/src/cli.rs | 4 +++- xtask/src/commands/install.rs | 4 ++++ xtask/src/commands/package.rs | 21 +++++++++++++++++++-- xtask/src/main.rs | 2 +- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/xtask/src/cli.rs b/xtask/src/cli.rs index 6b22e6a5..e9edff5b 100644 --- a/xtask/src/cli.rs +++ b/xtask/src/cli.rs @@ -16,7 +16,9 @@ pub enum Commands { /// Copy release build of the LSP server to the VSCode client CopyLspRelease, /// Build and package VSCode extension into a .vsix file - Package, + Package { + output_dir: Option + }, /// Build, package and install the VSCode extension Install } diff --git a/xtask/src/commands/install.rs b/xtask/src/commands/install.rs index 0698716a..7112188b 100644 --- a/xtask/src/commands/install.rs +++ b/xtask/src/commands/install.rs @@ -50,6 +50,10 @@ pub fn install() -> anyhow::Result<()> { if !installed_extensions.contains("witcherscript-ide") { bail!("Could not install the Visual Studio Code extension."); } + + // Remove the vsix file + // If you want to keep it use xtask package instead + sh.remove_path(VSIX_NAME)?; Ok(()) } \ No newline at end of file diff --git a/xtask/src/commands/package.rs b/xtask/src/commands/package.rs index ee4ae244..fb16cbaa 100644 --- a/xtask/src/commands/package.rs +++ b/xtask/src/commands/package.rs @@ -1,3 +1,4 @@ +use std::path::PathBuf; use anyhow::Context; use xshell::{Shell, cmd}; @@ -7,9 +8,16 @@ const LSP_DST: &str = "./editors/vscode/server/bin"; const EXT_DIR: &str = "./editors/vscode"; const VSIX_NAME: &str = "witcherscript-ide.vsix"; -pub fn package() -> anyhow::Result<()> { +pub fn package(output_dir: Option) -> anyhow::Result<()> { let sh = Shell::new()?; + // normalize the output path so it stays valid when we change cwd + let output_dir = if let Some(output_dir) = output_dir { + Some(PathBuf::from(&output_dir).canonicalize()?) + } else { + None + }; + println!("Building LSP release..."); cmd!(sh, "cargo build --package witcherscript-lsp --release").run()?; @@ -38,8 +46,17 @@ pub fn package() -> anyhow::Result<()> { } let version = env!("CARGO_PKG_VERSION"); - sh.copy_file(VSIX_NAME, format!("witcherscript-ide-{version}.vsix"))?; + let vsix_file = format!("witcherscript-ide-{version}.vsix"); + let vsix_dst = if let Some(output_dir) = output_dir { + output_dir.join(vsix_file) + } else { + PathBuf::from(&vsix_file).canonicalize()? + }; + + sh.copy_file(VSIX_NAME, vsix_dst.as_os_str())?; + println!("Copied vsix package into {}", vsix_dst.display()); + // remove the original vsix file sh.remove_path(VSIX_NAME)?; Ok(()) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 600056a7..02b4cd80 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -11,7 +11,7 @@ fn main() -> anyhow::Result<()> { match cli.command { cli::Commands::CopyLsp => commands::copy_lsp(), cli::Commands::CopyLspRelease => commands::copy_lsp_release(), - cli::Commands::Package => commands::package(), + cli::Commands::Package { output_dir } => commands::package(output_dir), cli::Commands::Install => commands::install() } } \ No newline at end of file From 1656e48538903f3c2e75aef6c88e7d4c2e68074e Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 15:58:41 +0100 Subject: [PATCH 03/12] xtask: add npm ci step to package and install --- xtask/src/commands/install.rs | 4 ++-- xtask/src/commands/package.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xtask/src/commands/install.rs b/xtask/src/commands/install.rs index 7112188b..3ed4a814 100644 --- a/xtask/src/commands/install.rs +++ b/xtask/src/commands/install.rs @@ -26,16 +26,16 @@ pub fn install() -> anyhow::Result<()> { if cfg!(unix) { cmd!(sh, "npm --version").run().with_context(|| "npm is required")?; - cmd!(sh, "vsce --version").run().with_context(|| "vsce is required: npm install -g vsce")?; cmd!(sh, "code --version").run().with_context(|| "Visual Studio Code is required")?; + cmd!(sh, "npm ci").run()?; cmd!(sh, "npm run package").run()?; } else { cmd!(sh, "cmd.exe /c npm --version").run().with_context(|| "npm is required")?; - cmd!(sh, "cmd.exe /c vsce --version").run().with_context(|| "vsce is required: npm install -g vsce")?; cmd!(sh, "cmd.exe /c code --version").run().with_context(|| "Visual Studio Code is required")?; + cmd!(sh, "cmd.exe /c npm ci").run()?; cmd!(sh, "cmd.exe /c npm run package").run()?; } diff --git a/xtask/src/commands/package.rs b/xtask/src/commands/package.rs index fb16cbaa..e46d3f99 100644 --- a/xtask/src/commands/package.rs +++ b/xtask/src/commands/package.rs @@ -35,13 +35,13 @@ pub fn package(output_dir: Option) -> anyhow::Result<()> { if cfg!(unix) { cmd!(sh, "npm --version").run().with_context(|| "npm is required")?; - cmd!(sh, "vsce --version").run().with_context(|| "vsce is required: npm install -g vsce")?; + cmd!(sh, "npm ci").run()?; cmd!(sh, "npm run package").run()?; } else { cmd!(sh, "cmd.exe /c npm --version").run().with_context(|| "npm is required")?; - cmd!(sh, "cmd.exe /c vsce --version").run().with_context(|| "vsce is required: npm install -g vsce")?; + cmd!(sh, "cmd.exe /c npm ci").run()?; cmd!(sh, "cmd.exe /c npm run package").run()?; } From 62301d2709beb0bb0d6eed0b6229bd21b2e3ec07 Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 16:04:30 +0100 Subject: [PATCH 04/12] ci/cd: draft-release action --- .github/workflows/draft-release.yml | 38 +++++++++++++++++++++++++++++ xtask/README.md | 2 ++ 2 files changed, 40 insertions(+) create mode 100644 .github/workflows/draft-release.yml diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml new file mode 100644 index 00000000..266314c8 --- /dev/null +++ b/.github/workflows/draft-release.yml @@ -0,0 +1,38 @@ +name: draft-release + +on: + push: + tags: '*' + +env: + CARGO_TERM_COLOR: always + +jobs: + release: + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup npm + uses: actions/setup-node@v4 + - name: Setup rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: x86_64-pc-windows-msvc + override: true + + - name: Build with Cargo + run: cargo build --release --target=x86_64-pc-windows-msvc + + - name: Pack the client + run: cargo xtask package . + + - name: Create draft release + uses: ncipollo/release-action@v1 + with: + artifacts: "*.vsix" + draft: true + generateReleaseNotes: true \ No newline at end of file diff --git a/xtask/README.md b/xtask/README.md index 2c98dd73..708d7ee4 100644 --- a/xtask/README.md +++ b/xtask/README.md @@ -2,4 +2,6 @@ This crate provides automation scripts for the repo. They are OS-agnostic as they don't directly use any specific shell. All you need is the `cargo xtask` command. +Beware, these tasks are used in github workflows, so make sure any breaking changes are also reflected in `.github/workflows`. + More about xtask workflow [here](https://github.com/matklad/cargo-xtask). \ No newline at end of file From c80f831009956afc0384aedbe4b7a1003d99ad93 Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 16:09:06 +0100 Subject: [PATCH 05/12] ci/cd: run `draft-release` on both windows and linux --- .github/workflows/draft-release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index 266314c8..7819dc0e 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -9,8 +9,11 @@ env: jobs: release: - runs-on: windows-latest + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v2 From 932f7f88354d39e96e5f4cc7d8ba4c688681a4b6 Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 16:29:29 +0100 Subject: [PATCH 06/12] ci/cd fix: different target for different platform --- .github/workflows/draft-release.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index 7819dc0e..800b1d7b 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -12,6 +12,11 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: windows-latest + target: x86_64-pc-windows-msvc runs-on: ${{ matrix.os }} steps: @@ -24,11 +29,11 @@ jobs: uses: actions-rs/toolchain@v1 with: toolchain: stable - target: x86_64-pc-windows-msvc + target: ${{ matrix.target }} override: true - name: Build with Cargo - run: cargo build --release --target=x86_64-pc-windows-msvc + run: cargo build --release --target=${{ matrix.target }} - name: Pack the client run: cargo xtask package . From aba5d4665cc47b085d2c4a52541bd283f03a88c1 Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 17:52:58 +0100 Subject: [PATCH 07/12] xtask fix: make sure LSP destination exists --- xtask/src/commands/copy_lsp.rs | 3 +++ xtask/src/commands/copy_lsp_release.rs | 3 +++ xtask/src/commands/install.rs | 4 ++++ xtask/src/commands/package.rs | 3 +++ 4 files changed, 13 insertions(+) diff --git a/xtask/src/commands/copy_lsp.rs b/xtask/src/commands/copy_lsp.rs index 6792f967..d9c18d2a 100644 --- a/xtask/src/commands/copy_lsp.rs +++ b/xtask/src/commands/copy_lsp.rs @@ -16,6 +16,9 @@ pub fn copy_lsp() -> anyhow::Result<()> { format!("{SRC}.exe") }; + // make sure DST exists + sh.create_dir(DST)?; + sh.copy_file(src, DST)?; println!("Copied debug LSP into {}", DST); diff --git a/xtask/src/commands/copy_lsp_release.rs b/xtask/src/commands/copy_lsp_release.rs index 88b12aa6..da35155f 100644 --- a/xtask/src/commands/copy_lsp_release.rs +++ b/xtask/src/commands/copy_lsp_release.rs @@ -16,6 +16,9 @@ pub fn copy_lsp_release() -> anyhow::Result<()> { format!("{SRC}.exe") }; + // make sure DST exists + sh.create_dir(DST)?; + sh.copy_file(src, DST)?; println!("Copied release LSP into {}", DST); diff --git a/xtask/src/commands/install.rs b/xtask/src/commands/install.rs index 3ed4a814..759cd9ee 100644 --- a/xtask/src/commands/install.rs +++ b/xtask/src/commands/install.rs @@ -19,9 +19,13 @@ pub fn install() -> anyhow::Result<()> { format!("{LSP_SRC}.exe") }; + // make sure DST exists + sh.create_dir(LSP_DST)?; + sh.copy_file(lsp_src, LSP_DST)?; println!("Copied LSP into {}", LSP_DST); + sh.change_dir(EXT_DIR); if cfg!(unix) { diff --git a/xtask/src/commands/package.rs b/xtask/src/commands/package.rs index e46d3f99..88e0bf4e 100644 --- a/xtask/src/commands/package.rs +++ b/xtask/src/commands/package.rs @@ -27,6 +27,9 @@ pub fn package(output_dir: Option) -> anyhow::Result<()> { format!("{LSP_SRC}.exe") }; + // make sure DST exists + sh.create_dir(LSP_DST)?; + sh.copy_file(lsp_src, LSP_DST)?; println!("Copied LSP into {}", LSP_DST); From d0ebea6d9c5fd155a5083b5f6dd84e8d3a968497 Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 17:54:11 +0100 Subject: [PATCH 08/12] ci/cd: refactor --- .github/workflows/build-and-test.yml | 5 +---- .github/workflows/draft-release.yml | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 11951100..4c746adb 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -20,9 +20,6 @@ jobs: with: toolchain: stable - name: Build with Cargo - uses: actions-rs/cargo@v1 - with: - command: build - args: --release + run: cargo build --release --workspace - name: Run tests run: cargo test --verbose \ No newline at end of file diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index 800b1d7b..258b3445 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -33,7 +33,7 @@ jobs: override: true - name: Build with Cargo - run: cargo build --release --target=${{ matrix.target }} + run: cargo build --release --workspace --target=${{ matrix.target }} - name: Pack the client run: cargo xtask package . @@ -43,4 +43,5 @@ jobs: with: artifacts: "*.vsix" draft: true + allowUpdates: true generateReleaseNotes: true \ No newline at end of file From 5ae97362b4acdffb7468ea72586f4cfe280ea53e Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 20:00:54 +0100 Subject: [PATCH 09/12] refactor --- .github/workflows/draft-release.yml | 5 +---- xtask/src/cli.rs | 4 +++- xtask/src/commands/package.rs | 4 ++-- xtask/src/main.rs | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index 258b3445..10f6b5d0 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -32,11 +32,8 @@ jobs: target: ${{ matrix.target }} override: true - - name: Build with Cargo - run: cargo build --release --workspace --target=${{ matrix.target }} - - name: Pack the client - run: cargo xtask package . + run: cargo xtask package --out-dir . - name: Create draft release uses: ncipollo/release-action@v1 diff --git a/xtask/src/cli.rs b/xtask/src/cli.rs index e9edff5b..d4e3ae98 100644 --- a/xtask/src/cli.rs +++ b/xtask/src/cli.rs @@ -17,7 +17,9 @@ pub enum Commands { CopyLspRelease, /// Build and package VSCode extension into a .vsix file Package { - output_dir: Option + /// Output directory for the .vsix file; default is the current working directory + #[arg(long)] + out_dir: Option }, /// Build, package and install the VSCode extension Install diff --git a/xtask/src/commands/package.rs b/xtask/src/commands/package.rs index 88e0bf4e..ee4d3318 100644 --- a/xtask/src/commands/package.rs +++ b/xtask/src/commands/package.rs @@ -8,11 +8,11 @@ const LSP_DST: &str = "./editors/vscode/server/bin"; const EXT_DIR: &str = "./editors/vscode"; const VSIX_NAME: &str = "witcherscript-ide.vsix"; -pub fn package(output_dir: Option) -> anyhow::Result<()> { +pub fn package(out_dir: Option) -> anyhow::Result<()> { let sh = Shell::new()?; // normalize the output path so it stays valid when we change cwd - let output_dir = if let Some(output_dir) = output_dir { + let output_dir = if let Some(output_dir) = out_dir { Some(PathBuf::from(&output_dir).canonicalize()?) } else { None diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 02b4cd80..d0e37f09 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -11,7 +11,7 @@ fn main() -> anyhow::Result<()> { match cli.command { cli::Commands::CopyLsp => commands::copy_lsp(), cli::Commands::CopyLspRelease => commands::copy_lsp_release(), - cli::Commands::Package { output_dir } => commands::package(output_dir), + cli::Commands::Package { out_dir } => commands::package(out_dir), cli::Commands::Install => commands::install() } } \ No newline at end of file From bf5dfc80d58e77ad007831279c1ae239c861e911 Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 23:15:09 +0100 Subject: [PATCH 10/12] xtask: add `prep-lsp` command to replace `copy-lsp` and `copy-lsp-release` --- xtask/src/cli.rs | 13 +++++--- xtask/src/commands/copy_lsp.rs | 26 ---------------- xtask/src/commands/copy_lsp_release.rs | 26 ---------------- xtask/src/commands/mod.rs | 6 ++-- xtask/src/commands/prep_lsp.rs | 42 ++++++++++++++++++++++++++ xtask/src/main.rs | 3 +- 6 files changed, 54 insertions(+), 62 deletions(-) delete mode 100644 xtask/src/commands/copy_lsp.rs delete mode 100644 xtask/src/commands/copy_lsp_release.rs create mode 100644 xtask/src/commands/prep_lsp.rs diff --git a/xtask/src/cli.rs b/xtask/src/cli.rs index d4e3ae98..468b6480 100644 --- a/xtask/src/cli.rs +++ b/xtask/src/cli.rs @@ -11,10 +11,15 @@ pub struct Cli { #[derive(Subcommand)] pub enum Commands { - /// Copy debug build of the LSP server to the VSCode client - CopyLsp, - /// Copy release build of the LSP server to the VSCode client - CopyLspRelease, + // Build and copy LSP server into VSCode's extension directory + PrepLsp { + /// Should LSP be built with optimised release profile + #[arg(long)] + release: bool, + /// Compilation target triple + #[arg(long)] + target: Option + }, /// Build and package VSCode extension into a .vsix file Package { /// Output directory for the .vsix file; default is the current working directory diff --git a/xtask/src/commands/copy_lsp.rs b/xtask/src/commands/copy_lsp.rs deleted file mode 100644 index d9c18d2a..00000000 --- a/xtask/src/commands/copy_lsp.rs +++ /dev/null @@ -1,26 +0,0 @@ -use xshell::{Shell, cmd}; - - -const SRC: &str = "./target/debug/witcherscript-lsp"; -const DST: &str = "./editors/vscode/server/bin"; - -pub fn copy_lsp() -> anyhow::Result<()> { - let sh = Shell::new()?; - - println!("Building the LSP..."); - cmd!(sh, "cargo build --package witcherscript-lsp").run()?; - - let src = if cfg!(unix) { - SRC.to_string() - } else { - format!("{SRC}.exe") - }; - - // make sure DST exists - sh.create_dir(DST)?; - - sh.copy_file(src, DST)?; - println!("Copied debug LSP into {}", DST); - - Ok(()) -} \ No newline at end of file diff --git a/xtask/src/commands/copy_lsp_release.rs b/xtask/src/commands/copy_lsp_release.rs deleted file mode 100644 index da35155f..00000000 --- a/xtask/src/commands/copy_lsp_release.rs +++ /dev/null @@ -1,26 +0,0 @@ -use xshell::{Shell, cmd}; - - -const SRC: &str = "./target/release/witcherscript-lsp"; -const DST: &str = "./editors/vscode/server/bin"; - -pub fn copy_lsp_release() -> anyhow::Result<()> { - let sh = Shell::new()?; - - println!("Building the LSP..."); - cmd!(sh, "cargo build --package witcherscript-lsp --release").run()?; - - let src = if cfg!(unix) { - SRC.to_string() - } else { - format!("{SRC}.exe") - }; - - // make sure DST exists - sh.create_dir(DST)?; - - sh.copy_file(src, DST)?; - println!("Copied release LSP into {}", DST); - - Ok(()) -} \ No newline at end of file diff --git a/xtask/src/commands/mod.rs b/xtask/src/commands/mod.rs index 4357673e..4db08a16 100644 --- a/xtask/src/commands/mod.rs +++ b/xtask/src/commands/mod.rs @@ -1,9 +1,7 @@ -mod copy_lsp; -mod copy_lsp_release; +mod prep_lsp; mod package; mod install; -pub use copy_lsp::copy_lsp; -pub use copy_lsp_release::copy_lsp_release; +pub use prep_lsp::prep_lsp; pub use package::package; pub use install::install; \ No newline at end of file diff --git a/xtask/src/commands/prep_lsp.rs b/xtask/src/commands/prep_lsp.rs new file mode 100644 index 00000000..3001cc71 --- /dev/null +++ b/xtask/src/commands/prep_lsp.rs @@ -0,0 +1,42 @@ +use std::path::PathBuf; +use xshell::{Shell, cmd}; + + +const LSP_DST: &str = "./editors/vscode/server/bin"; + +pub fn prep_lsp(release: bool, target: Option) -> anyhow::Result<()> { + let sh = Shell::new()?; + + let mut build = cmd!(sh, "cargo build --package witcherscript-lsp"); + + let mut lsp_src = PathBuf::from("./target"); + if let Some(target) = target { + build = build.arg("--target").arg(&target); + lsp_src.push(target); + } + + if release { + build = build.arg("--release"); + lsp_src.push("release"); + } else { + lsp_src.push("debug"); + } + + lsp_src.push("witcherscript-lsp"); + + if cfg!(windows) { + lsp_src.set_extension("exe"); + } + + println!("Building the LSP..."); + build.run()?; + + + // make sure destination folder exists + sh.create_dir(LSP_DST)?; + + sh.copy_file(lsp_src, LSP_DST)?; + println!("Copied LSP into {}", LSP_DST); + + Ok(()) +} \ No newline at end of file diff --git a/xtask/src/main.rs b/xtask/src/main.rs index d0e37f09..f49ed2f1 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -9,8 +9,7 @@ fn main() -> anyhow::Result<()> { let cli = Cli::parse(); match cli.command { - cli::Commands::CopyLsp => commands::copy_lsp(), - cli::Commands::CopyLspRelease => commands::copy_lsp_release(), + cli::Commands::PrepLsp { release, target } => commands::prep_lsp(release, target), cli::Commands::Package { out_dir } => commands::package(out_dir), cli::Commands::Install => commands::install() } From 4a070aa648c8d98ccc24817757e3fb78a7a02da1 Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 23:55:50 +0100 Subject: [PATCH 11/12] xtask: remove build stage in `package` and `install` + add args to those commands --- xtask/src/cli.rs | 5 ++++- xtask/src/commands/install.rs | 18 ------------------ xtask/src/commands/package.rs | 30 ++++++------------------------ xtask/src/main.rs | 2 +- 4 files changed, 11 insertions(+), 44 deletions(-) diff --git a/xtask/src/cli.rs b/xtask/src/cli.rs index 468b6480..f6d71791 100644 --- a/xtask/src/cli.rs +++ b/xtask/src/cli.rs @@ -24,7 +24,10 @@ pub enum Commands { Package { /// Output directory for the .vsix file; default is the current working directory #[arg(long)] - out_dir: Option + out_dir: Option, + /// Name of the output file without the extension + #[arg(long)] + out_name: Option }, /// Build, package and install the VSCode extension Install diff --git a/xtask/src/commands/install.rs b/xtask/src/commands/install.rs index 759cd9ee..926c8611 100644 --- a/xtask/src/commands/install.rs +++ b/xtask/src/commands/install.rs @@ -2,30 +2,12 @@ use anyhow::{Context, bail}; use xshell::{Shell, cmd}; -const LSP_SRC: &str = "./target/release/witcherscript-lsp"; -const LSP_DST: &str = "./editors/vscode/server/bin"; const EXT_DIR: &str = "./editors/vscode"; const VSIX_NAME: &str = "witcherscript-ide.vsix"; pub fn install() -> anyhow::Result<()> { let sh = Shell::new()?; - println!("Building LSP release..."); - cmd!(sh, "cargo build --package witcherscript-lsp --release").run()?; - - let lsp_src = if cfg!(unix) { - LSP_SRC.to_string() - } else { - format!("{LSP_SRC}.exe") - }; - - // make sure DST exists - sh.create_dir(LSP_DST)?; - - sh.copy_file(lsp_src, LSP_DST)?; - println!("Copied LSP into {}", LSP_DST); - - sh.change_dir(EXT_DIR); if cfg!(unix) { diff --git a/xtask/src/commands/package.rs b/xtask/src/commands/package.rs index ee4d3318..6c35615b 100644 --- a/xtask/src/commands/package.rs +++ b/xtask/src/commands/package.rs @@ -3,37 +3,20 @@ use anyhow::Context; use xshell::{Shell, cmd}; -const LSP_SRC: &str = "./target/release/witcherscript-lsp"; -const LSP_DST: &str = "./editors/vscode/server/bin"; const EXT_DIR: &str = "./editors/vscode"; const VSIX_NAME: &str = "witcherscript-ide.vsix"; -pub fn package(out_dir: Option) -> anyhow::Result<()> { +pub fn package(out_dir: Option, out_name: Option) -> anyhow::Result<()> { let sh = Shell::new()?; // normalize the output path so it stays valid when we change cwd - let output_dir = if let Some(output_dir) = out_dir { - Some(PathBuf::from(&output_dir).canonicalize()?) + let out_dir = if let Some(out_dir) = out_dir { + // can't just use Option::map because of error propagation here + Some(PathBuf::from(&out_dir).canonicalize()?) } else { None }; - println!("Building LSP release..."); - cmd!(sh, "cargo build --package witcherscript-lsp --release").run()?; - - let lsp_src = if cfg!(unix) { - LSP_SRC.to_string() - } else { - format!("{LSP_SRC}.exe") - }; - - // make sure DST exists - sh.create_dir(LSP_DST)?; - - sh.copy_file(lsp_src, LSP_DST)?; - println!("Copied LSP into {}", LSP_DST); - - sh.change_dir(EXT_DIR); if cfg!(unix) { @@ -48,9 +31,8 @@ pub fn package(out_dir: Option) -> anyhow::Result<()> { cmd!(sh, "cmd.exe /c npm run package").run()?; } - let version = env!("CARGO_PKG_VERSION"); - let vsix_file = format!("witcherscript-ide-{version}.vsix"); - let vsix_dst = if let Some(output_dir) = output_dir { + let vsix_file = format!("{}.vsix", out_name.unwrap_or("witcherscript-ide".to_string())); + let vsix_dst = if let Some(output_dir) = out_dir { output_dir.join(vsix_file) } else { PathBuf::from(&vsix_file).canonicalize()? diff --git a/xtask/src/main.rs b/xtask/src/main.rs index f49ed2f1..83554a89 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -10,7 +10,7 @@ fn main() -> anyhow::Result<()> { match cli.command { cli::Commands::PrepLsp { release, target } => commands::prep_lsp(release, target), - cli::Commands::Package { out_dir } => commands::package(out_dir), + cli::Commands::Package { out_dir, out_name } => commands::package(out_dir, out_name), cli::Commands::Install => commands::install() } } \ No newline at end of file From 3dcc6b03b6c1eb13beea292bfa91bc2dc9c8bffe Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sat, 27 Jan 2024 23:56:43 +0100 Subject: [PATCH 12/12] ci/cd: refactor `draft-release` to reflect recent changes in xtask --- .github/workflows/draft-release.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index 10f6b5d0..259ef819 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -32,8 +32,12 @@ jobs: target: ${{ matrix.target }} override: true - - name: Pack the client - run: cargo xtask package --out-dir . + - name: Build xtask + run: cargo build --package xtask --target ${{ matrix.target }} --release + - name: Prepare and pack the client + run: | + cargo xtask prep-lsp --target ${{ matrix.target }} --release + cargo xtask package --out-dir . --out-name "witcherscript-ide-${{ github.ref_name }}-${{ matrix.target }}" - name: Create draft release uses: ncipollo/release-action@v1