Skip to content

feat(dart): create Dart feature #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:
strategy:
matrix:
features:
# - color
# - hello
- dart
baseImage:
- debian:latest
- ubuntu:latest
Expand All @@ -34,8 +33,7 @@ jobs:
strategy:
matrix:
features:
# - color
# - hello
- dart
steps:
- uses: actions/checkout@v3

Expand Down
25 changes: 25 additions & 0 deletions src/dart/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- markdownlint-disable MD041 MD033 -->

<div align="center">

[![Dart website](https://thum.io/get/width/800/crop/600/noanimate/https://dart.dev/)](https://dart.dev/)

</div>

> Dart is a client-optimized language for fast apps on any platform

&mdash; [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! 🐛

<!-- prettier-ignore-start -->
[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
<!-- prettier-ignore-end -->
24 changes: 24 additions & 0 deletions src/dart/_common.sh
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions src/dart/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
20 changes: 20 additions & 0 deletions src/dart/install.sh
Original file line number Diff line number Diff line change
@@ -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"'
7 changes: 7 additions & 0 deletions test/dart/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e
source dev-container-features-test-lib

check 'dart' dart --version

reportResults