-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This new command creates convenient subshells with appropriate environment variables set to run tests for _one_ plugin at a time.
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env bash | ||
args=("$@") | ||
plugin_name=${args[0]} | ||
|
||
YELLOW='\033[33m' | ||
RESET='\033[0m' # No Color | ||
|
||
if [ -z "$plugin_name" ]; then | ||
echo "Usage: ./plugin-env <plugin_name>" | ||
echo " <plugin_name> is the name of the dd-trace plugin to enter the dev environment for." | ||
echo "" | ||
echo " It can be one of the following:" | ||
node - << EOF | ||
const fs=require('fs'); | ||
const yaml = require('yaml'); | ||
const pluginsData = fs.readFileSync('.github/workflows/plugins.yml', 'utf8'); | ||
const env=Object.keys(yaml.parse(pluginsData).jobs); | ||
console.log(...env); | ||
EOF | ||
exit 1 | ||
fi | ||
|
||
if ! hash node 2>/dev/null; then | ||
echo "Node.js is not installed. Please install Node.js before running this script." | ||
echo "You can use nvm to install Node.js. See https://nvm.sh for more information." | ||
echo "For best results, use the latest version of Node.js." | ||
exit 1 | ||
fi | ||
|
||
if ! hash yarn 2>/dev/null; then | ||
echo "[email protected] is not installed. Please install [email protected] before running this script." | ||
echo "You can install yarn by running 'npm install -g yarn'." | ||
exit 1 | ||
fi | ||
|
||
read -r PLUGINS SERVICES <<<$(node - << EOF | ||
const fs=require('fs'); | ||
const yaml = require('yaml'); | ||
const pluginsData = fs.readFileSync('.github/workflows/plugins.yml', 'utf8'); | ||
const { PLUGINS, SERVICES } = yaml.parse(pluginsData).jobs['$plugin_name'].env; | ||
console.log(PLUGINS || '', SERVICES || '') | ||
EOF | ||
) | ||
|
||
export PLUGINS | ||
export SERVICES | ||
|
||
if [ -z "$SERVICES" ]; then | ||
echo "The plugin '$plugin_name' does not have any services defined. Nothing to do here." | ||
else | ||
if ! hash docker 2>/dev/null; then | ||
echo "Docker is not installed. Please install Docker before running this script." | ||
echo "You can install Docker by following the instructions at https://docs.docker.com/get-docker/." | ||
exit 1 | ||
fi | ||
if (! docker stats --no-stream >/dev/null); then | ||
echo "The docker daemon is not running. Please start Docker before running this script." | ||
exit 1 | ||
fi | ||
if [ -z `docker ps -q --no-trunc | grep $(docker-compose ps -q $SERVICES)` ]; then | ||
teardown=1 | ||
docker compose up -d $SERVICES | ||
fi | ||
fi | ||
|
||
yarn services | ||
|
||
echo -e $YELLOW | ||
echo -e "You are now in a sub-shell (i.e. a dev environment) for the dd-trace plugin '$plugin_name'." | ||
echo -e "The following environment variables set:${RESET}" | ||
echo -e "\tPLUGINS=$PLUGINS" | ||
echo -e "\tSERVICES=$SERVICES" | ||
echo -e "${YELLOW}The ${RESET}versions${YELLOW} directory has been populated, and any ${RESET}\$SERVICES${YELLOW} have been brought up if not already running." | ||
echo -e "You can now run the plugin's tests with:" | ||
echo -e "\t${RESET}yarn test:plugins" | ||
echo -e "${YELLOW}To exit this shell, type 'exit' or do Ctrl+D." | ||
echo -e $RESET | ||
|
||
$SHELL | ||
|
||
if [ -n "$teardown" ]; then | ||
docker compose stop $SERVICES | ||
fi | ||
|
||
echo -e $YELLOW | ||
echo "Exited the sub-shell for the dd-trace plugin '$plugin_name'." | ||
if [ -n "$teardown" ]; then | ||
echo "Also stopped any services that were started." | ||
fi | ||
echo "You're now back in the main shell." | ||
echo -e $RESET |