Skip to content

Commit 41a8a39

Browse files
authored
[CICD-48] Add shell script and yaml linting to GHA
1 parent 0d63fba commit 41a8a39

File tree

6 files changed

+46
-20
lines changed

6 files changed

+46
-20
lines changed

.github/workflows/e2e-deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
# Deploy Options
2828
SRC_PATH: "tests/data/plugins/test-plugin"
2929
REMOTE_PATH: "wp-content/plugins/"
30-
PHP_LINT: TRUE
30+
PHP_LINT: true
3131
FLAGS: -r --backup --backup-dir=/tmp --itemize-changes
3232
SCRIPT: "tests/data/post-deploy/test-plugin.sh"
33-
CACHE_CLEAR: TRUE
33+
CACHE_CLEAR: true
3434
validate_result:
3535
runs-on: ubuntu-latest
3636
needs: run_action

.github/workflows/lint-files.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Lint GHA Files
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Lint files
16+
uses: actions/checkout@v3
17+
- run: echo "Running shell script lint!"
18+
- run: find . -name "*.sh" -type f | xargs -I {} shellcheck --severity=error {}
19+
- run: echo "Running yml file lint!"
20+
- run: find . -name "*.yml" -type f | xargs -I {} yamllint {}

.yamllint

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
rules:
3+
line-length:
4+
max: 120
5+
truthy: {check-keys: false}

action.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: "Deploy WordPress to WP Engine"
23
branding:
34
icon: "upload-cloud"
@@ -11,7 +12,7 @@ inputs:
1112
description: "optional php syntax check"
1213
required: false
1314
default: false
14-
FLAGS:
15+
FLAGS:
1516
description: "Optional flags for the deployment"
1617
required: true
1718
default: '-azvr --inplace --exclude=".*"'
@@ -39,10 +40,10 @@ inputs:
3940
DEV_ENV:
4041
description: "Destination to deploy to WPE Dev"
4142
required: false
42-
SCRIPT:
43+
SCRIPT:
4344
description: "File containing custom scripts run after the rsync"
4445
required: false
4546

4647
runs:
4748
using: "docker"
48-
image: "Dockerfile"
49+
image: "Dockerfile"

entrypoint.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
: ${INPUT_WPE_SSHG_KEY_PRIVATE?Required secret not set.}
5+
: "${INPUT_WPE_SSHG_KEY_PRIVATE?Required secret not set.}"
66

77
#Alias logic for ENV names
88
if [[ -n ${INPUT_WPE_ENV} ]]; then
@@ -30,7 +30,7 @@ WPE_DESTINATION=wpe_gha+"$WPE_SSH_USER":sites/"$WPE_ENV_NAME"/"$DIR_PATH"
3030

3131

3232
# Setup our SSH Connection & use keys
33-
if [ ! -d ${HOME}/.ssh ]; then
33+
if [ ! -d "${HOME}"/.ssh ]; then
3434
mkdir "${HOME}/.ssh"
3535
SSH_PATH="${HOME}/.ssh"
3636
mkdir "${SSH_PATH}/ctl/"
@@ -52,15 +52,15 @@ ssh-keyscan -t rsa "$WPE_SSH_HOST" >> "$KNOWN_HOSTS_PATH"
5252
chmod 644 "$KNOWN_HOSTS_PATH"
5353

5454
echo "prepping file perms..."
55-
find $SRC_PATH -type d -exec chmod -R 775 {} \;
56-
find $SRC_PATH -type f -exec chmod -R 664 {} \;
55+
find "$SRC_PATH" -type d -exec chmod -R 775 {} \;
56+
find "$SRC_PATH" -type f -exec chmod -R 664 {} \;
5757
echo "file perms set..."
5858

5959
# pre deploy php lint
6060
if [ "${INPUT_PHP_LINT^^}" == "TRUE" ]; then
6161
echo "Begin PHP Linting."
62-
for file in $(find $SRC_PATH/ -name "*.php"); do
63-
php -l $file
62+
find "$SRC_PATH"/ -name "*.php" -type f -print0 | while IFS= read -r -d '' file; do
63+
php -l "$file"
6464
status=$?
6565
if [[ $status -ne 0 ]]; then
6666
echo "FAILURE: Linting failed - $file :: $status" && exit 1
@@ -88,31 +88,31 @@ fi
8888

8989
# Deploy via SSH
9090
# setup master ssh connection
91-
ssh -nNf -v -i ${WPE_SSHG_KEY_PRIVATE_PATH} -o StrictHostKeyChecking=no -o ControlMaster=yes -o ControlPath="$SSH_PATH/ctl/%C" $WPE_FULL_HOST
91+
ssh -nNf -v -i "${WPE_SSHG_KEY_PRIVATE_PATH}" -o StrictHostKeyChecking=no -o ControlMaster=yes -o ControlPath="$SSH_PATH/ctl/%C" "$WPE_FULL_HOST"
9292

