Skip to content

Instantly share code, notes, and snippets.

@adamcstephens
Created June 24, 2022 15:26
Show Gist options
  • Save adamcstephens/ecfbac089e964dc3a62cc69347efc8fa to your computer and use it in GitHub Desktop.
Save adamcstephens/ecfbac089e964dc3a62cc69347efc8fa to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# generate aqua-registry package from github release.
# requires: curl, jq, fzf
if [ -z $2 ]; then
echo "Usage: $0 <repo_owner> <repo_name>"
exit 2
fi
REPO_OWNER=$1
REPO_NAME=$2
PKG=$REPO_OWNER/$REPO_NAME
PKG_FILE=pkgs/$PKG/pkg.yaml
REGISTRY_FILE=pkgs/$PKG/registry.yaml
if [ ! -d pkgs ]; then
echo "!! Must be run from root of aqua-registry repo"
fi
if [ -e $PKG_FILE ] || [ -e $REGISTRY_FILE ]; then
echo "!! registry files for $PKG already exist"
exit 2
fi
for exec in curl fzf jq; do
if ! command -v $exec >/dev/null; then
echo "!! Missing required dependency: $exec"
exit 2
fi
done
RELEASES=$(curl -sH "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases)
DESCRIPTION=$(curl -sH "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME} | jq -r .description)
ASSETS=$(echo "$RELEASES" | jq -r '.[0].assets[] | .name')
PRIMARY_ASSET=$(echo "$ASSETS" | fzf --header "Select asset for registry config")
PRIMARY_RELEASE=$(echo "$RELEASES" | jq -r '.[] | .tag_name' | fzf --header "Select version for pkg config")
# echo $PRIMARY_ASSET
mkdir -vp "$(dirname $PKG_FILE)"
cat <<EOF >$REGISTRY_FILE
https://github.com/${REPO_OWNER}/${REPO_NAME}
https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/${PRIMARY_RELEASE}
~~~
# discovered assets:
$(echo "$ASSETS" | sed -re 's/^/# - /')
~~~
packages:
- type: github_release
repo_owner: $REPO_OWNER
repo_name: $REPO_NAME
description: $DESCRIPTION
asset: '$PRIMARY_ASSET'
format: tar.gz
# format_overrides:
# - goos: windows
# format: zip
# replacements:
# amd64: x86_64
# arm64: aarch64
# darwin: apple-darwin
# linux: unknown-linux-musl
# windows: pc-windows-msvc
# 386: i686
# files:
# - name: dust
# src: 'dust-{{.Version}}-{{.Arch}}-{{.OS}}/dust'
EOF
echo ":: Wrote $REGISTRY_FILE"
cat <<-EOF >$PKG_FILE
packages:
- name: $PKG@$PRIMARY_RELEASE
EOF
echo ":: Wrote $PKG_FILE"
if [ ! -e aqua.yaml ]; then
echo ":: Writing local aqua.yaml for testing"
cp aqua.yaml.tmpl aqua.yaml
else
echo ":: Appending local aqua.yaml for testing"
fi
cat $PKG_FILE | grep -v 'packages:' >>aqua.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment