Skip to content

Commit

Permalink
feat: publish cli binaries and add install script (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
lostbean authored Jul 8, 2024
1 parent 2be7f55 commit e1e27e4
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 2 deletions.
30 changes: 28 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
run: |
nix develop --command test -z $(gofmt -l .)
build_and_test_nix:
name: Test and build
build_publish_images:
name: Test, build and publish images
needs: check_nix
runs-on: ubuntu-22.04
steps:
Expand Down Expand Up @@ -83,3 +83,29 @@ jobs:
nix run ./#publish-kardinal-manager-container
nix run ./#publish-kardinal-cli-container
nix run ./#publish-redis-proxy-overlay-container
build_clis:
name: Test and build cross-compiled clis
needs: check_nix
runs-on: ubuntu-22.04
strategy:
matrix:
os: [linux, darwin, windows]
arch: [amd64, arm64]

steps:
- name: git checkout
uses: actions/checkout@v3

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

- name: Magic cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Build cli
run: |
path=$(nix build ./#cross-compiled-cli.x86_64-linux.${{ matrix.os }}.${{ matrix.arch }} --no-link --print-out-paths)
binout="/tmp/kardinal-${{ matrix.os }}-${{ matrix.arch }}"
ln -s $path/bin/${{ matrix.os }}_${{ matrix.arch }}/kardinal.cli $binout
ls -lah $binout
32 changes: 32 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ jobs:
release-please:
runs-on: ubuntu-latest
# skip releases on forks
outputs:
tag_name: ${{ steps.release.outputs.tag_name }}
release_created: ${{ steps.release.outputs.release_created }}
if: github.repository == 'kurtosis-tech/kardinal'
steps:
- name: Run Release Please
id: release
uses: googleapis/release-please-action@v3
with:
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
Expand All @@ -24,3 +28,31 @@ jobs:
bump-minor-pre-major: true
bump-patch-for-minor-pre-major: true
include-v-in-tag: false

build-and-publish-clis:
needs: release-please
runs-on: ubuntu-22.04
if: ${{ needs.release-please.outputs.release_created }}
strategy:
matrix:
os: [linux, darwin, windows]
arch: [amd64, arm64]

steps:
- name: git checkout
uses: actions/checkout@v3

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

- name: Magic cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Upload Release CLI Artifact
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
path=$(nix build ./#cross-compiled-cli.x86_64-linux.${{ matrix.os }}.${{ matrix.arch }} --no-link --print-out-paths)
binout="/tmp/kardinal-${{ matrix.os }}-${{ matrix.arch }}"
ln -s $path/bin/${{ matrix.os }}_${{ matrix.arch }}/kardinal.cli $binout
gh release upload ${{ needs.release-please.outputs.tag_name }} $binout
25 changes: 25 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,31 @@
in
pkgs.lib.foldl' (set: acc: pkgs.lib.recursiveUpdate acc set) {}
all;

cross-compiled-cli = let
all =
pkgs.lib.mapCartesianProduct ({
arch,
os,
}: {
"${os}" = {
"${toString arch}" = packages.kardinal-cli.overrideAttrs (old:
old
// {
GOOS = os;
GOARCH = arch;
# CGO_ENABLED = disabled breaks the CLI compilation
# CGO_ENABLED = 0;
doCheck = false;
});
};
}) {
arch = architectures;
os = ["linux" "darwin" "windows"];
};
in
pkgs.lib.foldl' (set: acc: pkgs.lib.recursiveUpdate acc set) {}
all;
};
# Add containers matching architecture with local system as toplevel packages
# this means calling `nix build .#<SERVICE_NAME>-container` will build the container matching the local system.
Expand Down
50 changes: 50 additions & 0 deletions scripts/install_cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

REPO="kurtosis-tech/kardinal"
BINARY_NAME="kardinal"

OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

if [[ "$ARCH" == "x86_64" ]]; then
ARCH="amd64"
elif [[ "$ARCH" == "arm64" ]]; then
ARCH="arm64"
elif [[ "$ARCH" == "aarch64" ]]; then
ARCH="arm64"
fi

LATEST_RELEASE=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_RELEASE/${BINARY_NAME}-${OS}-${ARCH}"
curl -L $DOWNLOAD_URL -o /tmp/${BINARY_NAME}

BIN_FOLDER="$HOME/.local/bin"
mkdir -p $BIN_FOLDER

mv /tmp/$BINARY_NAME $BIN_FOLDER/$BINARY_NAME

if [ -f $BIN_FOLDER/$BINARY_NAME ]; then
if [ -d /usr/share/bash-completion/completions ]; then
source $($BIN_FOLDER/$BINARY_NAME completion bash)
fi

if [ -d ~/.zsh/completions ]; then
source $($BIN_FOLDER/$BINARY_NAME completion zsh)
fi

if [ -d ~/.config/fish/completions ]; then
source $($BIN_FOLDER/$BINARY_NAME completion fish)
fi
fi

echo "$BINARY_NAME has been installed successfully!"

if ! command -v $BINARY_NAME &>/dev/null; then
echo "export PATH=\$PATH:$BIN_FOLDER" >>~/.bashrc
source ~/.bashrc
echo "export PATH=\$PATH:$BIN_FOLDER" >>~/.zshrc
source ~/.zshrc
echo "set -gx PATH \$PATH $BIN_FOLDER" >>~/.config/fish/config.fish
source ~/.config/fish/config.fish
fi

0 comments on commit e1e27e4

Please sign in to comment.