From b2a00d49f17b60ec5fcb68ca819d6e79f9c69014 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Tue, 18 Aug 2020 20:22:50 -0700 Subject: [PATCH] ci: Automatically build package files on release Automatically builds packages for AUR, chocolatey, and homebrew on release. --- .travis.yml | 18 +++++-- .vscode/settings.json | 1 + deployment/linux/arch/PKGBUILD.template | 23 ++++++++ deployment/linux/arch/PKGBUILD_BIN.template | 24 +++++++++ deployment/macos/homebrew/bottom.rb.template | 15 ++++++ deployment/packager.py | 43 +++++++++++++++ .../windows/choco/bottom.nuspec.template | 52 +++++++++++++++++++ deployment/windows/choco/choco_packager.py | 48 +++++++++++++++++ .../choco/chocolateyinstall.ps1.template | 20 +++++++ 9 files changed, 240 insertions(+), 4 deletions(-) create mode 100644 deployment/linux/arch/PKGBUILD.template create mode 100644 deployment/linux/arch/PKGBUILD_BIN.template create mode 100644 deployment/macos/homebrew/bottom.rb.template create mode 100644 deployment/packager.py create mode 100644 deployment/windows/choco/bottom.nuspec.template create mode 100644 deployment/windows/choco/choco_packager.py create mode 100644 deployment/windows/choco/chocolateyinstall.ps1.template diff --git a/.travis.yml b/.travis.yml index cd472ce2..d4efa297 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,6 @@ script: - cargo clippy -- -D clippy::all - cargo build --verbose --target $TARGET - cargo test --verbose --target $TARGET - - cargo install --path . --target $TARGET --locked --force before_cache: - rm -rf /home/travis/.cargo/git @@ -48,6 +47,7 @@ notifications: before_deploy: - | + cargo install --path . --target $TARGET --locked --force if [[ $TRAVIS_OS_NAME == "windows" ]]; then choco install zip; rustup target add x86_64-pc-windows-msvc; @@ -60,6 +60,8 @@ before_deploy: strip "./target/i686-pc-windows-msvc/release/btm"; mv "./target/i686-pc-windows-msvc/release/btm" "btm.exe"; zip bottom_i686-pc-windows-msvc.zip "btm.exe"; + python "./deployment/windows/choco/choco_packager.py" "bottom_i686-pc-windows-msvc.zip" "bottom_x86_64-pc-windows-msvc.zip" $TRAVIS_TAG; + zip choco.zip "./deployment/windows/choco/bottom.nuspec" "./deployment/windows/choco/tools/"; else cargo build --release; cp ./target/release/btm btm; @@ -67,11 +69,16 @@ before_deploy: if [[ $TRAVIS_OS_NAME == "linux" ]]; then tar -czvf bottom_x86_64-unknown-linux-gnu.tar.gz btm; tar -czvf bottom_required_files.tar.gz ./src ./Cargo.toml ./Cargo.lock LICENSE README.md; - cargo install cargo-deb; - cargo deb; - cp ./target/debian/bottom_*.deb .; + python "./deployment/packager.py" "./bottom_x86_64-unknown-linux-gnu.tar.gz" $TRAVIS_TAG "./deployment/linux/arch/PKGBUILD_BIN.template", "./PKGBUILD_BIN" "SHA512"; + python "./deployment/packager.py" "./bottom_required_files.tar.gz" $TRAVIS_TAG "./deployment/linux/arch/PKGBUILD.template", "./PKGBUILD" "SHA512"; + tar -czvf arch.tar.gz PKGBUILD_BIN PKGBUILD; + cargo install cargo-deb; + cargo deb; + cp ./target/debian/bottom_*.deb .; elif [[ $TRAVIS_OS_NAME == "osx" ]]; then tar -czvf bottom_x86_64-apple-darwin.tar.gz btm; + python "./deployment/packager.py" "./bottom_x86_64-apple-darwin.tar.gz" $TRAVIS_TAG "./deployment/macos/homebrew/bottom.rb.template", "./bottom.rb" "SHA256"; + tar -czvf homebrew.tar.gz bottom.rb; fi fi @@ -85,6 +92,9 @@ deploy: - bottom_*.tar.gz - bottom_*.zip - bottom_*.deb + - arch.tar.gz + - homebrew.tar.gz + - choco.zip skip_cleanup: true on: tags: true diff --git a/.vscode/settings.json b/.vscode/settings.json index dbc29940..5074ded4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "Mahmoud", "Marcin", "Nonexhaustive", + "PKGBUILD", "Qudsi", "Tebibytes", "Ungrouped", diff --git a/deployment/linux/arch/PKGBUILD.template b/deployment/linux/arch/PKGBUILD.template new file mode 100644 index 00000000..bf0b2298 --- /dev/null +++ b/deployment/linux/arch/PKGBUILD.template @@ -0,0 +1,23 @@ +# Maintainer: Clement Tsang (xoronth) + +pkgname=bottom +pkgver=$version +pkgrel=0 +pkgdesc="A cross-platform graphical process/system monitor with a customizable interface and a multitude of features." +provides=('bottom') +makedepends=('cargo') +arch=('x86_64') +url="https://github.com/ClementTsang/bottom" +source=("$pkgname-$pkgver.tar.gz::https://github.com/ClementTsang/bottom/releases/download/$pkgver/bottom_required_files.tar.gz") +license=('MIT') +sha512sums=('$hash') + +build() { + cargo build --release --locked +} + +package() { + install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/${pkgname}/LICENSE" + cd "./target/release" + install -Dm755 btm "$pkgdir/usr/bin/btm" +} \ No newline at end of file diff --git a/deployment/linux/arch/PKGBUILD_BIN.template b/deployment/linux/arch/PKGBUILD_BIN.template new file mode 100644 index 00000000..41580b48 --- /dev/null +++ b/deployment/linux/arch/PKGBUILD_BIN.template @@ -0,0 +1,24 @@ +# Maintainer: Clement Tsang (xoronth) + +pkgname=bottom-bin +pkgver=$version +pkgrel=0 +pkgdesc='A cross-platform graphical process/system monitor with a customizable interface and a multitude of features.' +provides=('bottom') +conflicts=('bottom') +arch=('x86_64') +url="https://github.com/ClementTsang/bottom" +license=(MIT) +source=( + archive-${pkgver}.tar.gz::${url}/releases/download/${pkgver}/bottom_x86_64-unknown-linux-gnu.tar.gz + LICENSE::${url}/raw/${pkgver}/LICENSE +) +sha512sums=( + '$hash' + SKIP +) + +package() { + install -Dm755 btm "$pkgdir"/usr/bin/btm + install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE +} diff --git a/deployment/macos/homebrew/bottom.rb.template b/deployment/macos/homebrew/bottom.rb.template new file mode 100644 index 00000000..b338c5f5 --- /dev/null +++ b/deployment/macos/homebrew/bottom.rb.template @@ -0,0 +1,15 @@ +class Bottom < Formula + desc "A cross-platform graphical process/system monitor with a customizable interface and a multitude of features." + homepage "https://github.com/ClementTsang/bottom" + url "https://github.com/ClementTsang/bottom/releases/download/$version/bottom_x86_64-apple-darwin.tar.gz" + sha256 "$hash" + version "$version" + + def install + bin.install "btm" + ohai "You're done! Run with \"btm\"" + ohai "For runtime flags, see \"btm --help\"" + ohai "If you want to configure bottom, by default bottom looks for a file in $HOME/.config/bottom/bottom.toml" + end + end + \ No newline at end of file diff --git a/deployment/packager.py b/deployment/packager.py new file mode 100644 index 00000000..ec167675 --- /dev/null +++ b/deployment/packager.py @@ -0,0 +1,43 @@ +import hashlib +import sys +from string import Template + +args = sys.argv +deployment_file_path = args[1] +version = args[2] +template_file_path = args[3] +generated_file_path = args[4] + +# SHA512, SHA256, or SHA1 +hash_type = args[5] + +print("Generating package for file: %s" % deployment_file_path) +print(" VERSION: %s" % version) +print(" TEMPLATE PATH: %s" % template_file_path) +print(" SAVING AT: %s" % generated_file_path) +print(" USING HASH TYPE: %s" % hash_type) + + +with open(deployment_file_path, "rb") as deployment_file: + if str.lower(hash_type) == "sha512": + deployment_hash = hashlib.sha512(deployment_file.read()).hexdigest() + elif str.lower(hash_type) == "sha256": + deployment_hash = hashlib.sha256(deployment_file.read()).hexdigest() + elif str.lower(hash_type) == "sha1": + deployment_hash = hashlib.sha1(deployment_file.read()).hexdigest() + else: + print('Unsupported hash format "%s". Please use SHA512, SHA256, or SHA1.', hash_type) + exit(1) + + print("Generated hash: ", deployment_hash) + + with open(template_file_path, "r") as template_file: + template = Template(template_file.read()) + substitute = template.safe_substitute(version=version, hash=deployment_hash) + print("\n================== Generated package file ==================\n") + print(substitute) + print("\n============================================================\n") + + with open(generated_file_path, "w") as generated_file: + generated_file.write(substitute) + diff --git a/deployment/windows/choco/bottom.nuspec.template b/deployment/windows/choco/bottom.nuspec.template new file mode 100644 index 00000000..acecb0ca --- /dev/null +++ b/deployment/windows/choco/bottom.nuspec.template @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + bottom + $version + + + + bottom + Clement Tsang + https://github.com/ClementTsang/bottom + https://github.com/ClementTsang/bottom/blob/master/LICENSE + true + https://github.com/ClementTsang/bottom + https://github.com/ClementTsang/bottom/blob/master/README.md + https://github.com/ClementTsang/bottom/issues + cli cross-platform terminal top tui monitoring bottom btm + A cross-platform graphical process/system monitor with a customizable interface and a multitude of features. + + A cross-platform graphical process/system monitor with a customizable interface and a multitude of features. Supports Linux, macOS, and Windows. Inspired by both [gtop](https://github.com/aksakalli/gtop) and [gotop](https://github.com/cjbassi/gotop). + + **Usage** + To use, run `btm` in a terminal. + + For more [documentation and usage](https://github.com/ClementTsang/bottom/blob/master/README.md), see the [official repo](https://github.com/ClementTsang/bottom). + + https://github.com/ClementTsang/bottom/releases/tag/0.4.3/ + + + + + + + diff --git a/deployment/windows/choco/choco_packager.py b/deployment/windows/choco/choco_packager.py new file mode 100644 index 00000000..0d4431a0 --- /dev/null +++ b/deployment/windows/choco/choco_packager.py @@ -0,0 +1,48 @@ +# Because choco is a special case and I'm too lazy to make my +# packaging script robust enough, so whatever, hard-code time. + +import hashlib +import sys +from string import Template +import os + +args = sys.argv +deployment_file_path_32 = args[1] +deployment_file_path_64 = args[2] +version = args[3] + +print("Generating Chocolatey package for:") +print(" 32-bit: %s", deployment_file_path_32) +print(" 64-bit: %s", deployment_file_path_64) +print(" VERSION: %s" % version) + +with open(deployment_file_path_32, "rb") as deployment_file_32, open( + deployment_file_path_64, "rb" +) as deployment_file_64: + hash_32 = hashlib.sha1(deployment_file_32.read()).hexdigest() + hash_64 = hashlib.sha1(deployment_file_64.read()).hexdigest() + + print("Generated 32 hash: ", hash_32) + print("Generated 64 hash: ", hash_64) + + with open("./bottom.nuspec.template", "r") as template_file: + template = Template(template_file.read()) + substitute = template.safe_substitute(version=version) + print("\n================== Generated nuspec file ==================\n") + print(substitute) + print("\n============================================================\n") + + with open("./bottom.nuspec", "w") as generated_file: + generated_file.write(substitute) + + os.makedirs("tools") + with open("./chocolateyinstall.ps1.template", "r") as template_file: + template = Template(template_file.read()) + substitute = template.safe_substitute(version=version, hash_32=hash_32, hash_64=hash_64) + print("\n================== Generated chocolateyinstall file ==================\n") + print(substitute) + print("\n============================================================\n") + + with open("./tools/chocolateyinstall.ps1", "w") as generated_file: + generated_file.write(substitute) + diff --git a/deployment/windows/choco/chocolateyinstall.ps1.template b/deployment/windows/choco/chocolateyinstall.ps1.template new file mode 100644 index 00000000..638d7281 --- /dev/null +++ b/deployment/windows/choco/chocolateyinstall.ps1.template @@ -0,0 +1,20 @@ +$ErrorActionPreference = 'Stop'; +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +$url = 'https://github.com/ClementTsang/bottom/releases/download/$version/bottom_i686-pc-windows-msvc.zip' +$url64 = 'https://github.com/ClementTsang/bottom/releases/download/$version/bottom_x86_64-pc-windows-msvc.zip' + +$packageArgs = @{ + packageName = $env:ChocolateyPackageName + softwareName = 'bottom' + unzipLocation = $toolsDir + fileType = 'exe' + url = $url + url64bit = $url64 + + checksum = '$hash_32' + checksumType = 'sha1' + checksum64 = '$hash_64' + checksumType64= 'sha1' + +} +Install-ChocolateyZipPackage @packageArgs