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 authored Jul 12, 2024
2 parents 4bd5a63 + 5f09078 commit 7ca123c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
features:
- ghidra
- lib-common
- lib-github
baseImage:
- debian:latest
- ubuntu:latest
Expand All @@ -37,6 +38,7 @@ jobs:
- burp-suite
- ghidra
- lib-common
- lib-github
steps:
- uses: actions/checkout@v3

Expand Down
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": {}
}
}
39 changes: 39 additions & 0 deletions src/lib-github/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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"}

find /usr/share/phorcys-devcontainer-libraries/common

# Source lib-common feature
source "$BASE_DIR/common/1/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
12 changes: 12 additions & 0 deletions test/lib-github/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -euo pipefail

# Optional: Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

check "Library folder exists" test -d "/usr/share/phorcys-devcontainer-libraries/github"

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults

0 comments on commit 7ca123c

Please sign in to comment.