Skip to content

Commit

Permalink
idea
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbhmr authored Aug 14, 2023
1 parent 909fff4 commit ba13c79
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/publish-feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Publish feature
on:
release:
types: published
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
publish-feature:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: devcontainers-community/publish-feature@v1
with:
collection: ghcr.io/devcontainers-community/features
33 changes: 33 additions & 0 deletions .github/workflows/test-feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test feature
on:
push:
branches: "main"
paths-ignore:
- .gitignore
- LICENSE
- README.md
- .github/**
- "!.github/workflows/test-feature.yml"
pull_request:
paths-ignore:
- .gitignore
- LICENSE
- README.md
- .github/**
- "!.github/workflows/test-feature.yml"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test-feature:
strategy:
fail-fast: false
matrix:
test-path:
- test/ubuntu.sh
- test/debian-slim.sh
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install -g @devcontainers/cli
- run: bash ${{ matrix.test-path }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
.cache

# Logs
logs
*.log
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Jacob Hummer
Copyright (c) 2023 Devcontainers community

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
# cmake
🍰 CMake @devcontainers feature
# CMake Dev Container Feature

🍰 Installs the CMake build tool

<div align="center">

<p>
<img width="600" src="https://i.imgur.com/hwiPvLS.png" />
</p>

<!-- prettier-ignore -->
[Docs](https://devcontainers.community/features-cmake/)
| [GitHub](https://github.com/devcontainers-community/features-cmake)
| [Feature collection](https://devcontainers.community/features/)

</div>

> CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice. The suite of CMake tools were created by Kitware in response to the need for a powerful, cross-platform build environment for open-source projects such as ITK and VTK.
&mdash; [CMake](https://cmake.org/)

## Usage

```json
// devcontainer.json
{
"features": {
"ghcr.io/devcontainers-community/features/cmake:1": {}
}
}
```

### Options

- **`version`:** Choose a specific version to install. The default is 'latest'. If specified, this should be a full 'X.Y.Z' version number.
22 changes: 22 additions & 0 deletions devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"id": "cmake",
"version": "0.1.0",
"name": "CMake",
"documentationURL": "https://devcontainers.community/features-cmake/",
"licenseURL": "https://github.com/devcontainers-community/features-cmake/blob/main/LICENSE",
"description": "🍰 Installs the CMake build tool",
"options": {
"version": {
"type": "string",
"default": "latest",
"proposals": [
"latest",
"3.27.2"
],
"description": "Choose a specific version to install. The default is 'latest'. If specified, this should be a full 'X.Y.Z' version number."
}
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
17 changes: 17 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -ex
source lib.sh

check_packages wget

find_version_from_git_tags VERSION https://github.com/cli/cli

pushd /tmp/cmake
wget "https://github.com/Kitware/CMake/releases/download/v$VERSION/cmake-$VERSION-linux-$(uname -m).sh"
chmod +x cmake-*.sh
./cmake-*.sh --prefix=/usr/local --skip-license
popd
rm -rf /tmp/cmake

# Clean up
rm -rf /var/lib/apt/lists/*
51 changes: 51 additions & 0 deletions lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

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

# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update
apt-get -y install --no-install-recommends "$@"
fi
}

# Figure out correct version of a three part version number is not passed
find_version_from_git_tags() {
local variable_name=$1
local requested_version=${!variable_name}
if [ "${requested_version}" = "none" ]; then return; fi
local repository=$2
local prefix=${3:-"tags/v"}
local separator=${4:-"."}
local last_part_optional=${5:-"false"}
if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then
local escaped_separator=${separator//./\\.}
local last_part
if [ "${last_part_optional}" = "true" ]; then
last_part="(${escaped_separator}[0-9]+)?"
else
last_part="${escaped_separator}[0-9]+"
fi
local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$"
local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)"
if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then
declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)"
else
set +e
declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
set -e
fi
fi
if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" > /dev/null 2>&1; then
echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
exit 1
fi
echo "${variable_name}=${!variable_name}"
}
16 changes: 16 additions & 0 deletions test/debian-slim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -ex

mkdir -p .cache/debian-slim/.devcontainer
cat <<<EOF > .cache/debian-slim/.devcontainer/devcontainer.json
{
"image": "debian-slim",
"features": {
"../..": {}
}
}
EOF

devcontainer up --workspace-folder .cache/debian-slim
devcontainer exec --workspace-folder .cache/debian-slim cmake --version
echo "TODO: Kill container after test"
16 changes: 16 additions & 0 deletions test/ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -ex

mkdir -p .cache/ubuntu/.devcontainer
cat <<<EOF > .cache/ubuntu/.devcontainer/devcontainer.json
{
"image": "ubuntu",
"features": {
"../..": {}
}
}
EOF

devcontainer up --workspace-folder .cache/ubuntu
devcontainer exec --workspace-folder .cache/ubuntu cmake --version
echo "TODO: Kill container after test"

0 comments on commit ba13c79

Please sign in to comment.