From 1d5278b675aecb5c074cc11f928a52553db4922b Mon Sep 17 00:00:00 2001 From: Xieyt Date: Sat, 3 Jun 2023 15:40:31 +0530 Subject: [PATCH 1/6] feat: block emails --- 000-block-emails.php | 18 ++++++++++++++ Dockerfile | 2 +- main.sh | 56 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 000-block-emails.php diff --git a/000-block-emails.php b/000-block-emails.php new file mode 100644 index 0000000..73e2d17 --- /dev/null +++ b/000-block-emails.php @@ -0,0 +1,18 @@ + diff --git a/Dockerfile b/Dockerfile index a0fcfb6..8343764 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,7 +46,7 @@ RUN curl -sL https://deb.nodesource.com/setup_16.x | bash && \ apt install -y nodejs && \ rm -rf /var/lib/apt/lists/* -COPY deploy.php hosts.yml / +COPY deploy.php hosts.yml 000-block-emails.php / COPY *.sh / RUN chmod +x /*.sh diff --git a/main.sh b/main.sh index d7171b7..2697eca 100755 --- a/main.sh +++ b/main.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Exit on error -set -e +set -ex hosts_file="$GITHUB_WORKSPACE/.github/hosts.yml" export PATH="$PATH:$COMPOSER_HOME/vendor/bin" @@ -266,6 +266,59 @@ function deploy() { dep deploy "$GITHUB_BRANCH" } +function block_emails() { + + hosts_block_email=$(shyaml get-value "$GITHUB_BRANCH.block_emails" < "$hosts_file" 2>/dev/null || exit 0) + + if [[ -n "$hosts_block_email" ]]; then + BLOCK_EMAILS="$hosts_block_email" + fi + + if [[ -n "$BLOCK_EMAILS" ]]; then + + # priority: 1. hosts.yml 2. vip 3. WP + echo -e "\033[34mSETUP EMAIL BLOCKING\033[0m" + if [[ -d "$HTDOCS/wp-content/client-mu-plugins" ]]; then + BLOCK_EMAIL_DIR="$HTDOCS/wp-content/client-mu-plugins" + elif [[ -d "$HTDOCS/wp-content/mu-plugins" ]]; then + BLOCK_EMAIL_DIR="$HTDOCS/wp-content/mu-plugins" + fi + + hosts_block_email_dir=$(shyaml get-value "$GITHUB_BRANCH.block_emails_plugin_path" < "$hosts_file" 2>/dev/null || exit 0) + + if [[ -n "$hosts_block_email_dir" ]]; then + BLOCK_EMAIL_DIR="$HTDOCS/wp-content/$hosts_block_email_dir" + elif [[ -n "$BLOCK_EMAILS_PLUGIN_PATH" ]]; then + BLOCK_EMAIL_DIR="$HTDOCS/wp-content/$BLOCK_EMAILS_PLUGIN_PATH" + fi + + BLOCK_EMAIL_DIR="${BLOCK_EMAIL_DIR%/}" + + # using this naming convention by default to load this plugin first in mu-plugin loading phase. + BLOCK_EMAIL_PLUGIN_NAME="000-block-emails.php" + + hosts_block_email_file_name=$(shyaml get-value "$GITHUB_BRANCH.block_emails_plugin_file_name" < "$hosts_file" 2>/dev/null || exit 0) + + if [[ -n "$hosts_block_email_file_name" ]]; then + BLOCK_EMAIL_PLUGIN_NAME="${hosts_block_email_file_name}.php" + elif [[ -n "$BLOCK_EMAILS_PLUGIN_FILE_NAME" ]]; then + BLOCK_EMAIL_PLUGIN_NAME="${BLOCK_EMAILS_PLUGIN_FILE_NAME}.php" + fi + + BLOCK_EMAIL_PLUGIN_PATH="$BLOCK_EMAIL_DIR/$BLOCK_EMAIL_PLUGIN_NAME" + + if [[ -d "$BLOCK_EMAIL_DIR" ]]; then + rsync -av "/000-block-emails.php" "$BLOCK_EMAIL_PLUGIN_PATH" + echo -e "\033[34mEMAIL BLOCK [Activated]: $BLOCK_EMAIL_PLUGIN_PATH \033[0m" + else + echo -e "\033[31mEMAIL BLOCK [PATH ERROR]: $BLOCK_EMAIL_DIR doesn't exist.\033[0m" + + fi + fi + +} + + function main() { init_checks @@ -279,6 +332,7 @@ function main() { maybe_run_node_build maybe_install_submodules setup_wordpress_files + block_emails deploy fi } From 8c1a52e3c77eb68a6ce6fe84ad7bf4103329ecb9 Mon Sep 17 00:00:00 2001 From: Xieyt Date: Fri, 9 Jun 2023 13:15:21 +0530 Subject: [PATCH 2/6] fix: remove plugin_path workflow env, create mu-plugins --- main.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/main.sh b/main.sh index 2697eca..d4623ee 100755 --- a/main.sh +++ b/main.sh @@ -278,20 +278,21 @@ function block_emails() { # priority: 1. hosts.yml 2. vip 3. WP echo -e "\033[34mSETUP EMAIL BLOCKING\033[0m" - if [[ -d "$HTDOCS/wp-content/client-mu-plugins" ]]; then - BLOCK_EMAIL_DIR="$HTDOCS/wp-content/client-mu-plugins" - elif [[ -d "$HTDOCS/wp-content/mu-plugins" ]]; then - BLOCK_EMAIL_DIR="$HTDOCS/wp-content/mu-plugins" - fi hosts_block_email_dir=$(shyaml get-value "$GITHUB_BRANCH.block_emails_plugin_path" < "$hosts_file" 2>/dev/null || exit 0) if [[ -n "$hosts_block_email_dir" ]]; then BLOCK_EMAIL_DIR="$HTDOCS/wp-content/$hosts_block_email_dir" - elif [[ -n "$BLOCK_EMAILS_PLUGIN_PATH" ]]; then - BLOCK_EMAIL_DIR="$HTDOCS/wp-content/$BLOCK_EMAILS_PLUGIN_PATH" + elif [[ -d "$HTDOCS/wp-content/client-mu-plugins" ]]; then + BLOCK_EMAIL_DIR="$HTDOCS/wp-content/client-mu-plugins" + elif [[ -d "$HTDOCS/wp-content/mu-plugins" ]]; then + BLOCK_EMAIL_DIR="$HTDOCS/wp-content/mu-plugins" + else + BLOCK_EMAIL_DIR="$HTDOCS/wp-content/mu-plugins" + mkdir -p "$BLOCK_EMAIL_DIR" fi + # remove traling slash BLOCK_EMAIL_DIR="${BLOCK_EMAIL_DIR%/}" # using this naming convention by default to load this plugin first in mu-plugin loading phase. @@ -309,7 +310,7 @@ function block_emails() { if [[ -d "$BLOCK_EMAIL_DIR" ]]; then rsync -av "/000-block-emails.php" "$BLOCK_EMAIL_PLUGIN_PATH" - echo -e "\033[34mEMAIL BLOCK [Activated]: $BLOCK_EMAIL_PLUGIN_PATH \033[0m" + echo -e "\033[34mEMAIL BLOCK [ACTIVATED]: $BLOCK_EMAIL_PLUGIN_PATH \033[0m" else echo -e "\033[31mEMAIL BLOCK [PATH ERROR]: $BLOCK_EMAIL_DIR doesn't exist.\033[0m" From ef2d325669598f1ddea0ded45582da63487d19db Mon Sep 17 00:00:00 2001 From: Xieyt Date: Fri, 9 Jun 2023 13:24:57 +0530 Subject: [PATCH 3/6] fix: remove plugin_name workflow env --- main.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.sh b/main.sh index d4623ee..8c3a9d6 100755 --- a/main.sh +++ b/main.sh @@ -302,8 +302,6 @@ function block_emails() { if [[ -n "$hosts_block_email_file_name" ]]; then BLOCK_EMAIL_PLUGIN_NAME="${hosts_block_email_file_name}.php" - elif [[ -n "$BLOCK_EMAILS_PLUGIN_FILE_NAME" ]]; then - BLOCK_EMAIL_PLUGIN_NAME="${BLOCK_EMAILS_PLUGIN_FILE_NAME}.php" fi BLOCK_EMAIL_PLUGIN_PATH="$BLOCK_EMAIL_DIR/$BLOCK_EMAIL_PLUGIN_NAME" From e90246af4fdc862fc08a69fe072dc271c1795f40 Mon Sep 17 00:00:00 2001 From: Xieyt Date: Tue, 20 Jun 2023 17:31:29 +0530 Subject: [PATCH 4/6] Update: README --- README.md | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f4cb1ff..787bdc4 100644 --- a/README.md +++ b/README.md @@ -46,24 +46,46 @@ jobs: define GitHub branch mapping. Only the GitHub branches mapped in `hosts.yml` will be deployed, rest will be filtered out. Here is a sample [hosts.yml](https://github.com/rtCamp/wordpress-skeleton/blob/main/.github/hosts.yml). +## Inventory file Variables + +### Mandatory Variables + +| Variable | Default | Possible Values | Purpose | +|---------------|---------|----------------------------------------------------------------|--------------------------------| +| `user` | null | valid username. eg: `root` | Username for ssh. | +| `deploy_path` | null | valid path. eg: `/opt/easyengine/sites/example.com/app/htdocs` | path where action will deploy. | +| `hostname` | null | hostname. eg: `example.com` | hostname for ssh. | + + +### Optional + +| Variable | Default | Possible Values | Description | +|---------------------------------|------------------|-------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `block_emails` | null | true | If set to true, this will enable email blocking functionality. | +| `block_emails_plugin_path` | null | Accept relative path from wp-content directory, eg: `custom-mu-plugins` | If you have set the `MU_PLUGIN_DIR` constant in your wp-config.php file to specify a custom path for mu-plugins, you can use this variable to install Block Emails into your custom mu-plugins directory. | +| `block_emails_plugin_file_name` | 000-block-emails | String without the .php extension. | If you wish to modify the loading position of this plugin within the mu-plugins loading phase. | +| `WP_VERSION` | null | Any valid WordPress version | If you specify a WordPress version, then that speicifc WordPress version will be downloaded, instead of latest WordPress version. **Note:** Please use double quotes while giving value to this variable. This will have higher priority then the one defined in workflow file. | + + ## Environment Variables This GitHub action's behavior can be customized using following environment variables: -Variable | Default | Possible Values | Purpose -------------------|---------|---------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -`MU_PLUGINS_URL` | null | vip, any git repo url | If value is `vip`, then action will clone [VIP's MU plugins](https://github.com/Automattic/vip-mu-plugins-public) as `mu-plugins` folder. If you want to specifiy a non-VIP mu-plugins repo, you can provide a publicly accessible mu-plugins repo URL as the value. -`WP_VERSION` | latest | Any valid WordPress version | If you specify a WordPress version, then that speicifc WordPress version will be downloaded, instead of latest WordPress version. **Note:** Please use double quotes while giving value to this variable. Also, `WP_VERSION`, if defined in hosts.yml will have higher priority then the one defined in workflow file. -`WP_MINOR_UPDATE` | null | `true` / `false` | If set to `true`, latest minor version of `WP_VERSION` will be taken. -`JUMPHOST_SERVER` | null | Hostname/IP address of the jumphost server | If the deployment server is not directly accessible, and needs a jumphost, then this method should be used. (Note: The `SSH_PRIVATE_KEY` env variable should have access to the jumphost as well as deployment server for this to work. Also, this method does not work with vault.) -`SUBMODULE_DEPLOY_KEY` | null | Read access deploy key created in the submodule repo's deploy keys. | Only required for privated submodule repo. For now only one private submodule deploy key is allowed. All public submodules in repo will be fetched by default without the need of this env variable. (To create a deploy key go to: Settings > Deploy Keys > Add deploy key) -`SKIP_WP_TASKS` | null | `true`/`false` | If set to `true`, WordPress specific deplyment tasks will skipped. -`PHP_VERSION` | 7.4 | Valid PHP version | Determines the cachetool version compatible to use for purging opcache. -`NPM_VERSION` | null | Valid NPM Version | NPM Version. If not specified, latest version will be used. -`NODE_VERSION` | null | Valid Node Version | If not specified, default version built into action will be used. -`NODE_BUILD_DIRECTORY` | null | path to valid directory on repository. | Build directory. Generally root directory or directory like frontend. -`NODE_BUILD_COMMAND` | null | `npm run build` or similar command. | Command used to to build the dependencies needed on deployment. -`NODE_BUILD_SCRIPT` | null | path to valid shell script | Custom or predefined script to run after compilation. +| Variable | Default | Possible Values | Purpose | +| ------------------ | --------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `MU_PLUGINS_URL` | null | vip, any git repo url | If value is `vip`, then action will clone [VIP's MU plugins](https://github.com/Automattic/vip-mu-plugins-public) as `mu-plugins` folder. If you want to specifiy a non-VIP mu-plugins repo, you can provide a publicly accessible mu-plugins repo URL as the value. | +| `WP_VERSION` | latest | Any valid WordPress version | If you specify a WordPress version, then that speicifc WordPress version will be downloaded, instead of latest WordPress version. **Note:** Please use double quotes while giving value to this variable. Also, `WP_VERSION`, if defined in hosts.yml will have higher priority then the one defined in workflow file. | +| `WP_MINOR_UPDATE` | null | `true` / `false` | If set to `true`, latest minor version of `WP_VERSION` will be taken. | +| `JUMPHOST_SERVER` | null | Hostname/IP address of the jumphost server | If the deployment server is not directly accessible, and needs a jumphost, then this method should be used. (Note: The `SSH_PRIVATE_KEY` env variable should have access to the jumphost as well as deployment server for this to work. Also, this method does not work with vault.) | +| `SUBMODULE_DEPLOY_KEY` | null | Read access deploy key created in the submodule repo's deploy keys. | Only required for privated submodule repo. For now only one private submodule deploy key is allowed. All public submodules in repo will be fetched by default without the need of this env variable. (To create a deploy key go to: Settings > Deploy Keys > Add deploy key) | +| `SKIP_WP_TASKS` | null | `true`/`false` | If set to `true`, WordPress specific deplyment tasks will skipped. | +| `PHP_VERSION` | 7.4 | Valid PHP version | Determines the cachetool version compatible to use for purging opcache. | +| `NPM_VERSION` | null | Valid NPM Version | NPM Version. If not specified, latest version will be used. | +| `NODE_VERSION` | null | Valid Node Version | If not specified, default version built into action will be used. | +| `NODE_BUILD_DIRECTORY` | null | path to valid directory on repository. | Build directory. Generally root directory or directory like frontend. | +| `NODE_BUILD_COMMAND` | null | `npm run build` or similar command. | Command used to to build the dependencies needed on deployment. | +| `NODE_BUILD_SCRIPT` | null | path to valid shell script | Custom or predefined script to run after compilation. | +| `BLOCK_EMAILS` | null | true | If set to true, this will enable email blocking functionality. | All node related variables are completely optional. You can use them if your site needs to have node dependencies built. From 1a97d571e5901c44d6aac2aee728383e3f23cf82 Mon Sep 17 00:00:00 2001 From: Xieyt Date: Tue, 20 Jun 2023 17:34:09 +0530 Subject: [PATCH 5/6] Update: README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 787bdc4..aa19af2 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ jobs: ## Inventory file Variables -### Mandatory Variables +### Mandatory | Variable | Default | Possible Values | Purpose | |---------------|---------|----------------------------------------------------------------|--------------------------------| From a2720f49e134503478efd2f732a770fce16f7a91 Mon Sep 17 00:00:00 2001 From: Xieyt Date: Tue, 20 Jun 2023 17:40:27 +0530 Subject: [PATCH 6/6] Update: main.sh --- main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.sh b/main.sh index 8c3a9d6..6fcd77d 100755 --- a/main.sh +++ b/main.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Exit on error -set -ex +set -e hosts_file="$GITHUB_WORKSPACE/.github/hosts.yml" export PATH="$PATH:$COMPOSER_HOME/vendor/bin"