ci: Automatically build package files on release

Automatically builds packages for AUR, chocolatey, and homebrew on release.
This commit is contained in:
Clement Tsang 2020-08-18 20:22:50 -07:00 committed by GitHub
parent eb5ac54ad0
commit b2a00d49f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 240 additions and 4 deletions

View File

@ -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

View File

@ -6,6 +6,7 @@
"Mahmoud",
"Marcin",
"Nonexhaustive",
"PKGBUILD",
"Qudsi",
"Tebibytes",
"Ungrouped",

View File

@ -0,0 +1,23 @@
# Maintainer: Clement Tsang (xoronth) <cjhtsang@uwaterloo.ca>
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"
}

View File

@ -0,0 +1,24 @@
# Maintainer: Clement Tsang (xoronth) <cjhtsang@uwaterloo.ca>
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
}

View File

@ -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

43
deployment/packager.py Normal file
View File

@ -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)

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Read this before creating packages: https://chocolatey.org/docs/create-packages -->
<!-- It is especially important to read the above link to understand additional requirements when publishing packages to the community feed aka dot org (https://chocolatey.org/packages). -->
<!-- Test your packages in a test environment: https://github.com/chocolatey/chocolatey-test-environment -->
<!--
This is a nuspec. It mostly adheres to https://docs.nuget.org/create/Nuspec-Reference. Chocolatey uses a special version of NuGet.Core that allows us to do more than was initially possible. As such there are certain things to be aware of:
* the package xmlns schema url may cause issues with nuget.exe
* Any of the following elements can ONLY be used by choco tools - projectSourceUrl, docsUrl, mailingListUrl, bugTrackerUrl, packageSourceUrl, provides, conflicts, replaces
* nuget.exe can still install packages with those elements but they are ignored. Any authoring tools or commands will error on those elements
-->
<!-- You can embed software files directly into packages, as long as you are not bound by distribution rights. -->
<!-- * If you are an organization making private packages, you probably have no issues here -->
<!-- * If you are releasing to the community feed, you need to consider distribution rights. -->
<!-- Do not remove this test for UTF-8: if “Ω” doesnt appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one. -->
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<!-- == PACKAGE SPECIFIC SECTION == -->
<id>bottom</id>
<version>$version</version>
<!-- == SOFTWARE SPECIFIC SECTION == -->
<!-- This section is about the software itself -->
<title>bottom</title>
<authors>Clement Tsang</authors>
<projectUrl>https://github.com/ClementTsang/bottom</projectUrl>
<licenseUrl>https://github.com/ClementTsang/bottom/blob/master/LICENSE</licenseUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<projectSourceUrl>https://github.com/ClementTsang/bottom</projectSourceUrl>
<docsUrl>https://github.com/ClementTsang/bottom/blob/master/README.md</docsUrl>
<bugTrackerUrl>https://github.com/ClementTsang/bottom/issues</bugTrackerUrl>
<tags>cli cross-platform terminal top tui monitoring bottom btm</tags>
<summary>A cross-platform graphical process/system monitor with a customizable interface and a multitude of features.</summary>
<description>
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).
</description>
<releaseNotes>https://github.com/ClementTsang/bottom/releases/tag/0.4.3/</releaseNotes>
</metadata>
<files>
<!-- this section controls what actually gets packaged into the Chocolatey package -->
<file src="tools\**" target="tools" />
<!--Building from Linux? You may need this instead: <file src="tools/**" target="tools" />-->
</files>
</package>

View File

@ -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)

View File

@ -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