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
|
|
|
|
|
2023-02-23 15:19:13 +01:00
|
|
|
# Instructions for manually creating an MSI for Winget Releases when they fail
|
2022-12-01 03:18:28 +01:00
|
|
|
# Added 2022-11-29 when Windows packaging wouldn't work
|
2023-02-23 15:19:13 +01:00
|
|
|
# Updated again on 2023-02-23 because msis are still failing validation
|
|
|
|
# To run this manual for windows here are the steps I take
|
|
|
|
# checkout the release you want to publish
|
2023-10-18 23:04:59 +02:00
|
|
|
# 1. git checkout 0.86.0
|
2023-02-23 15:19:13 +01:00
|
|
|
# unset CARGO_TARGET_DIR if set (I have to do this in the parent shell to get it to work)
|
|
|
|
# 2. $env:CARGO_TARGET_DIR = ""
|
|
|
|
# 2. hide-env CARGO_TARGET_DIR
|
2023-06-30 21:57:51 +02:00
|
|
|
# 3. $env.TARGET = 'x86_64-pc-windows-msvc'
|
2024-05-20 19:22:08 +02:00
|
|
|
# 4. $env.GITHUB_WORKSPACE = 'D:\nushell'
|
|
|
|
# 5. $env.GITHUB_OUTPUT = 'D:\nushell\output\out.txt'
|
|
|
|
# 6. $env.OS = 'windows-latest'
|
2022-12-01 03:18:28 +01:00
|
|
|
# make sure 7z.exe is in your path https://www.7-zip.org/download.html
|
2024-05-20 19:22:08 +02:00
|
|
|
# 7. $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
|
2024-05-20 19:22:08 +02:00
|
|
|
# 8. $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/
|
2024-05-20 19:22:08 +02:00
|
|
|
# 9. $env.Path = ($env.Path | append 'C:\Users\dschroeder\AppData\Local\tauri\WixTools')
|
2023-02-23 15:19:13 +01:00
|
|
|
# You need to run the release-pkg twice. The first pass, with _EXTRA_ as 'bin', makes the output
|
|
|
|
# folder and builds everything. The second pass, that generates the msi file, with _EXTRA_ as 'msi'
|
2024-05-20 19:22:08 +02:00
|
|
|
# 10. $env._EXTRA_ = 'bin'
|
|
|
|
# 11. source .github\workflows\release-pkg.nu
|
|
|
|
# 12. cd ..
|
|
|
|
# 13. $env._EXTRA_ = 'msi'
|
|
|
|
# 14. source .github\workflows\release-pkg.nu
|
2023-02-23 15:19:13 +01:00
|
|
|
# After msi is generated, you have to update winget-pkgs repo, you'll need to patch the release
|
2023-01-11 23:28:30 +01:00
|
|
|
# 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
|
2024-05-20 19:22:08 +02:00
|
|
|
# 15. open target\wix\nu-0.74.0-x86_64-pc-windows-msvc.msi | hash sha256
|
2023-01-11 23:28:30 +01:00
|
|
|
# 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 dist = $'($env.GITHUB_WORKSPACE)/output'
|
|
|
|
let version = (open Cargo.toml | get package.version)
|
|
|
|
|
2023-04-10 22:10:41 +02:00
|
|
|
print $'Debugging info:'
|
2024-05-20 19:22:08 +02:00
|
|
|
print { version: $version, bin: $bin, os: $os, target: $target, src: $src, dist: $dist }; hr-line -b
|
2022-12-01 03:44:21 +01:00
|
|
|
|
2022-05-28 04:41:47 +02:00
|
|
|
# $env
|
|
|
|
|
2024-03-08 05:50:22 +01:00
|
|
|
let USE_UBUNTU = $os starts-with ubuntu
|
2022-12-01 03:44:21 +01:00
|
|
|
|
2023-04-10 22:10:41 +02:00
|
|
|
print $'(char nl)Packaging ($bin) v($version) for ($target) in ($src)...'; hr-line -b
|
2022-05-28 04:41:47 +02:00
|
|
|
if not ('Cargo.lock' | path exists) { cargo generate-lockfile }
|
|
|
|
|
2023-04-10 22:10:41 +02:00
|
|
|
print $'Start building ($bin)...'; hr-line
|
2022-05-28 04:41:47 +02:00
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Build for Ubuntu and macOS
|
|
|
|
# ----------------------------------------------------------------------------
|
2024-03-08 05:50:22 +01:00
|
|
|
if $os in ['macos-latest'] or $USE_UBUNTU {
|
|
|
|
if $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
|
|
|
|
}
|
2023-04-10 22:10:41 +02:00
|
|
|
match $target {
|
|
|
|
'aarch64-unknown-linux-gnu' => {
|
|
|
|
sudo apt-get install gcc-aarch64-linux-gnu -y
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = 'aarch64-linux-gnu-gcc'
|
2024-05-20 19:22:08 +02:00
|
|
|
cargo-build-nu
|
2023-04-10 22:10:41 +02:00
|
|
|
}
|
2023-06-12 04:40:18 +02:00
|
|
|
'riscv64gc-unknown-linux-gnu' => {
|
|
|
|
sudo apt-get install gcc-riscv64-linux-gnu -y
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER = 'riscv64-linux-gnu-gcc'
|
2024-05-20 19:22:08 +02:00
|
|
|
cargo-build-nu
|
2023-06-12 04:40:18 +02:00
|
|
|
}
|
|
|
|
'armv7-unknown-linux-gnueabihf' => {
|
|
|
|
sudo apt-get install pkg-config gcc-arm-linux-gnueabihf -y
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER = 'arm-linux-gnueabihf-gcc'
|
2024-05-20 19:22:08 +02:00
|
|
|
cargo-build-nu
|
2023-06-12 04:40:18 +02:00
|
|
|
}
|
2024-09-04 03:28:00 +02:00
|
|
|
'aarch64-unknown-linux-musl' => {
|
|
|
|
aria2c https://musl.cc/aarch64-linux-musl-cross.tgz
|
2024-09-13 16:03:31 +02:00
|
|
|
tar -xf aarch64-linux-musl-cross.tgz -C $env.HOME
|
|
|
|
$env.PATH = ($env.PATH | split row (char esep) | prepend $'($env.HOME)/aarch64-linux-musl-cross/bin')
|
2024-09-04 03:28:00 +02:00
|
|
|
$env.CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER = 'aarch64-linux-musl-gcc'
|
|
|
|
cargo-build-nu
|
|
|
|
}
|
|
|
|
'armv7-unknown-linux-musleabihf' => {
|
|
|
|
aria2c https://musl.cc/armv7r-linux-musleabihf-cross.tgz
|
2024-09-13 16:03:31 +02:00
|
|
|
tar -xf armv7r-linux-musleabihf-cross.tgz -C $env.HOME
|
|
|
|
$env.PATH = ($env.PATH | split row (char esep) | prepend $'($env.HOME)/armv7r-linux-musleabihf-cross/bin')
|
2024-09-04 03:28:00 +02:00
|
|
|
$env.CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER = 'armv7r-linux-musleabihf-gcc'
|
|
|
|
cargo-build-nu
|
|
|
|
}
|
2024-09-22 11:20:15 +02:00
|
|
|
'loongarch64-unknown-linux-gnu' => {
|
|
|
|
aria2c https://github.com/loongson/build-tools/releases/download/2024.08.08/x86_64-cross-tools-loongarch64-binutils_2.43-gcc_14.2.0-glibc_2.40.tar.xz
|
|
|
|
tar xf x86_64-cross-tools-loongarch64-*.tar.xz
|
|
|
|
$env.PATH = ($env.PATH | split row (char esep) | prepend $'($env.PWD)/cross-tools/bin')
|
|
|
|
$env.CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER = 'loongarch64-unknown-linux-gnu-gcc'
|
|
|
|
cargo-build-nu
|
|
|
|
}
|
2023-04-10 22:10:41 +02:00
|
|
|
_ => {
|
|
|
|
# musl-tools to fix 'Failed to find tool. Is `musl-gcc` installed?'
|
|
|
|
# Actually just for x86_64-unknown-linux-musl target
|
2024-03-08 05:50:22 +01:00
|
|
|
if $USE_UBUNTU { sudo apt install musl-tools -y }
|
2024-05-20 19:22:08 +02:00
|
|
|
cargo-build-nu
|
2023-04-10 22:10:41 +02:00
|
|
|
}
|
2022-05-28 04:41:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Build for Windows without static-link-openssl feature
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
if $os in ['windows-latest'] {
|
2024-05-20 19:22:08 +02:00
|
|
|
cargo-build-nu
|
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)'
|
2023-04-10 22:10:41 +02:00
|
|
|
print $'Current executable file: ($executable)'
|
2022-05-28 04:41:47 +02:00
|
|
|
|
|
|
|
cd $src; mkdir $dist;
|
2024-03-08 05:50:22 +01:00
|
|
|
rm -rf ...(glob $'target/($target)/release/*.d') ...(glob $'target/($target)/release/nu_pretty_hex*')
|
2023-04-10 22:10:41 +02:00
|
|
|
print $'(char nl)All executable files:'; hr-line
|
|
|
|
# We have to use `print` here to make sure the command output is displayed
|
2024-03-08 05:50:22 +01:00
|
|
|
print (ls -f ($executable | into glob)); sleep 1sec
|
2022-05-28 04:41:47 +02:00
|
|
|
|
2023-04-10 22:10:41 +02:00
|
|
|
print $'(char nl)Copying release files...'; hr-line
|
2024-04-30 09:42:21 +02:00
|
|
|
"To use the included Nushell plugins, register the binaries with the `plugin add` command to tell Nu where to find the plugin.
|
|
|
|
Then you can use `plugin use` to load the plugin into your session.
|
|
|
|
For example:
|
2023-05-20 14:57:51 +02:00
|
|
|
|
2024-04-30 09:42:21 +02:00
|
|
|
> plugin add ./nu_plugin_query
|
|
|
|
> plugin use query
|
|
|
|
|
|
|
|
For more information, refer to https://www.nushell.sh/book/plugins.html
|
|
|
|
" | save $'($dist)/README.txt' -f
|
2024-03-08 05:50:22 +01:00
|
|
|
[LICENSE ...(glob $executable)] | each {|it| cp -rv $it $dist } | flatten
|
2022-05-28 04:41:47 +02:00
|
|
|
|
2023-04-10 22:10:41 +02:00
|
|
|
print $'(char nl)Check binary release version detail:'; hr-line
|
2022-05-28 04:41:47 +02:00
|
|
|
let ver = if $os == 'windows-latest' {
|
2023-05-20 14:50:38 +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) {
|
2023-11-21 13:40:01 +01:00
|
|
|
print $'(ansi r)Incompatible Nu binary: The binary cross compiled is not runnable on current arch...(ansi reset)'
|
2023-04-10 22:10:41 +02:00
|
|
|
} else { print $ver }
|
2022-05-28 04:41:47 +02:00
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Create a release archive and send it to output for the following steps
|
|
|
|
# ----------------------------------------------------------------------------
|
2023-04-10 22:10:41 +02:00
|
|
|
cd $dist; print $'(char nl)Creating release archive...'; hr-line
|
2024-03-08 05:50:22 +01:00
|
|
|
if $os in ['macos-latest'] or $USE_UBUNTU {
|
2022-05-28 04:41:47 +02:00
|
|
|
|
2022-10-22 18:39:11 +02:00
|
|
|
let files = (ls | get name)
|
2024-05-20 19:22:08 +02:00
|
|
|
let dest = $'($bin)-($version)-($target)'
|
2022-10-22 18:39:11 +02:00
|
|
|
let archive = $'($dist)/($dest).tar.gz'
|
2022-05-28 04:41:47 +02:00
|
|
|
|
2022-10-22 18:39:11 +02:00
|
|
|
mkdir $dest
|
2024-03-08 07:36:08 +01:00
|
|
|
$files | each {|it| cp -v $it $dest }
|
2022-10-22 18:39:11 +02:00
|
|
|
|
2024-03-08 07:36:08 +01:00
|
|
|
print $'(char nl)(ansi g)Archive contents:(ansi reset)'; hr-line; ls $dest | print
|
2022-10-22 18:39:11 +02:00
|
|
|
|
|
|
|
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' {
|
|
|
|
|
2024-05-20 19:22:08 +02:00
|
|
|
let releaseStem = $'($bin)-($version)-($target)'
|
2022-05-28 04:41:47 +02:00
|
|
|
|
2023-04-10 22:10:41 +02:00
|
|
|
print $'(char nl)Download less related stuffs...'; hr-line
|
2024-07-25 15:50:59 +02:00
|
|
|
# todo: less-v661 is out but is released as a zip file. maybe we should switch to that and extract it?
|
2022-11-29 03:21:00 +01:00
|
|
|
aria2c https://github.com/jftuga/less-Windows/releases/download/less-v608/less.exe -o less.exe
|
2024-07-25 15:50:59 +02:00
|
|
|
# the below was renamed because it was failing to download for darren. it should work but it wasn't
|
|
|
|
# todo: maybe we should get rid of this aria2c dependency and just use http get?
|
|
|
|
#aria2c https://raw.githubusercontent.com/jftuga/less-Windows/master/LICENSE -o LICENSE-for-less.txt
|
|
|
|
aria2c https://github.com/jftuga/less-Windows/blob/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'
|
2024-03-08 05:50:22 +01:00
|
|
|
print $'(char nl)Start creating Windows msi package with the following contents...'
|
2022-05-28 04:41:47 +02:00
|
|
|
cd $src; hr-line
|
|
|
|
# Wix need the binaries be stored in target/release/
|
2024-03-08 05:50:22 +01:00
|
|
|
cp -r ($'($dist)/*' | into glob) target/release/
|
|
|
|
ls target/release/* | print
|
2024-05-02 00:31:16 +02:00
|
|
|
cargo install cargo-wix --version 0.3.8
|
2022-05-28 04:41:47 +02:00
|
|
|
cargo wix --no-build --nocapture --package nu --output $wixRelease
|
2023-09-12 15:05:55 +02:00
|
|
|
# Workaround for https://github.com/softprops/action-gh-release/issues/280
|
2023-10-08 13:12:46 +02:00
|
|
|
let archive = ($wixRelease | str replace --all '\' '/')
|
2023-09-12 15:05:55 +02:00
|
|
|
print $'archive: ---> ($archive)';
|
|
|
|
echo $"archive=($archive)" | save --append $env.GITHUB_OUTPUT
|
2022-05-28 04:41:47 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2024-03-09 04:00:33 +01:00
|
|
|
print $'(char nl)(ansi g)Archive contents:(ansi reset)'; hr-line; ls | print
|
2022-05-28 04:41:47 +02:00
|
|
|
let archive = $'($dist)/($releaseStem).zip'
|
2024-03-08 05:50:22 +01:00
|
|
|
7z a $archive ...(glob *)
|
2022-05-28 04:41:47 +02:00
|
|
|
let pkg = (ls -f $archive | get name)
|
2022-09-07 05:36:42 +02:00
|
|
|
if not ($pkg | is-empty) {
|
2023-09-12 15:05:55 +02:00
|
|
|
# Workaround for https://github.com/softprops/action-gh-release/issues/280
|
2023-10-08 13:12:46 +02:00
|
|
|
let archive = ($pkg | get 0 | str replace --all '\' '/')
|
2023-09-12 15:05:55 +02:00
|
|
|
print $'archive: ---> ($archive)'
|
|
|
|
echo $"archive=($archive)" | save --append $env.GITHUB_OUTPUT
|
2022-05-28 04:41:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-20 19:22:08 +02:00
|
|
|
def 'cargo-build-nu' [] {
|
|
|
|
if $os == 'windows-latest' {
|
|
|
|
cargo build --release --all --target $target
|
2022-05-28 04:41:47 +02:00
|
|
|
} else {
|
2024-05-20 19:22:08 +02:00
|
|
|
cargo build --release --all --target $target --features=static-link-openssl
|
2022-05-28 04:41:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Print a horizontal line marker
|
|
|
|
def 'hr-line' [
|
2023-10-18 23:03:21 +02:00
|
|
|
--blank-line(-b)
|
2022-05-28 04:41:47 +02:00
|
|
|
] {
|
|
|
|
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
|
|
|
|
}
|