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
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- gcc
# skipping zephyr-dev due to hard requirement of an existing west-workspace
# - zephyr-dev
- prek
baseImage:
- debian:latest
- ubuntu:latest
Expand All @@ -46,6 +47,7 @@ jobs:
- ceedling
# - gcc
- zephyr-dev
- prek
steps:
- uses: actions/checkout@v4

Expand Down
22 changes: 22 additions & 0 deletions src/prek/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# prek (Pre-Commit Check Tool)

prek

## Example Usage

```json
"features": {
"ghcr.io/DojoFive/embedops-features/prek:1": {}
}
```

## Options

| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| prek-version | Select or enter the prek Version | string | latest |

---

_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/DojoFive/embedops-features/blob/main/src/zephyr-dev/devcontainer-feature.json). Add additional notes to a `NOTES.md`._
21 changes: 21 additions & 0 deletions src/prek/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "prek",
"id": "prek",
"version": "1.0.0",
"description": "prek",
"options": {
"prek-version": {
"type": "string",
"proposals": [
"latest",
"v0.2.22"
],
"default": "latest",
"description": "Select or enter the Prek Version"
},
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils",
"ghcr.io/devcontainers/features/docker-in-docker"
]
}
114 changes: 114 additions & 0 deletions src/prek/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env bash
set -x

export DEBIAN_FRONTEND=noninteractive
# Load system info, including OS type
. /etc/os-release

# Determine base Linux distribution
if [[ "${ID}" = "debian" || "${ID_LIKE}" = "debian" ]]; then
ADJUSTED_ID="debian"
elif [ "${ID}" = "alpine" ]; then
ADJUSTED_ID="alpine"
else
echo "Linux distro ${ID} not supported."
exit 1
fi

if type apt-get > /dev/null 2>&1; then
INSTALL_CMD=apt-get
elif type apk > /dev/null 2>&1; then
INSTALL_CMD=apk
elif type microdnf > /dev/null 2>&1; then
INSTALL_CMD=microdnf
elif type dnf > /dev/null 2>&1; then
INSTALL_CMD=dnf
elif type yum > /dev/null 2>&1; then
INSTALL_CMD=yum
else
echo "(Error) Unable to find a supported package manager."
exit 1
fi

pkg_mgr_update() {
if [ ${INSTALL_CMD} = "apt-get" ]; then
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
${INSTALL_CMD} update -y
fi
elif [ ${INSTALL_CMD} = "apk" ]; then
if [ "$(find /var/cache/apk/* | wc -l)" = "0" ]; then
echo "Running apk update..."
${INSTALL_CMD} update
fi
fi
}

check_packages() {
if [ ${INSTALL_CMD} = "apt-get" ]; then
if ! dpkg -s "$@" > /dev/null 2>&1; then
pkg_mgr_update
${INSTALL_CMD} -y install --no-install-recommends "$@"
fi
elif [ ${INSTALL_CMD} = "apk" ]; then
${INSTALL_CMD} add \
--no-cache \
"$@"
else
echo "Linux distro ${ID} not supported."
exit 1
fi
}

clean_up() {
case $ADJUSTED_ID in
debian)
rm -rf /var/lib/apt/lists/*
;;
alpine)
rm -rf /var/cache/apk/*
;;
esac
}

install_dependencies() {
echo "Installing dependencies for ${ADJUSTED_ID}..."

check_packages curl jq ca-certificates
}

install_prek() {
echo "Installing prek..."

# Check if PREK_VERSION is set, otherwise exit
if [[ -z "${PREK_VERSION}" ]]; then
echo "Error: PREK_VERSION is not set. Please provide the version as a feature variable."
exit 1
fi

if [[ "${PREK_VERSION}" = "latest" ]]; then
PREK_VERSION=$(\
curl -Lf -H "Accept: application/vnd.github+json" "https://api.github.com/repos/j178/prek/releases?per_page=1" | jq -r '.[0].tag_name'\
)
fi

local SDK_URL="https://github.com/j178/prek/releases/download/${PREK_VERSION}/prek-installer.sh"
export PREK_INSTALL_DIR=/usr/bin

curl --proto '=https' --tlsv1.2 -LsSfo prek-installer.sh ${SDK_URL} || { echo "Error: Failed to get prek installer."; exit 1; }
sh prek-installer.sh || { echo "Error: Failed to install prek."; exit 1; }

rm prek-installer.sh
}

main() {
echo "Starting prek installation process..."
pkg_mgr_update
install_dependencies
install_prek

echo "prek installation process completed successfully."
clean_up
}

main
23 changes: 23 additions & 0 deletions test/prek/alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# This test file will be executed against an auto-generated devcontainer.json that
# includes the 'hello' Feature with no options.
#
# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md
#

set -e

# Optional: Import test library bundled with the devcontainer CLI
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
# Provides the 'check' and 'reportResults' commands.
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
# check <LABEL> <cmd> [args...]
check "execute command" bash -c "prek --version | grep 'prek'"

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
15 changes: 15 additions & 0 deletions test/prek/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"ubuntu": {
"image": "ubuntu:latest",
"features": {
"prek": {}
}
},
"alpine": {
"image": "alpine:latest",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
"prek": {}
}
}
}
23 changes: 23 additions & 0 deletions test/prek/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# This test file will be executed against an auto-generated devcontainer.json that
# includes the 'hello' Feature with no options.
#
# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md
#

set -e

# Optional: Import test library bundled with the devcontainer CLI
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
# Provides the 'check' and 'reportResults' commands.
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
# check <LABEL> <cmd> [args...]
check "execute command" bash -c "/usr/bin/prek --version | grep 'prek'"

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
23 changes: 23 additions & 0 deletions test/prek/ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# This test file will be executed against an auto-generated devcontainer.json that
# includes the 'hello' Feature with no options.
#
# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md
#

set -e

# Optional: Import test library bundled with the devcontainer CLI
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
# Provides the 'check' and 'reportResults' commands.
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
# check <LABEL> <cmd> [args...]
check "execute command" bash -c "prek --version | grep 'prek'"

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