diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..2aaa800 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 + with: + severity: warning + - 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 }} diff --git a/commands/host/aljibe-assistant b/commands/host/aljibe-assistant index 2226cf3..43d3b9b 100755 --- a/commands/host/aljibe-assistant +++ b/commands/host/aljibe-assistant @@ -1,12 +1,18 @@ #!/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-project $AUTO ddev aljibe-create-symlinks echo -e "\e[30;48;5;2m Aljibe is now installed, you can access your site here:\e[0m" diff --git a/commands/host/aljibe-create-project b/commands/host/aljibe-create-project index 541da8b..b0c2c0f 100755 --- a/commands/host/aljibe-create-project +++ b/commands/host/aljibe-create-project @@ -1,5 +1,4 @@ #!/bin/bash - #ddev-generated ## Description: Create and configure a project. @@ -11,11 +10,15 @@ DRUSH_ALIASES_FOLDER="./drush/sites" CYAN='\033[0;36m' -MAGENTA='\033[0;35m' GREEN='\033[0;32m' NC='\033[0m' # No Color PROJECT_NAME=${DDEV_PROJECT} +if [ "$1" == "--auto" ]; then + AUTO=1 +else + AUTO=0 +fi # Process example files processExampleFile() { @@ -32,8 +35,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 @@ -74,8 +79,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 @@ -94,18 +104,24 @@ 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 fi } @@ -125,8 +141,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 '-' '_') diff --git a/commands/host/aljibe-create-symlinks b/commands/host/aljibe-create-symlinks index 0a75e8e..048555b 100755 --- a/commands/host/aljibe-create-symlinks +++ b/commands/host/aljibe-create-symlinks @@ -1,5 +1,4 @@ #!/bin/bash - #ddev-generated ## Description: Create symlinks to the scripts provided by Scripthor. @@ -18,7 +17,7 @@ createSymlinks() { if createScriptDir; then createScriptLink else - echo "./scripts directory not created." > `tty` + echo "./scripts directory not created." exit 1 fi } @@ -26,7 +25,7 @@ createSymlinks() { # Create script directory createScriptDir() { if [ ! -d $DIR ]; then - echo "./scripts directory created with 755 permissions." > `tty` + echo "./scripts directory created with 755 permissions." mkdir $DIR chmod 755 $DIR fi @@ -44,10 +43,10 @@ createScriptLink() { SCRIPT="$DIR/$FILE" if [ ! -f $SCRIPT ]; then ln -s $TARGET_DIR$FILE $SCRIPT - echo "Script created: $FILE" > `tty` + echo "Script created: $FILE" fi done } -echo "Creating symlinks..." > `tty` +echo "Creating symlinks..." createSymlinks \ No newline at end of file diff --git a/commands/host/aljibe-logo b/commands/host/aljibe-logo index 76fd950..22ffa5f 100644 --- a/commands/host/aljibe-logo +++ b/commands/host/aljibe-logo @@ -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 diff --git a/tests/test.bats b/tests/test.bats new file mode 100644 index 0000000..fd66581 --- /dev/null +++ b/tests/test.bats @@ -0,0 +1,37 @@ +setup() { + set -eu -o pipefail + export DIR + 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 +} diff --git a/tests/testdata/.gitmanaged b/tests/testdata/.gitmanaged new file mode 100644 index 0000000..e69de29