Skip to content

Commit

Permalink
feat: add lib-github feature
Browse files Browse the repository at this point in the history
  • Loading branch information
phorcys420 committed Jul 12, 2024
1 parent faeeceb commit b941e59
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib-github/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Library - GitHub",
"id": "lib-github",
"version": "1.0.0",
"description": "A feature that contains utilities to fetch releases from GitHub",
"keywords": ["library"],
"options": {
"baseDir": {
"type": "string",
"default": "/usr/share/phorcys-devcontainer-libraries",
"description": "Select the base directory where the library should be installed"
}
},

"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
],

"dependsOn": [
"ghcr.io/phorcys420/devcontainer-features/lib-common:1"
]
}
37 changes: 37 additions & 0 deletions src/lib-github/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

set -euo pipefail

FEATURE_NAME="github"
echo "Activating feature '$FEATURE_NAME'"

# Define the base directory where the feature libraries are stored
BASE_DIR=${BASEDIR:-"/usr/share/phorcys-devcontainer-libraries"}

# Source lib-common feature
source "$BASE_DIR/common/main.sh"

# Grab current feature version and split it in parts
VERSION=$(getFeatureVersion)
VERSION_PARTS=($(getVersionParts "$VERSION"))

# Define the installation directory for the current feature and the current feature version
FEATURE_DIR="$BASE_DIR/$FEATURE_NAME"
INSTALL_DIR="$FEATURE_DIR/$VERSION"

# Create directory for current feature version
echo "[$FEATURE_NAME] [+] Installing library to $INSTALL_DIR"
mkdir --parents "$INSTALL_DIR"
cp --recursive src/. "$INSTALL_DIR"

# Make links to each subversion (e.g if version is 1.0.0, then link to 1.0 and 1) and "current"
SUBFOLDERS=(
"${VERSION_PARTS[0]}.${VERSION_PARTS[1]}", # 1.0
"${VERSION_PARTS[0]}", # 1
"current"
)

for SUBFOLDER in "${SUBFOLDERS[@]}"
do
ln --symbolic --force "$INSTALL_DIR" "$FEATURE_DIR/$SUBFOLDER"
done
17 changes: 17 additions & 0 deletions src/lib-github/src/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

getRelease() {
REPOSITORY=$1
TAG=${2:-latest}

if [ $TAG = "latest" ]; then
RELEASE_API_URL="https://api.github.com/repos/$REPOSITORY/releases/latest"
else
RELEASE_API_URL="https://api.github.com/repos/$REPOSITORY/releases/tags/$TAG"
fi

curl "$RELEASE_API_URL" --silent --show-error
}

# Check for necessary packages
checkPackages curl jq

0 comments on commit b941e59

Please sign in to comment.