2022-05-28 04:41:47 +02:00
|
|
|
#!/usr/bin/env nu
|
|
|
|
|
|
|
|
# Created: 2022/05/26 19:05:20
|
|
|
|
# Description:
|
|
|
|
# A script to do the github release task, need nushell to be installed.
|
|
|
|
# REF:
|
|
|
|
# 1. https://github.com/volks73/cargo-wix
|
|
|
|
|
2022-12-01 03:18:28 +01:00
|
|
|
# Added 2022-11-29 when Windows packaging wouldn't work
|
|
|
|
# To run this manual for windows
|
2023-01-11 23:28:30 +01:00
|
|
|
# unset CARGO_TARGET_DIR if set
|
|
|
|
# hide-env CARGO_TARGET_DIR
|
2022-12-01 03:18:28 +01:00
|
|
|
# let-env TARGET = 'x86_64-pc-windows-msvc'
|
|
|
|
# let-env TARGET_RUSTFLAGS = ''
|
|
|
|
# let-env GITHUB_WORKSPACE = 'C:\Users\dschroeder\source\repos\forks\nushell'
|
2023-01-11 23:28:30 +01:00
|
|
|
# let-env GITHUB_OUTPUT = 'C:\Users\dschroeder\source\repos\forks\nushell\output\out.txt'
|
|
|
|
# let-env OS = 'windows-latest'
|
|
|
|
# You need to run this twice. The first pass makes the output folder and builds everything
|
|
|
|
# The second pass generates the msi file
|
2022-12-01 03:18:28 +01:00
|
|
|
# Pass 1 let-env _EXTRA_ = 'bin'
|
|
|
|
# Pass 2 let-env _EXTRA_ = 'msi'
|
|
|
|
# make sure 7z.exe is in your path https://www.7-zip.org/download.html
|
2023-01-11 23:28:30 +01:00
|
|
|
# let-env Path = ($env.Path | append 'c:\apps\7-zip')
|
2022-12-01 03:18:28 +01:00
|
|
|
# make sure aria2c.exe is in your path https://github.com/aria2/aria2
|
2023-01-11 23:28:30 +01:00
|
|
|
# let-env Path = ($env.Path | append 'c:\path\to\aria2c')
|
2022-12-01 03:18:28 +01:00
|
|
|
# make sure you have the wixtools installed https://wixtoolset.org/
|
2023-01-11 23:28:30 +01:00
|
|
|
# let-env Path = ($env.Path | append 'C:\Users\dschroeder\AppData\Local\tauri\WixTools')
|
|
|
|
# After msi is generated, if you have to update winget-pkgs repo, you'll need to patch the release
|
|
|
|
# by deleting the existing msi and uploading this new msi. Then you'll need to update the hash
|
|
|
|
# on the winget-pkgs PR. To generate the hash, run this command
|
|
|
|
# open target\wix\nu-0.74.0-x86_64-pc-windows-msvc.msi | hash sha256
|
|
|
|
# Then, just take the output and put it in the winget-pkgs PR for the hash on the msi
|
2022-12-01 03:18:28 +01:00
|
|
|
|
|
|
|
|
2022-05-28 04:41:47 +02:00
|
|
|
# The main binary file to be released
|
|
|
|
let bin = 'nu'
|
|
|
|
let os = $env.OS
|
|
|
|
let target = $env.TARGET
|
|
|
|
# Repo source dir like `/home/runner/work/nushell/nushell`
|
|
|
|
let src = $env.GITHUB_WORKSPACE
|
|
|
|
let flags = $env.TARGET_RUSTFLAGS
|
|
|
|
let dist = $'($env.GITHUB_WORKSPACE)/output'
|
|
|
|
let version = (open Cargo.toml | get package.version)
|
|
|
|
|
2022-12-01 03:44:21 +01:00
|
|
|
$'Debugging info:'
|
|
|
|
print { version: $version, bin: $bin, os: $os, target: $target, src: $src, flags: $flags, dist: $dist }; hr-line -b
|
|
|
|
|
2022-05-28 04:41:47 +02:00
|
|
|
# $env
|
|
|
|
|
2022-12-01 03:44:21 +01:00
|
|
|
let USE_UBUNTU = 'ubuntu-20.04'
|
|
|
|
|
2022-05-28 04:41:47 +02:00
|
|
|
$'(char nl)Packaging ($bin) v($version) for ($target) in ($src)...'; hr-line -b
|
|
|
|
if not ('Cargo.lock' | path exists) { cargo generate-lockfile }
|
|
|
|
|
|
|
|
$'Start building ($bin)...'; hr-line
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Build for Ubuntu and macOS
|
|
|
|
# ----------------------------------------------------------------------------
|
2022-12-01 03:44:21 +01:00
|
|
|
if $os in [$USE_UBUNTU, 'macos-latest'] {
|
|
|
|
if $os == $USE_UBUNTU {
|
2022-12-14 11:09:39 +01:00
|
|
|
sudo apt update
|
2022-05-28 04:41:47 +02:00
|
|
|
sudo apt-get install libxcb-composite0-dev -y
|
|
|
|
}
|
|
|
|
if $target == 'aarch64-unknown-linux-gnu' {
|
|
|
|
sudo apt-get install gcc-aarch64-linux-gnu -y
|
|
|
|
let-env CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = 'aarch64-linux-gnu-gcc'
|
|
|
|
cargo-build-nu $flags
|
|
|
|
} else if $target == 'armv7-unknown-linux-gnueabihf' {
|
|
|
|
sudo apt-get install pkg-config gcc-arm-linux-gnueabihf -y
|
|
|
|
let-env CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER = 'arm-linux-gnueabihf-gcc'
|
|
|
|
cargo-build-nu $flags
|
2022-12-14 11:09:39 +01:00
|
|
|
} else if $target == 'riscv64gc-unknown-linux-gnu' {
|
|
|
|
sudo apt-get install gcc-riscv64-linux-gnu -y
|
|
|
|
let-env CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER = 'riscv64-linux-gnu-gcc'
|
|
|
|
cargo-build-nu $flags
|
2022-05-28 04:41:47 +02:00
|
|
|
} else {
|
|
|
|
# musl-tools to fix 'Failed to find tool. Is `musl-gcc` installed?'
|
|
|
|
# Actually just for x86_64-unknown-linux-musl target
|
2022-12-01 03:44:21 +01:00
|
|
|
if $os == $USE_UBUNTU { sudo apt install musl-tools -y }
|
2022-05-28 04:41:47 +02:00
|
|
|
cargo-build-nu $flags
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Build for Windows without static-link-openssl feature
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
if $os in ['windows-latest'] {
|
2022-09-07 05:36:42 +02:00
|
|
|
if ($flags | str trim | is-empty) {
|
2022-11-23 01:58:11 +01:00
|
|
|
cargo build --release --all --target $target
|
2022-05-28 04:41:47 +02:00
|
|
|
} else {
|
2022-11-23 01:58:11 +01:00
|
|
|
cargo build --release --all --target $target $flags
|
2022-05-28 04:41:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Prepare for the release archive
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
let suffix = if $os == 'windows-latest' { '.exe' }
|
|
|
|
# nu, nu_plugin_* were all included
|
|
|
|
let executable = $'target/($target)/release/($bin)*($suffix)'
|
|
|
|
$'Current executable file: ($executable)'
|
|
|
|
|
|
|
|
cd $src; mkdir $dist;
|
|
|
|
rm -rf $'target/($target)/release/*.d' $'target/($target)/release/nu_pretty_hex*'
|
|
|
|
$'(char nl)All executable files:'; hr-line
|
|
|
|
ls -f $executable
|
|
|
|
|
|
|
|
$'(char nl)Copying release files...'; hr-line
|
|
|
|
cp -v README.release.txt $'($dist)/README.txt'
|
|
|
|
[LICENSE $executable] | each {|it| cp -rv $it $dist } | flatten
|
|
|
|
|
|
|
|
$'(char nl)Check binary release version detail:'; hr-line
|
|
|
|
let ver = if $os == 'windows-latest' {
|
2022-10-05 16:10:25 +02:00
|
|
|
(do -i { ./output/nu.exe -c 'version' }) | str join
|
2022-05-28 04:41:47 +02:00
|
|
|
} else {
|
2022-10-05 16:10:25 +02:00
|
|
|
(do -i { ./output/nu -c 'version' }) | str join
|
2022-05-28 04:41:47 +02:00
|
|
|
}
|
2022-09-07 05:36:42 +02:00
|
|
|
if ($ver | str trim | is-empty) {
|
2022-05-28 04:41:47 +02:00
|
|
|
$'(ansi r)Incompatible nu binary...(ansi reset)'
|
|
|
|
} else { $ver }
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Create a release archive and send it to output for the following steps
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
cd $dist; $'(char nl)Creating release archive...'; hr-line
|
2022-12-01 03:44:21 +01:00
|
|
|
if $os in [$USE_UBUNTU, 'macos-latest'] {
|
2022-05-28 04:41:47 +02:00
|
|
|
|
2022-10-22 18:39:11 +02:00
|
|
|
let files = (ls | get name)
|
|
|
|
let dest = $'($bin)-($version)-($target)'
|
|
|
|
let archive = $'($dist)/($dest).tar.gz'
|
2022-05-28 04:41:47 +02:00
|
|
|
|
2022-10-22 18:39:11 +02:00
|
|
|
mkdir $dest
|
|
|
|
$files | each {|it| mv $it $dest } | ignore
|
|
|
|
|
|
|
|
$'(char nl)(ansi g)Archive contents:(ansi reset)'; hr-line; ls $dest
|
|
|
|
|
|
|
|
tar -czf $archive $dest
|
2022-05-28 04:41:47 +02:00
|
|
|
print $'archive: ---> ($archive)'; ls $archive
|
2022-12-01 03:44:21 +01:00
|
|
|
# REF: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
|
|
|
|
echo $"archive=($archive)" | save --append $env.GITHUB_OUTPUT
|
2022-05-28 04:41:47 +02:00
|
|
|
|
|
|
|
} else if $os == 'windows-latest' {
|
|
|
|
|
|
|
|
let releaseStem = $'($bin)-($version)-($target)'
|
|
|
|
|
|
|
|
$'(char nl)Download less related stuffs...'; hr-line
|
2022-11-29 03:21:00 +01:00
|
|
|
aria2c https://github.com/jftuga/less-Windows/releases/download/less-v608/less.exe -o less.exe
|
2022-06-25 03:09:48 +02:00
|
|
|
aria2c https://raw.githubusercontent.com/jftuga/less-Windows/master/LICENSE -o LICENSE-for-less.txt
|
2022-05-28 04:41:47 +02:00
|
|
|
|
|
|
|
# Create Windows msi release package
|
|
|
|
if (get-env _EXTRA_) == 'msi' {
|
|
|
|
|
|
|
|
let wixRelease = $'($src)/target/wix/($releaseStem).msi'
|
|
|
|
$'(char nl)Start creating Windows msi package...'
|
|
|
|
cd $src; hr-line
|
|
|
|
# Wix need the binaries be stored in target/release/
|
|
|
|
cp -r $'($dist)/*' target/release/
|
2023-02-12 05:13:28 +01:00
|
|
|
cargo install cargo-wix --version 0.3.4
|
2022-05-28 04:41:47 +02:00
|
|
|
cargo wix --no-build --nocapture --package nu --output $wixRelease
|
2022-12-01 03:44:21 +01:00
|
|
|
print $'archive: ---> ($wixRelease)';
|
|
|
|
echo $"archive=($wixRelease)" | save --append $env.GITHUB_OUTPUT
|
2022-05-28 04:41:47 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$'(char nl)(ansi g)Archive contents:(ansi reset)'; hr-line; ls
|
|
|
|
let archive = $'($dist)/($releaseStem).zip'
|
|
|
|
7z a $archive *
|
|
|
|
print $'archive: ---> ($archive)';
|
|
|
|
let pkg = (ls -f $archive | get name)
|
2022-09-07 05:36:42 +02:00
|
|
|
if not ($pkg | is-empty) {
|
2022-12-01 03:44:21 +01:00
|
|
|
echo $"archive=($pkg | get 0)" | save --append $env.GITHUB_OUTPUT
|
2022-05-28 04:41:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def 'cargo-build-nu' [ options: string ] {
|
2022-09-07 05:36:42 +02:00
|
|
|
if ($options | str trim | is-empty) {
|
2022-11-23 01:58:11 +01:00
|
|
|
cargo build --release --all --target $target --features=static-link-openssl
|
2022-05-28 04:41:47 +02:00
|
|
|
} else {
|
2022-11-23 01:58:11 +01:00
|
|
|
cargo build --release --all --target $target --features=static-link-openssl $options
|
2022-05-28 04:41:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Print a horizontal line marker
|
|
|
|
def 'hr-line' [
|
|
|
|
--blank-line(-b): bool
|
|
|
|
] {
|
|
|
|
print $'(ansi g)---------------------------------------------------------------------------->(ansi reset)'
|
2022-08-20 02:05:58 +02:00
|
|
|
if $blank_line { char nl }
|
2022-05-28 04:41:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get the specified env key's value or ''
|
|
|
|
def 'get-env' [
|
|
|
|
key: string # The key to get it's env value
|
|
|
|
default: string = '' # The default value for an empty env
|
|
|
|
] {
|
|
|
|
$env | get -i $key | default $default
|
|
|
|
}
|