Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bserem committed Sep 23, 2024
0 parents commit d90748d
Show file tree
Hide file tree
Showing 14 changed files with 520 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: tests
on:
pull_request:
push:
branches: [ main ]

schedule:
- cron: '25 08 * * *'

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

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# 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:
- 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 }}
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# DDEV Annertech Tools

Highly opinionated.

## What it does:

- Provides commands:
- - robo
- - behat
- - login
- Adds actions on DDEV hooks
- Adds custom settings.local.php file on project start
84 changes: 84 additions & 0 deletions commands/host/branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env python3

## Description: Create a git branch from a trello url
## Usage: branch
## Example: ddev branch

# Given a Trello url, and optional name, creates a new branch
#
# Prompts for a Trello url, and then for an optional branch name. Given the
# following url and string:
#
# - https://trello.com/c/xxK4l2eP/31-region-footer
# - qa_rework
#
# the script will create a git branch with the following name:
#
# 2019_w37_31_region_footer_xxK4l2eP__qa_rework
#
# Where:
#
# - 2019 is the year
# - w37 is the current week
# - 31_region_footer_xxK4l2eP is the Trello card identifier
# - qa_rework is the branch name provided
#

import datetime, re, subprocess, sys, getopt


def main(argv):
trello = ''
name = ''

if len(argv) == 0:
trello = input("Please enter the Trello url: ")
name = input("Please enter a branch name (optional): ")
suffix = ""
elif len(argv) == 1 and ('trello' in argv[0]):
trello = argv[0]
else:
try:
opts, args = getopt.getopt(argv, "u:b:", ['url=', 'branch='])
except getopt.GetoptError as err:
print(err)
print("fin branch -u TRELLO_URL [-b BRANCH_NAME]")
sys.exit(2)
for opt, arg in opts:
if opt in ("-u", "--url"):
trello = arg
elif opt in ("-b", "--branch"):
name = arg
try:
""" Make sure this looks like part of a Trello path. """
path = trelloPath(trello)

""" If we got a name, ensure it's composed of acceptable characters. """
if name != None:
suffix = re.fullmatch(r'[a-zA-Z0-9_-]+', name)

""" Proceed if we we got a match. """
if path != None:
parts = path.group(1).split("/")
today = datetime.date.today()
name = re.sub(r'-', '_', parts[1])
hash = parts[0]
branch = "{}_w{}_{}_{}".format(
today.year, today.isocalendar()[1], name, hash)

""" If we were able to match a suffix, append it now. """
if suffix != None:
branch = "{}__{}".format(branch, suffix.group(0))

""" Check out a branch with the new name. """
subprocess.run(["git", "checkout", "-b", branch])
else:
raise ValueError

except ValueError:
print("The argument did not match the expected pattern.")

def trelloPath(test_url):
return re.fullmatch(r'https:\/\/trello.com\/[a-zA-Z]{1}\/([0-9A-Za-z-]+\/[0-9A-Za-z-]+)', test_url)

main(sys.argv[1:])
22 changes: 22 additions & 0 deletions commands/host/login
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

## Description: Launch a browser and login to the current Drupal project.
## Usage: login [--name=USER]
## Example: "ddev login" or "ddev login --name=username" or "ddev login --uid=1"

FULLURL=${DDEV_PRIMARY_URL}
HTTPS=""
if [ ${DDEV_PRIMARY_URL%://*} = "https" ]; then HTTPS=true; fi
FULLURL=`ddev drush uli ${1}`

case $OSTYPE in
linux-gnu)
xdg-open ${FULLURL}
;;
"darwin"*)
open ${FULLURL}
;;
"win*"* | "msys"*)
start ${FULLURL}
;;
esac
7 changes: 7 additions & 0 deletions commands/web/behat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
## Description: Run behat inside the web container
## Usage: behat [flags] [args]
## Example: "ddev behat --tags ~wip"

cd tests/behat
bin/behat "$@"
6 changes: 6 additions & 0 deletions commands/web/robo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
## Description: Run robo inside the web container
## Usage: robo [flags] [args]
## Example: "ddev robo init"

robo "$@"
13 changes: 13 additions & 0 deletions config.hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ddev-generated
hooks:
pre-start:
- exec-host: "cp .ddev/settings.ddev.annertech.php web/sites/default/settings.local.php"
- exec-host: "cp .ddev/scripts/git-hooks/commit-msg .git/hooks/commit-msg"
- exec-host: "chmod +x .git/hooks/commit-msg"
post-start:
- exec-host: "ddev auth ssh"
post-import-db:
- exec: "drush cr"
- exec: "drush sql:sanitize -y"
- exec: "drush en stage_file_proxy -y"
- exec: "drush uli"
Binary file added images/gh-tmate.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/template-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Details about the install.yaml file are at https://ddev.readthedocs.io/en/stable/users/extend/additional-services/#sections-and-features-of-ddev-get-add-on-installyaml

name: annertech-ddev

# pre_install_actions - list of actions to run before installing the addon.
# Examples would be removing an extraneous docker volume,
# or doing a sanity check for requirements.
# DDEV environment variables can be interpolated into these actions
# pre_install_actions are executed in the context of the target project's root directory.
pre_install_actions:
# - |
# #ddev-description:Check architecture type for incompatible arm64 type
# if [ "$(uname -m)" = "arm64" -o "$(uname -m)" = "aarch64" ]; then
# echo "This package does not work on arm64 (Apple Silicon) machines";
# exit 1;
# fi

