diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc9d869..475b0ad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,8 +13,7 @@ jobs: strategy: matrix: features: - # - color - # - hello + - dart baseImage: - debian:latest - ubuntu:latest @@ -34,8 +33,7 @@ jobs: strategy: matrix: features: - # - color - # - hello + - dart steps: - uses: actions/checkout@v3 diff --git a/src/dart/NOTES.md b/src/dart/NOTES.md new file mode 100644 index 0000000..3498020 --- /dev/null +++ b/src/dart/NOTES.md @@ -0,0 +1,25 @@ + + +
+ +[![Dart website](https://thum.io/get/width/800/crop/600/noanimate/https://dart.dev/)](https://dart.dev/) + +
+ +> Dart is a client-optimized language for fast apps on any platform + +— [Dart programming language | Dart] + +This feature installs the Dart SDK using the official installer script. You can +choose to pin a specific version with the `version` input. You might also want +to check out [Flutter] if you're interested in Dart. + +🆘 If you're having trouble with this feature, [open a Discussion] or [open an +Issue]! We'd be happy to fix bugs! 🐛 + + +[Dart programming language | Dart]: https://dart.dev/ +[Flutter]: https://flutter.dev/ +[open a Discussion]: https://github.com/devcontainers-community/features/discussions/new?category=q-a +[open an Issue]: https://github.com/devcontainers-community/features/issues/new + diff --git a/src/dart/_common.sh b/src/dart/_common.sh new file mode 100644 index 0000000..2a3b009 --- /dev/null +++ b/src/dart/_common.sh @@ -0,0 +1,24 @@ +updaterc() { + echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..." + if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then + echo -e "$1" >> /etc/bash.bashrc + fi + if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then + echo -e "$1" >> /etc/zsh/zshrc + fi +} + +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 +} diff --git a/src/dart/devcontainer-feature.json b/src/dart/devcontainer-feature.json new file mode 100644 index 0000000..3e8e963 --- /dev/null +++ b/src/dart/devcontainer-feature.json @@ -0,0 +1,18 @@ +{ + "id": "dart", + "name": "Dart", + "description": "Installs the Dart SDK", + "version": "1.0.0", + "options": { + "version": { + "description": "Dart version", + "type": "string", + "default": "latest" + } + }, + "customizations": { + "vscode": { + "extensions": ["dart-code.dart-code"] + } + } +} diff --git a/src/dart/install.sh b/src/dart/install.sh new file mode 100644 index 0000000..47e8ceb --- /dev/null +++ b/src/dart/install.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e +source _common.sh + +check_packages wget gpg apt-transport-https ca-certificates + +# https://dart.dev/get-dart +wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/dart.gpg +echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | tee /etc/apt/sources.list.d/dart_stable.list + +apt-get update +if [[ -z $VERSION || $VERSION == latest ]]; then + apt-get install dart +else + apt-get install "dart=$VERSION" +fi + +# Now that we have Dart installed to /usr/lib/dart/bin, we need to expose that +# to future shell sessions via $PATH. +updaterc 'export PATH="$PATH:/usr/lib/dart/bin"' diff --git a/test/dart/test.sh b/test/dart/test.sh new file mode 100644 index 0000000..38cfc95 --- /dev/null +++ b/test/dart/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e +source dev-container-features-test-lib + +check 'dart' dart --version + +reportResults