Skip to content

Commit

Permalink
Add flake for development, fix download url, new list-all script
Browse files Browse the repository at this point in the history
  • Loading branch information
pirackr committed Mar 2, 2024
1 parent 979220d commit 6a261e2
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 64 deletions.
34 changes: 0 additions & 34 deletions .circleci/config.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eval "$(lorri direnv)"
use flake
20 changes: 10 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ jobs:
run: |
echo "Trying to list all versions of telepresence"
asdf list all telepresence
echo "Will try to install telepresence 2.4.6"
asdf install telepresence 2.4.6
echo "Will try to install telepresence 2.4.7"
asdf install telepresence 2.4.7
echo "Setting telepresence version 2.4.6 as the default value in ~/.tool-versions"
echo 'telepresence 2.4.6' > ~/.tool-versions
telepresence version 2>&1 | grep '2.4.6'
echo "Setting telepresence version 2.4.7 as the default value in ~/.tool-versions"
echo 'telepresence 2.4.7' > ~/.tool-versions
telepresence version 2>&1 | grep '2.4.7'
echo "Will try to install telepresence 2.17.0"
asdf install telepresence 2.17.0
echo "Will try to install telepresence 2.18.0"
asdf install telepresence 2.18.0
echo "Setting telepresence version 2.17.0 as the default value in ~/.tool-versions"
echo 'telepresence 2.17.0' > ~/.tool-versions
telepresence version 2>&1 | grep '2.17.0'
echo "Setting telepresence version 2.18.0 as the default value in ~/.tool-versions"
echo 'telepresence 2.18.0' > ~/.tool-versions
telepresence version 2>&1 | grep '2.18.0'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.direnv/
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build](https://github.com/pirackr/asdf-telepresence/actions/workflows/build.yml/badge.svg)](https://github.com/pirackr/asdf-telepresence/actions/workflows/build.yml)

[Telepresence](https://www.telepresence.io/) plugin for [asdf](https://github.com/asdf-vm/asdf) version manager. Forked from [Kubectl plugin](github.com/asdf-community/asdf-kubectl).
[Telepresence](https://www.telepresence.io/) plugin for [asdf](https://github.com/asdf-vm/asdf) version manager. Forked from [Kubectl plugin](https://github.com/asdf-community/asdf-kubectl).

## Install

Expand All @@ -20,14 +20,14 @@ The `ASDF_TELEPRESENCE_OVERWRITE_ARCH` variable can be used to override the arch
### Without `ASDF_TELEPRESENCE_OVERWRITE_ARCH`:

```
% asdf install telepresence 2.4.10
Downloading telepresence from https://app.getambassador.io/download/tel2/linux/arm64/2.4.10/telepresence
% asdf install telepresence 2.18.0
Downloading teplepresence from url: https://app.getambassador.io/download/tel2oss/releases/download/v2.18.0/telepresence-linux-arm64
```

### With `ASDF_TELEPRESENCE_OVERWRITE_ARCH`:

```
% ASDF_TELEPRESENCE_OVERWRITE_ARCH=amd64 asdf install telepresence 2.4.10
Downloading telepresence from https://app.getambassador.io/download/tel2/linux/amd64/2.4.10/telepresence
% ASDF_TELEPRESENCE_OVERWRITE_ARCH=amd64 asdf install telepresence 2.18.0
Downloading teplepresence from url: https://app.getambassador.io/download/tel2oss/releases/download/v2.18.0/telepresence-linux-amd64
```

10 changes: 5 additions & 5 deletions bin/install
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash

set -e
set -o pipefail
set -eo pipefail

ASDF_INSTALL_TYPE=${ASDF_INSTALL_TYPE:-version }
[ -n "$ASDF_INSTALL_VERSION" ] || (echo >&2 'Missing ASDF_INSTALL_VERSION' && exit 1)
Expand All @@ -11,10 +9,12 @@ install_telepresence() {
local version=$2
local install_path=$3
local bin_install_path="$install_path/bin"
local bin_path="${bin_install_path}/telepresence"

mkdir -p "${bin_install_path}"

local bin_path="${bin_install_path}/telepresence"
echo "Downloading teplepresence from url: $(get_download_url "$version")"

if curl -Lksf "$(get_download_url "$version")" -o "$bin_path"; then
chmod +x "$bin_path"
else
Expand Down Expand Up @@ -42,7 +42,7 @@ get_cpu() {
}

get_download_url() {
echo "https://app.getambassador.io/download/tel2oss/releases/download/$1/telepresence-$(get_arch)-$(get_cpu)"
echo "https://app.getambassador.io/download/tel2oss/releases/download/v$1/telepresence-$(get_arch)-$(get_cpu)"
}

install_telepresence "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
26 changes: 16 additions & 10 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#!/usr/bin/env bash
set -eo pipefail

set -euo pipefail
cmd="curl --silent --location"
releases_path="https://api.github.com/repos/telepresenceio/telepresence/releases?per_page=100"

# stolen from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942
function sort_versions() {
if [ -n "$GITHUB_API_TOKEN" ]; then
cmd="$cmd --header 'Authorization: token $GITHUB_API_TOKEN'"
fi

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

list_all_versions() {
git ls-remote --tags --refs https://github.com/telepresenceio/telepresence.git |
grep -o 'refs/tags/.*' |
cut -d/ -f3- |
sed 's/^v//'
}
versions=$(
eval "$cmd $releases_path" |
grep -o '"name": "v.*' |
sed 's/"name": "v\(.*\)",/\1/' |
grep -E '[0-9]+.[0-9]+.[0-9]+$' |
xargs
)

list_all_versions | sort_versions | xargs echo
echo "$versions"
59 changes: 59 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
description = "my project description";

inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.asdf-vm
pkgs.shfmt
pkgs.shellcheck
];
};
}
);
}

10 changes: 10 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
buildInputs = [
pkgs.hello

# keep this line if you use bash
pkgs.bashInteractive
];
}

0 comments on commit 6a261e2

Please sign in to comment.