Skip to content

Commit fecbae8

Browse files
Development (#1)
* added git-deployer-app in ignore list added, cleanup step * checking secret * checking secret * checking secret * checking secret * checking secret * checking secret * checking secret * checking secret * fix deleting * fix deleting * fix SSH_AUTH * fix SSH_AUTH * fix SSH_AUTH * fix SSH_AUTH * fix SSH_AUTH * fix SSH_AUTH * fix SSH_AUTH * fix SSH_AUTH * fix SSH_AUTH * fix SSH_AUTH * added private_key validation removed extra echos * testing Cleanup Uploaded Tar * Fix tar file deletion on fail * removed Cleanup test code * fix warning * echo ignore list for debug * added / in root files path for ignore. * removed debug code. * updated README.md * added validation for ssh creds * added bash -l -c for script run command * changed README.md
1 parent 4ae57ac commit fecbae8

File tree

3 files changed

+96
-79
lines changed

3 files changed

+96
-79
lines changed

README.md

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
# GoDaddy GitHub Action for Wordpress deployment
1+
# GoDaddy GitHub Action for Managed WordPress Deployment
22

33
## Overview
44

5-
This GitHub Action automates WordPress deployment using `rsync` over SSH. It creates a tar archive of modified files, transfers it to the remote server, and executes a deployment script. The action supports post-deployment commands, WordPress health checks, and automatic rollback in case of failures.
5+
This GitHub Action automates the deployment of your WordPress site by leveraging `rsync` over SSH. It packages only modified files into a tar archive, transfers them to your remote server, and executes a tailored deployment script. In addition, the action supports:
6+
- Post-deployment commands
7+
- WordPress health checks with automatic rollback upon failure
8+
- Secure authentication using an SSH private key
69

710
## Features
811

9-
- **Deploy only changed files** using `rsync --checksum`
10-
- **Remove deleted files** from the repository on the server
11-
- **Execute post-deployment commands**
12-
- **Perform WordPress health checks** and rollback if necessary
13-
- **Secure authentication** via SSH private key
12+
- **Deploy Only Changed Files:** Uses `rsync --checksum` to efficiently update only the modified files.
13+
- **Sync File Deletions:** Automatically removes files deleted from the repository on the server.
14+
- **WordPress Health Checks:** Monitor site health and trigger a rollback on failure.
15+
- **Secure SSH Authentication:** Ensures connectivity using your SSH private key.
1416

1517
## Usage
1618

17-
### 1. **Add the Action to Your Workflow**
19+
### 1. Add the Action to Your Workflow
1820

19-
Create a `.github/workflows/deploy.yml` file in your repository:
21+
Create a `.github/workflows/deploy.yml` file in your repository with the following content:
2022

2123
```yaml
2224
name: Deploy WordPress
@@ -25,71 +27,67 @@ on:
2527
workflow_dispatch:
2628
inputs:
2729
deployment_dest:
28-
description: 'Target server directory, leave blank for root directory'
30+
description: 'Target server directory; leave blank for the root directory'
2931
required: false
3032
enable_health_check:
31-
description: 'Enable wordpress health check?'
33+
description: 'Enable WordPress health check?'
3234
type: choice
3335
required: false
3436
default: "yes"
3537
options:
3638
- "yes"
3739
- "no"
40+
3841
jobs:
3942
deploy:
4043
runs-on: ubuntu-latest
4144
steps:
42-
- name: Checkout repository
45+
- name: Checkout Repository
4346
uses: actions/checkout@v3
4447

45-
- name: Deploy using GitHub Action
46-
uses: your-org/your-action-repo@v1
48+
- name: Deploy via GoDaddy GitHub Action
49+
uses: godaddy-wordpress/[email protected]
4750
with:
48-
remote_host: ${{ secrets.REMOTE_HOST }}
49-
ssh_user: ${{ secrets.SSH_USER }}
50-
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
51+
remote_host: 'http://your-wordpress-site.com'
52+
ssh_user: 'SSH_USERNAME_FROM_GODADDY_INTERFACE'
53+
ssh_private_key: ${{ secrets.PRIVATE_KEY }}
5154
deployment_dest: ${{ github.event.inputs.deployment_dest }}
5255
enable_health_check: ${{ github.event.inputs.enable_health_check }}
5356
```
5457
55-
## Inputs
58+
### 2. Configuration Inputs
5659
5760
| Name | Description | Required | Default |
58-
| ----------------------- | ------------------------------------ | -------- | ------- |
59-
| `remote_host` | The remote server IP or domain | ✅ Yes | - |
60-
| `ssh_user` | SSH username for authentication | ✅ Yes | - |
61-
| `ssh_private_key` | SSH private key for authentication | ✅ Yes | - |
62-
| `deployment_dest` | Remote WordPress directory | ❌ No | `.` |
63-
| `post_deploy_commands` | Commands to run after deployment | ❌ No | `''` |
64-
| `cleanup_deleted_files` | Remove deleted files from the server | ❌ No | `yes` |
65-
| `enable_health_check` | Perform a WordPress health check | ❌ No | `yes` |
66-
67-
## Requirements
68-
69-
- **Enable Git Deployment** for site from GoDaddy interface
70-
- **GitHub secrets configured** for `REMOTE_HOST`, `SSH_USER`, and `SSH_PRIVATE_KEY`
71-
72-
## Troubleshooting
61+
| ----------------------- | ------------------------------------ | -------- | ------ |
62+
| `remote_host` | The remote server IP or domain | ✅ Yes | - |
63+
| `ssh_user` | SSH username for authentication | ✅ Yes | - |
64+
| `ssh_private_key` | SSH private key for authentication | ✅ Yes | - |
65+
| `deployment_dest` | Remote WordPress directory | ❌ No | `''` |
66+
| `enable_health_check` | Perform a WordPress health check | ❌ No | `yes` |
7367

74-
### SSH Key Issues
7568

76-
Ensure the private key format is correct and matches the server's authorized keys:
69+
### Requirements
70+
- Git Deployment Enabled: Activate Git Deployment for your site via the GoDaddy control panel.
71+
- GitHub Secrets: Ensure the following secrets are configured in your repository:
72+
- `PRIVATE_KEY`
7773

7874
```bash
7975
cat ~/.ssh/id_rsa | base64
8076
```
77+
Copy the output and configure it as your repository's SSH_PRIVATE_KEY secret. (**Note:** You may have used a different name when creating your key. Please ammend the example to match your case.)
8178

82-
Set the output as `SSH_PRIVATE_KEY` in GitHub Secrets.
79+
### For additional troubleshooting:
8380

84-
## License
81+
- Double-check your remote host details.
82+
- Consult the issues tab in this repository for similar problems and their resolution.
8583

86-
This action is licensed under the MIT License.
84+
### License
8785

88-
## Contributing
86+
This GitHub Action is licensed under the MIT License.
8987

90-
Feel free to open issues or submit PRs for improvements!
88+
### Contributing
9189

92-
## Support
93-
94-
For help, open an issue in the repository.
90+
Contributions, bug reports, and ideas for improvements are welcome! Please open an issue or submit a pull request for discussion.
9591

92+
## Support
93+
For additional help or support, please open an issue in this repository.

action.yml

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ runs:
5050
OUTPUT_DIR="output"
5151
IGNORE_FILES="$ACTION_DIR/files_to_ignore.txt"
5252
SYNC_FILES="$OUTPUT_DIR/files_to_sync.txt"
53-
TEMP_KEY_FILE="private_key"
54-
SSH_AUTH="-i $TEMP_KEY_FILE -o StrictHostKeyChecking=no"
53+
TEMP_KEY_FILE="$(pwd)/private_key"
54+
SSH_AUTH="-i \"$TEMP_KEY_FILE\" -o StrictHostKeyChecking=no"
55+
5556
TAR_NAME="repository_$(openssl rand -hex 4).tar"
5657
5758
CHECKOUT_DIR=${{ inputs.source_path }}
@@ -72,7 +73,8 @@ runs:
7273
ACTION_PATH="${{ github.action_path }}"
7374
TAG_NAME=$(basename "$ACTION_PATH")
7475
echo "ACTION_TAG=$TAG_NAME" >> $GITHUB_ENV
75-
echo "::set-output name=ACTION_TAG::$TAG_NAME"
76+
echo "ACTION_TAG=$TAG_NAME" >> $GITHUB_OUTPUT
77+
7678
7779
echo "ACTION_DIR=$ACTION_DIR" >> $GITHUB_ENV
7880
echo "IGNORE_FILES=$IGNORE_FILES" >> $GITHUB_ENV
@@ -91,19 +93,31 @@ runs:
9193
9294
mkdir -p ~/.ssh $OUTPUT_DIR
9395
ssh-keyscan -H "${{ inputs.remote_host }}" >> ~/.ssh/known_hosts
94-
echo "${{ inputs.ssh_private_key }}" > "$TEMP_KEY_FILE"
96+
echo -e "${{ inputs.ssh_private_key }}" > "$TEMP_KEY_FILE"
9597
chmod 600 "$TEMP_KEY_FILE"
9698
echo "TEMP_KEY_FILE=$TEMP_KEY_FILE" >> $GITHUB_ENV
9799
- name: Validate inputs
98100
shell: bash
99101
run: |
102+
TRIMMED_KEY="$(echo "${{ inputs.ssh_private_key }}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
103+
if [[ -z "$TRIMMED_KEY" ]]; then
104+
echo "Error: SSH private key is missing."
105+
exit 1
106+
fi
107+
100108
if [ ! -d "$CHECKOUT_DIR" ]; then
101109
echo "The source directory does not exists."
102110
exit 1
103111
fi
104112
113+
# Checking credentials
114+
if ! ssh -i "$TEMP_KEY_FILE" -o StrictHostKeyChecking=no -o BatchMode=yes "$SSH_USER@$SSH_HOST" "exit" 2>/dev/null; then
115+
echo "Error: SSH authentication failed. Please check your SSH credentials."
116+
exit 1
117+
fi
118+
105119
if [[ "$WP_DEST_DIR" != "$WP_ROOT_DIR" ]]; then
106-
if ! ssh "$SSH_AUTH" "$SSH_USER@$SSH_HOST" "[ -d '/$WP_DEST_DIR' ]"; then
120+
if ! ssh -i "$TEMP_KEY_FILE" -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "[ -d '/$WP_DEST_DIR' ]"; then
107121
echo "Error: Directory '/$WP_DEST_DIR' does not exist on the server."
108122
exit 1
109123
fi
@@ -124,14 +138,10 @@ runs:
124138
EXCLUDE_ARGS+="--exclude=$line "
125139
done < "$IGNORE_FILES"
126140
127-
echo "ignore list: $EXCLUDE_ARGS"
128141
echo "Preparing a changed file list..."
129142
echo "Source: $CHECKOUT_DIR/"
130143
echo "Destination: /$WP_DEST_DIR/"
131144
echo "current dir: $(pwd)"
132-
ls -lha
133-
echo "rsync command: "
134-
echo "rsync -av --dry-run --checksum -e ssh $SSH_AUTH $CHECKOUT_DIR/ $SSH_USER@$SSH_HOST:/$WP_DEST_DIR/"
135145
136146
rsync -av --dry-run --checksum $EXCLUDE_ARGS \
137147
-e "ssh $SSH_AUTH" \
@@ -154,14 +164,14 @@ runs:
154164
155165
rsync -av --dry-run --delete --ignore-existing $EXCLUDE_ARGS \
156166
-e "ssh $SSH_AUTH" \
157-
$CHECKOUT_DIR/ "$SSH_USER@$SSH_HOST:/$WP_DEST_DIR/" \
158-
| grep '^deleting ' | awk '{print $2}' | grep -v '/$' > $DEL_FILE_LIST
159-
167+
"$CHECKOUT_DIR/" "$SSH_USER@$SSH_HOST:/$WP_DEST_DIR/" \
168+
| grep '^deleting ' 2>/dev/null | awk '{print $2}' | grep -v '/$' > "$DEL_FILE_LIST" || true
169+
160170
if [[ $? -ne 0 ]]; then
161171
echo "Error: Failed to prepare the list of files to delete."
162172
exit 1
163173
fi
164-
174+
165175
echo $(basename "$DEL_FILE_LIST") >> "$SYNC_FILES"
166176
echo "Files to be DELETED:"
167177
cat "$DEL_FILE_LIST"
@@ -179,10 +189,11 @@ runs:
179189
echo "Tar file created successfully."
180190
181191
- name: Upload tar file to server
192+
id: upload
182193
shell: bash
183194
run: |
184195
echo "Creating remote directory: $UPLOAD_DIR"
185-
ssh $SSH_AUTH "$SSH_USER@$SSH_HOST" "mkdir -p '/$UPLOAD_DIR' || exit 1"
196+
ssh -i "$TEMP_KEY_FILE" -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "mkdir -p '/$UPLOAD_DIR' || exit 1"
186197
187198
echo "Uploading tar file to $UPLOAD_DIR"
188199
rsync -avz -e "ssh $SSH_AUTH" $TAR_FILE "$SSH_USER@$SSH_HOST:/$UPLOAD_DIR/"
@@ -202,13 +213,21 @@ runs:
202213
POST_COMMAND=${{inputs.post_deploy_commands}}
203214
HEALTH_CHECK=${{inputs.enable_health_check}}
204215
DEPLOYER_SH="php /$DEPLOYER_APP_DIR/bin/init mwp:deployer"
205-
206-
OPTIONS="--destDir=$DEST_DIR --postDeploymentCommand=$POST_COMMAND"
207-
if [ "$HEALTH_CHECK" == "no" ]; then
216+
217+
OPTIONS="--destDir=$DEST_DIR"
218+
if [ "$HEALTH_CHECK" = "no" ]; then
208219
OPTIONS="$OPTIONS --skipHealthCheck"
209220
fi
210-
211-
echo "SSH Command: ssh $SSH_AUTH "$SSH_USER@$SSH_HOST" $DEPLOYER_SH $TAR_NAME $OPTIONS";
212-
ssh $SSH_AUTH "$SSH_USER@$SSH_HOST" $DEPLOYER_SH $TAR_NAME $OPTIONS
221+
222+
ssh -i "$TEMP_KEY_FILE" -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" \
223+
"bash -l -c '$DEPLOYER_SH $TAR_NAME \"$OPTIONS\"'"
213224
214225
rm -f $TEMP_KEY_FILE
226+
227+
- name: Cleanup Uploaded Tar File on Failure
228+
shell: bash
229+
if: failure() && steps.upload.outcome == 'success'
230+
run: |
231+
echo "Deleting uploaded tar file"
232+
ssh -i "$TEMP_KEY_FILE" -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "rm -f '/$UPLOAD_DIR/$TAR_NAME'"
233+

files_to_ignore.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ Thumbs.db
66
readme.md
77
.gitignore
88
output
9-
private_key
9+
/private_key
1010
action_dir
11-
index.php
12-
plat-cron.php
13-
wp-activate.php
14-
wp-blog-header.php
15-
wp-comments-post.php
16-
wp-cron.php
17-
wp-links-opml.php
18-
wp-load.php
19-
wp-login.php
20-
wp-mail.php
21-
wp-settings.php
22-
wp-signup.php
23-
wp-trackback.php
24-
xmlrpc.php
11+
/index.php
12+
/plat-cron.php
13+
/wp-activate.php
14+
/wp-blog-header.php
15+
/wp-comments-post.php
16+
/wp-cron.php
17+
/wp-links-opml.php
18+
/wp-load.php
19+
/wp-login.php
20+
/wp-mail.php
21+
/wp-settings.php
22+
/wp-signup.php
23+
/wp-trackback.php
24+
/xmlrpc.php
25+
git-deployer-app/
2526
platform/
2627
wp-admin/
2728
wp-includes/
2829
wp-content/mu-plugins/
2930
wp-content/object-cache.php
3031
wp-content/uploads/
31-
git-deployer-app/

0 commit comments

Comments
 (0)