Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,41 @@ jobs:
- name: Test
shell: bash
run: ./test/bats/bin/bats ./test

integration-alpine:
needs: test
runs-on: ubuntu-latest
container: library/alpine:3
steps:
- name: Install dependencies
run: apk add jq openssl bash git
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Test
shell: bash
run: ./test/bats/bin/bats ./test
- name: Install something
shell: bash
run: ./gah install mikefarah/yq --unattended
- name: Test if yq was installed correctly
run: yq --version

integration-debian:
needs: test
runs-on: ubuntu-latest
container: library/debian:13-slim
steps:
- name: Install dependencies
run: apt-get update && apt-get install -y jq openssl curl git
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Test
run: ./test/bats/bin/bats ./test
- name: Install something
run: ./gah install mikefarah/yq --unattended
- name: Test if yq was installed correctly
run: yq --version
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,24 @@ Nowadays more and more command-line tools and applications are distributed via G
- 🗃 Has own base of predefined aliases for GitHub repositories (PRs are welcome!)
- 🔐 Verifies downloaded files using provided by `openssl` against [asset's digest value](https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#get-a-release-asset)

## Requirements

- `bash`
- `jq`
- `curl` or `wget`
- `tar`
- `unzip`
- `openssl`

## Installation

```bash
bash -c "$(curl -fsSL https://raw.githubusercontent.com/get-gah/gah/refs/heads/master/tools/install.sh)"
```
or
```bash
bash -c "$(wget -qO- https://raw.githubusercontent.com/get-gah/gah/refs/heads/master/tools/install.sh)"
```

## Usage

Expand Down
45 changes: 40 additions & 5 deletions gah
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,48 @@ function cleanup() {
fi
}

function http_get() {
local url="$1"
# if curl is available, use it, otherwise use wget.
if command -v curl >/dev/null 2>&1; then
curl -s "${GITHUB_AUTH_ARGS[@]}" "$url"
else
wget -q -O- "${GITHUB_AUTH_ARGS[@]}" "$url"
fi
}

function http_download() {
local url="$1"
local destination="$2"
local silent="$3"
local progress="$4"
# if curl is available, use it, otherwise use wget.
if command -v curl >/dev/null 2>&1; then
[[ $silent == "true" ]] && silent_option="-s" || silent_option=""
[[ $progress == "true" ]] && progress_option="--progress-bar" || progress_option=""
curl ${silent_option} -L ${progress_option} "${GITHUB_AUTH_ARGS[@]}" -o "$destination" "$url"
else
# detect if wget is from alpine/busybox or a GNU wget
if wget --version >/dev/null 2>&1; then
local is_gnu_wget="true"
else
local is_gnu_wget="false"
fi
local wget_progress_option
local silent_option
[[ $silent == "true" ]] && silent_option="-q" || silent_option=""
[[ $progress == "true" && $is_gnu_wget == "true" ]] && progress_option="--show-progress" || progress_option=""
wget ${silent_option} ${progress_option} "${GITHUB_AUTH_ARGS[@]}" -O "$destination" "$url"
fi
}

#endregion
#--------------------------------------------------
#region GitHub Authentication

# Setup GitHub authentication if GITHUB_PAT is provided
if [[ -n "${GITHUB_PAT:-}" ]]; then
GITHUB_AUTH_ARGS=(-H "Authorization: token ${GITHUB_PAT}")
GITHUB_AUTH_ARGS=(--header "Authorization: token ${GITHUB_PAT}")
print_green "Using GitHub Personal Access Token for API requests"
else
GITHUB_AUTH_ARGS=()
Expand Down Expand Up @@ -173,7 +208,7 @@ function fetch_release_info() {
local url=$(get_fetch_release_info_url "$1" "$2")
print_debug "Fetching release information from: $url"

curl -s "${GITHUB_AUTH_ARGS[@]}" "$url" > release.json
http_get "$url" > release.json

# Validate that we got a valid JSON response
if [[ ! -s release.json ]]; then
Expand Down Expand Up @@ -322,7 +357,7 @@ function verify_digest() {

function fetch_db() {
print_debug "Fetching DB"
curl -s "https://raw.githubusercontent.com/get-gah/gah-db/refs/heads/master/db.json" > "$GAH_DB_FILE"
http_get "https://raw.githubusercontent.com/get-gah/gah-db/refs/heads/master/db.json" > "$GAH_DB_FILE"
}

function get_db_path() {
Expand Down Expand Up @@ -443,7 +478,7 @@ function command_install() {

# Download the file
print_blue "Downloading: $filename"
curl -L --progress-bar -o "$filename" "$download_url"
http_download "$download_url" "$filename" true true

# Verify the download if digest is available
print_debug "Verifying download digest if available"
Expand Down Expand Up @@ -552,7 +587,7 @@ function command_update() {
fi

# Download gah! script
curl -sL https://raw.githubusercontent.com/$gah_repo/refs/tags/$tag/gah -o "$script_realpath"
http_download "https://raw.githubusercontent.com/$gah_repo/refs/tags/$tag/gah" "$script_realpath" true false
chmod +x "$script_realpath"
print_green "OK"

Expand Down
2 changes: 2 additions & 0 deletions test/02_github_api_functions.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "get_fetch_release_info_url should print the correct URL if no version is provided" {
Expand All @@ -43,6 +44,7 @@ teardown() {

@test "fetch_release_info should save the release info to a file" {
stub curl "-s * : cat '$DIR/test/fixtures/releases/argocd/release.json'"
stub wget "-q * : cat '$DIR/test/fixtures/releases/argocd/release.json'"

TEST_TEMP_DIR=$(mktemp -d)
cd "$TEST_TEMP_DIR"
Expand Down
5 changes: 5 additions & 0 deletions test/03_test_release__error.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "fetch_release_info should print an network error message if the release info cannot be fetched" {
stub curl "-s * : touch release.json"
stub wget "-q * : touch release.json"

TEST_TEMP_DIR=$(mktemp -d)
cd "$TEST_TEMP_DIR"
Expand All @@ -35,6 +37,7 @@ teardown() {

@test "fetch_release_info should print an json error message if the release info is not valid json" {
stub curl "-s * : echo 'not a json'"
stub wget "-q * : echo 'not a json'"

TEST_TEMP_DIR=$(mktemp -d)
cd "$TEST_TEMP_DIR"
Expand All @@ -48,6 +51,7 @@ teardown() {

@test "fetch_release_info should print an rate limit error message if the response indicates rate limiting" {
stub curl "-s * : cat '$DIR/test/fixtures/releases/_error/rate_limit_release.json'"
stub wget "-q * : cat '$DIR/test/fixtures/releases/_error/rate_limit_release.json'"

TEST_TEMP_DIR=$(mktemp -d)
cd "$TEST_TEMP_DIR"
Expand All @@ -65,6 +69,7 @@ teardown() {

@test "fetch_release_info should print an error message if the release info contains some other error" {
stub curl "-s * : cat '$DIR/test/fixtures/releases/_error/teapot_release.json'"
stub wget "-q * : cat '$DIR/test/fixtures/releases/_error/teapot_release.json'"

TEST_TEMP_DIR=$(mktemp -d)
cd "$TEST_TEMP_DIR"
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_age.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_argocd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_bottom.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_devbox.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_dive.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_duckdb.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_fd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_fx.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_fzf.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_gdu.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_genact.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_gh.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_git-sizer.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_goss.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_gping.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_helm.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_helmfile.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_jsonschema.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_k9s.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_kind.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_kops.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_lazydocker.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_lazygit.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
1 change: 1 addition & 0 deletions test/03_test_release_odin.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

unstub uname || true
unstub curl || true
unstub wget || true
}

@test "find_download_url should print match for the correct asset [linux/amd64]" {
Expand Down
Loading