-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ColoredCow/feat/continous-delivery
script to export civicrm
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Import CiviCRM - Staging | ||
on: | ||
push: | ||
branches: main | ||
|
||
jobs: | ||
import: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: SSH and Import | ||
uses: appleboy/ssh-action@master | ||
env: | ||
SSH_BUILD_DIRECTORY: ${{ secrets.SSH_BUILD_DIRECTORY }} | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USERNAME }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
envs: SSH_BUILD_DIRECTORY | ||
script: | | ||
cd $SSH_BUILD_DIRECTORY | ||
git checkout -f main | ||
git pull origin main | ||
./bin/import_civicrm.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Determine the script's directory and infer the project root directory | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" | ||
|
||
EXPORT_DIR_NAME="wp-content/civi-exports" | ||
EXPORT_DIR_PATH="$PROJECT_ROOT/$EXPORT_DIR_NAME" | ||
TIMESTAMP=$(date +%s) | ||
ZIP_FILE="${TIMESTAMP}-export.zip" | ||
|
||
# Create the exports directory if it doesn't exist | ||
mkdir -p $EXPORT_DIR_PATH | ||
|
||
echo "Backing up..." | ||
echo "wp civicrm core backup --backup-dir=$EXPORT_DIR_PATH/civicrm-backup --yes" | ||
wp civicrm core backup --backup-dir=$EXPORT_DIR_PATH/civicrm-backup --yes | ||
echo "Backup complete" | ||
|
||
cd $EXPORT_DIR_PATH | ||
|
||
cd civicrm-backup | ||
|
||
sed -i.bak 's/DEFINER=`[^`]*`@`localhost`/DEFINER=`civicrm`@`localhost`/g' civicrm-db.sql | ||
|
||
rm civicrm.zip | ||
|
||
cd .. | ||
|
||
echo "zip -r $ZIP_FILE civicrm-backup" | ||
|
||
zip -r $ZIP_FILE civicrm-backup | ||
|
||
rm -rf civicrm-backup | ||
|
||
cd $PROJECT_ROOT | ||
|
||
echo "Export ${ZIP_FILE} saved successfully to ${EXPORT_DIR_PATH}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Determine the script's directory and infer the project root directory | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" | ||
|
||
EXPORT_DIR_NAME="wp-content/civi-exports" | ||
EXPORT_DIR_PATH=$PROJECT_ROOT/$EXPORT_DIR_NAME | ||
|
||
cd $EXPORT_DIR_NAME | ||
|
||
# Get the latest zip file by timestamp | ||
ZIP_FILE=$(ls -t *-export.zip 2>/dev/null | head -n 1) | ||
|
||
|
||
# Check if there is any zip file | ||
if [ -z "$ZIP_FILE" ]; then | ||
echo "No export zip files found in ${EXPORT_DIR_NAME}." | ||
exit 0 | ||
fi | ||
|
||
# Unzip the latest zip file | ||
unzip -o $ZIP_FILE | ||
|
||
cd .. | ||
|
||
# Use yes to automate the confirmation prompt | ||
yes y | wp civicrm core restore --backup-dir=$EXPORT_DIR_PATH/civicrm-backup --yes | ||
|
||
echo "Imported ${ZIP_FILE} successfully" |
Binary file not shown.