# - "docker volume rm ddev-${DDEV_PROJECT}_solr 2>/dev/null || true"

# You can also check for client DDEV version with ddev_version_constraint (see below).
# - |
# #ddev-description:Checking DDEV version
# if ! ( ddev debug capabilities 2>/dev/null | grep corepack >/dev/null 2>&1 ) ; then
# echo "This add-on requires DDEV v1.23+ or higher, please upgrade." && exit 2
# fi

# - 'echo "what is your platform.sh token" && read x'

# This item shows templating using DDEV environment variables.
# - |
# #ddev-description:Touch a file to create it
# touch ${DDEV_APPROOT}/.ddev/somefile.${DDEV_PROJECT_TYPE}.${DDEV_DOCROOT}.txt

# This item shows complex go templating possibilities based on yaml_read_files
# - |
# #ddev-description:Create a config.platformsh.yaml
# cat <<EOF >${DDEV_APPROOT}/.ddev/config.platformsh.yaml
# php_version: {{ trimPrefix "php:" .platformapp.type }}
# database:
# type: {{ regexReplaceAll ":.*$" .services.db.type "" }}
# version: {{ regexReplaceAll "^.*:" .services.db.type "" }}

# docroot: {{ dig "web" "locations" "/" "root" "notfound" .platformapp }}
# {{- if eq .platformapp.build.flavor "composer" }}
# hooks:
# post-start:
# - composer: install
# {{- if .platformapp.hooks.deploy }}
# - exec: "{{ trimAll "\n" .platformapp.hooks.deploy | splitList "\n" | join ` && ` }}"
# {{- end }}
# {{- end }}

# EOF

# list of files and directories listed that are copied into project .ddev directory
# Each file should contain #ddev-generated so it can be replaced by a later `ddev get`
# if it hasn't been modified by the user.
# DDEV environment variables can be interpolated into these filenames
# If you use directories, they must be directories that are managed
# by this add-on, or removal could remove things that are not owned by it
project_files:
- config.hooks.yaml
- settings.ddev.annertech.php
- scripts
- commands
# - some-directory/file1.txt
# - some-directory/file2.txt
# - extra_files_dir_created_by_this_template/
# - somefile.sh

# List of files and directories that are copied into the global .ddev directory
# DDEV environment variables can be interpolated into these filenames
global_files:
# - commands/web/add-on-command
# - homeadditions/some-file.txt

# Version constraint for DDEV that will be validated against the running DDEV executable
# and prevent add-on from being installed if it doesn't validate.
# See https://github.com/Masterminds/semver#checking-version-constraints for constraint rules.
# Available with DDEV v1.23.4+, and works only for DDEV v1.23.4+ binaries
# example: ddev_version_constraint: '>= v1.23.4'
ddev_version_constraint: ''

# List of add-on names that this add-on depends on
dependencies:
# - redis

# DDEV environment variables can be interpolated into these actions.
# post_install_actions are executed in the context of the target project's .ddev directory.
post_install_actions:
# - chmod +x ~/.ddev/commands/web/somecommand
# - touch ${DDEV_APPROOT}/somefile.${GOOS}.${DDEV_WEBSERVER}
# - perl -pi -e 's/oldstring/newstring/g' ${DDEV_APPROOT}/.ddev/docker-compose.addon-template.yaml

# Shell actions that can be done during removal of the add-on.
# Files listed in project_files section will be automatically removed here if they contain #ddev-generated line.
# removal_actions are executed in the context of the target project's .ddev directory.
removal_actions:
- rm ~/.ddev/commands/web/behat
- rm ~/.ddev/commands/web/robo
- rm ~/.ddev/commands/host/login
- rm ~/.ddev/settings.ddev.annertech.php
- |
if [ -f ${DDEV_APPROOT}/.ddev/config.hooks.yaml then
if grep -q '#ddev-generated' ${DDEV_APPROOT}/.ddev/config.hooks.yaml; then
rm -f ${DDEV_APPROOT}/.ddev/config.hooks.yaml
echo "Unwilling to remove '${DDEV_APPROOT}/.ddev/config.hooks.yaml' because it does not have #ddev-generated in it; you can manually delete it if it is safe to delete."
fi
fi
# Advanced usage - YAML files can be read in and then used as go template actions
# in pre_install_actions and post_install_actions
# See example in
# https://github.com/ddev/ddev/blob/master/cmd/ddev/cmd/testdata/TestCmdAddonComplex/recipe/install.yaml
yaml_read_files:
# someyaml: someyaml.yaml
# otheryaml: someotheryaml.yaml
17 changes: 17 additions & 0 deletions scripts/git-hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Regex pattern for the commit message
PATTERN="^T-[0-9]*"

# Read the commit message
commit_message=$(cat "$1")

# Check if the commit message matches the pattern
if [[ ! $commit_message =~ $PATTERN ]]; then
echo "Error: Commit message must start with the pattern 'T-00000000'."
exit 1
fi

# If the pattern matches, allow the commit
exit 0

Loading

0 comments on commit d90748d

Please sign in to comment.