9393
echo "!!! MASTER SSH CONNECTION ESTABLISHED !!!"
9494
#rsync
95-
rsync --rsh="ssh -v -p 22 -i ${WPE_SSHG_KEY_PRIVATE_PATH} -o StrictHostKeyChecking=no -o 'ControlPath=$SSH_PATH/ctl/%C'" $INPUT_FLAGS --exclude-from='/exclude.txt' $SRC_PATH "$WPE_DESTINATION"
95+
rsync --rsh="ssh -v -p 22 -i ${WPE_SSHG_KEY_PRIVATE_PATH} -o StrictHostKeyChecking=no -o 'ControlPath=$SSH_PATH/ctl/%C'" $INPUT_FLAGS --exclude-from='/exclude.txt' "$SRC_PATH" "$WPE_DESTINATION"
9696

9797
# post deploy script and cache clear
9898
if [[ -n ${SCRIPT} || -n ${CACHE_CLEAR} ]]; then
9999

100100
if [[ -n ${SCRIPT} ]]; then
101-
if ! ssh -v -p 22 -i ${WPE_SSHG_KEY_PRIVATE_PATH} -o StrictHostKeyChecking=no -o ControlPath="$SSH_PATH/ctl/%C" $WPE_FULL_HOST "test -s sites/${WPE_ENV_NAME}/${INPUT_SCRIPT}"; then
101+
if ! ssh -v -p 22 -i "${WPE_SSHG_KEY_PRIVATE_PATH}" -o StrictHostKeyChecking=no -o ControlPath="$SSH_PATH/ctl/%C" "$WPE_FULL_HOST" "test -s sites/${WPE_ENV_NAME}/${INPUT_SCRIPT}"; then
102102
status=1
103103
fi
104104

105105
if [[ $status -ne 0 && -f ${INPUT_SCRIPT} ]]; then
106-
ssh -v -p 22 -i ${WPE_SSHG_KEY_PRIVATE_PATH} -o StrictHostKeyChecking=no -o ControlPath="$SSH_PATH/ctl/%C" $WPE_FULL_HOST "mkdir -p sites/${WPE_ENV_NAME}/$(dirname ${INPUT_SCRIPT})"
106+
ssh -v -p 22 -i "${WPE_SSHG_KEY_PRIVATE_PATH}" -o StrictHostKeyChecking=no -o ControlPath="$SSH_PATH/ctl/%C" "$WPE_FULL_HOST" "mkdir -p sites/${WPE_ENV_NAME}/$(dirname "${INPUT_SCRIPT}")"
107107

108-
rsync --rsh="ssh -v -p 22 -i ${WPE_SSHG_KEY_PRIVATE_PATH} -o StrictHostKeyChecking=no -o 'ControlPath=$SSH_PATH/ctl/%C'" ${INPUT_SCRIPT} wpe_gha+"$WPE_SSH_USER":sites/"$WPE_ENV_NAME"/$(dirname ${INPUT_SCRIPT})
108+
rsync --rsh="ssh -v -p 22 -i ${WPE_SSHG_KEY_PRIVATE_PATH} -o StrictHostKeyChecking=no -o 'ControlPath=$SSH_PATH/ctl/%C'" "${INPUT_SCRIPT}" "wpe_gha+$WPE_SSH_USER:sites/$WPE_ENV_NAME/$(dirname "${INPUT_SCRIPT}")"
109109
fi
110110
fi
111111

112-
ssh -v -p 22 -i ${WPE_SSHG_KEY_PRIVATE_PATH} -o StrictHostKeyChecking=no -o ControlPath="$SSH_PATH/ctl/%C" $WPE_FULL_HOST "cd sites/${WPE_ENV_NAME} ${SCRIPT} ${CACHE_CLEAR}"
112+
ssh -v -p 22 -i "${WPE_SSHG_KEY_PRIVATE_PATH}" -o StrictHostKeyChecking=no -o ControlPath="$SSH_PATH/ctl/%C" "$WPE_FULL_HOST" "cd sites/${WPE_ENV_NAME} ${SCRIPT} ${CACHE_CLEAR}"
113113
fi
114114

115115
#close master ssh
116-
ssh -O exit -o ControlPath="$SSH_PATH/ctl/%C" $WPE_FULL_HOST
116+
ssh -O exit -o ControlPath="$SSH_PATH/ctl/%C" "$WPE_FULL_HOST"
117117

118118
echo "SUCCESS: Your code has been deployed to WP Engine!"

tests/data/post-deploy/test-plugin.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ AFTER_PLUGIN_VERSION=$(wp plugin get $PLUGIN_NAME | sed -n "/version/p" | cut -f
1414
echo "New test plugin version: $AFTER_PLUGIN_VERSION"
1515

1616
# Revert to backup created by rsync if it exists
17-
if [ -d $BACKUP_DIR/$PLUGIN_NAME ]; then
17+
if [ -d $BACKUP_DIR/$PLUGIN_NAME ]; then
1818
rm -rf $PLUGINS_DIR/$PLUGIN_NAME && mv $BACKUP_DIR/$PLUGIN_NAME $PLUGINS_DIR/
1919
fi
2020

@@ -29,4 +29,4 @@ if [ -z "$BEFORE_PLUGIN_VERSION" ] || [ -z "$AFTER_PLUGIN_VERSION" ] || [ "$BEFO
2929
else
3030
echo "Success: Test plugin successfully updated from $BEFORE_PLUGIN_VERSION to $AFTER_PLUGIN_VERSION!"
3131
echo "::set-output name=status::pass"
32-
fi
32+
fi

0 commit comments

Comments
 (0)