Skip to content

Commit

Permalink
Added basic tests and an auto option to the assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjol committed Aug 30, 2024
1 parent 5606adf commit 69774cc
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 25 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: tests
on:
pull_request:
push:
branches: [ main ]

schedule:
- cron: '00 07 * * *'

workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: Debug with tmate
required: false
default: false

# This is required for "gautamkrishnar/keepalive-workflow", see "ddev/github-action-add-on-test"
permissions:
actions: write

jobs:
tests:
strategy:
matrix:
ddev_version: [stable, HEAD]
fail-fast: false

runs-on: ubuntu-latest

steps:
- name: "Check out code"
uses: actions/checkout@v3
- name: "ShellChecker"
uses: a5k-actions/shellchecker@v0
severity: error

- uses: ddev/github-action-add-on-test@v2
with:
ddev_version: ${{ matrix.ddev_version }}
token: ${{ secrets.GITHUB_TOKEN }}
debug_enabled: ${{ github.event.inputs.debug_enabled }}
addon_repository: ${{ env.GITHUB_REPOSITORY }}
addon_ref: ${{ env.GITHUB_REF }}
8 changes: 7 additions & 1 deletion commands/host/aljibe-assistant
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/bin/bash

#ddev-generated

## Description: Launch project creation assistant.
## Usage: aljibe-assistant
## Example: "ddev aljibe-assistant"

if [ "$1" == "--auto" ]; then
AUTO=1
else
AUTO=0
fi

ddev aljibe-logo
ddev aljibe-create-project
ddev aljibe-create-symlinks
Expand Down
55 changes: 36 additions & 19 deletions commands/host/aljibe-create-project
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

#ddev-generated

## Description: Create and configure a project.
Expand Down Expand Up @@ -32,8 +31,10 @@ processExampleFile() {
setConfFiles() {
cd ${DDEV_APPROOT} || exit

echo -e "${CYAN}Please enter the project name (default to ${DDEV_PROJECT}):${NC}"
read PROJECT_NAME_INPUT
if [ "$AUTO" == "0" ]; then
echo -e "${CYAN}Please enter the project name (default to ${DDEV_PROJECT}):${NC}"
read PROJECT_NAME_INPUT
fi
echo "Configuring ddev environment"

if [ -z "$PROJECT_NAME_INPUT" ]; then
Expand Down Expand Up @@ -74,8 +75,13 @@ setConfFiles() {

# Setup git repo
setUpGit() {
echo -e "${CYAN}Do you want to initialize a git repository for your new project?${NC} [Y/n]"
read INITIALIZE_GIT
if [ "$AUTO" == "0" ]; then
echo -e "${CYAN}Do you want to initialize a git repository for your new project?${NC} [Y/n]"
read INITIALIZE_GIT
else
INITIALIZE_GIT="n"
fi

if [ "$INITIALIZE_GIT" != "n" ]; then
## Init with main branch
git init -b main
Expand All @@ -94,18 +100,25 @@ initGrumpPhp() {
}

installDrupal() {
echo -e "${CYAN}Do you want to install Drupal?${NC} [Y/n]"
read INSTALL_DRUPAL

if [ "$INSTALL_DRUPAL" != "n" ]; then
AVAILABLE_PROFILES=("minimal" "standard" "demo_umami")
echo -e "${CYAN}What install profile you want to install?${NC}"
select PROFILE in "${AVAILABLE_PROFILES[@]}"; do
echo "Installing profile $PROFILE"
ddev drush -y si $PROFILE
ddev drush cr
break
done
if [ "$AUTO" == "0" ]; then
echo -e "${CYAN}Do you want to install Drupal?${NC} [Y/n]"
read INSTALL_DRUPAL
if [ "$INSTALL_DRUPAL" != "n" ]; then
AVAILABLE_PROFILES=("minimal" "standard" "demo_umami")
echo -e "${CYAN}What install profile you want to install?${NC}"
select PROFILE in "${AVAILABLE_PROFILES[@]}"; do
echo "Installing profile $PROFILE"
ddev drush -y si $PROFILE
ddev drush cr
break
done
fi
else
PROFILE="standard"
echo "Installing profile $PROFILE"
ddev drush -y si $PROFILE
ddev drush cr
break
fi
}

Expand All @@ -125,8 +138,12 @@ createDirectories() {
}

createSubTheme() {
echo -e "${CYAN}Do you want to create a Radix sub-theme?${NC} [Y/n] "
read CREATE_SUB_THEME
if [ "$AUTO" == "0" ]; then
echo -e "${CYAN}Do you want to create a Radix sub-theme?${NC} [Y/n] "
read CREATE_SUB_THEME
else
CREATE_SUB_THEME="n"
fi

if [ "$CREATE_SUB_THEME" != "n" ]; then
DEFAULT_THEME_NAME=$(echo "${PROJECT_NAME}_radix" | tr '-' '_')
Expand Down
1 change: 0 additions & 1 deletion commands/host/aljibe-create-symlinks
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

#ddev-generated

## Description: Create symlinks to the scripts provided by Scripthor.
Expand Down
4 changes: 0 additions & 4 deletions commands/host/aljibe-logo
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/bin/bash

#ddev-generated

## Description: Show Aljibe logo.
## Usage: aljibe-logo
## Example: "ddev aljibe-logo"


#!/bin/bash

# ANSI color codes
brown='\033[0;33m'
NC='\033[0m' # No Color
Expand Down
36 changes: 36 additions & 0 deletions tests/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
setup() {
set -eu -o pipefail
export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
export TESTDIR=~/tmp/test-addon-aljibe-assistant
mkdir -p $TESTDIR
export PROJNAME=test-addon-aljibe-assistant
export DDEV_NON_INTERACTIVE=true
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true
cd "${TESTDIR}"
ddev config --project-name=${PROJNAME}
ddev start -y >/dev/null
}

teardown() {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR}
}

@test "install from directory" {
set -eu -o pipefail
cd ${TESTDIR}
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get ${DIR}
ddev restart
}

@test "install from release" {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
echo "# ddev get drud/test-addon-aljibe-assistant with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get drud/test-addon-aljibe-assistant
ddev restart >/dev/null
# Do something useful here that verifies the add-on
}
Empty file added tests/testdata/.gitmanaged
Empty file.

0 comments on commit 69774cc

Please sign in to comment.