Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Action to deploy and test the plugin in a target environment #64

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/deploy-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Deploy Plugin to Server

on:
push:
branches:
- main
workflow_dispatch:

env:
PLUGIN_NAME: bluehost-wordpress-plugin
CYPRESS_TEST_PATH: tests/cypress/integration/help.cy.js
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
environment: [bluehost-shared]
fail-fast: false

environment: ${{ matrix.environment }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20
registry-url: "https://npm.pkg.github.com"
scope: "@newfold-labs"

- name: Authenticate with GitHub Packages
run: |
echo "@newfold-labs:registry=https://npm.pkg.github.com" >> .npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.NEWFOLD_ACCESS_TOKEN }}" >> .npmrc

- name: Install PHP and Composer
run: |
sudo apt update
sudo apt install -y php-cli unzip curl
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

- name: Install Composer dependencies
run: composer install --no-dev --optimize-autoloader

- name: Install Node dependencies and build project
run: |
npm install
npm run build
npm run create:dev

- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: plugin-build-${{ matrix.environment }}
path: ./${{ env.PLUGIN_NAME }}.zip

- name: Setup SSH Key
run: |
echo "${{ secrets.SERVER_SSH_PRIVATE_KEY }}" > github-actions
chmod 600 github-actions

- name: Copy .zip file to server via SCP
run: |
scp -i github-actions -o StrictHostKeyChecking=no ./${{ env.PLUGIN_NAME }}.zip ${{ vars.SERVER_USERNAME }}@${{ vars.SERVER_IP }}:${{ vars.SERVER_PATH }}/wp-content/uploads

- name: Extract Plugin and Activate
run: |
ssh -i github-actions -o StrictHostKeyChecking=no ${{ vars.SERVER_USERNAME }}@${{ vars.SERVER_IP }} << 'EOF'
cd ${{ vars.SERVER_PATH }}/wp-content
wp plugin install uploads/${{ env.PLUGIN_NAME }}.zip --force --path=./../
rm uploads/${{ env.PLUGIN_NAME }}.zip
wp plugin activate ${{ env.PLUGIN_NAME }} --path=./../
EOF

- name: Cleanup SSH Key
run: rm -f github-actions

- name: Check if the remote Server is up
run: |
for i in {1..30}; do
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" "${{ vars.SITE_URL }}/wp-login.php")
if [[ "$STATUS_CODE" == "200" ]]; then
echo "Server is up with status code: $STATUS_CODE"
exit 0
fi
echo "Waiting for server to be ready... (Last status: $STATUS_CODE)"
sleep 10
done
echo "Server not ready after 5 minutes" && exit 1

- name: Run Specific Cypress Tests
uses: cypress-io/github-action@v6
with:
install: true
start: npm start
wait-on: ${{ vars.SITE_URL }}
config: baseUrl=${{ vars.SITE_URL }}
command: npx cypress run --spec ${{ env.CYPRESS_TEST_PATH }}
env:
BASE_URL: ${{ vars.SITE_URL }}
WP_ADMIN_USERNAME: ${{ secrets.WP_ADMIN_USERNAME }}
WP_ADMIN_PASSWORD: ${{ secrets.WP_ADMIN_PASSWORD }}
8 changes: 4 additions & 4 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const wpVersion = /[^/]*$/.exec( core )[ 0 ];
module.exports = defineConfig( {
projectId: '71eo94',
env: {
wpUsername: 'admin',
wpPassword: 'password',
wpVersion,
baseUrl: process.env.BASE_URL || 'http://localhost:8882',
wpUsername: process.env.WP_ADMIN_USERNAME || 'admin',
wpPassword: process.env.WP_ADMIN_PASSWORD || 'password',
phpVersion,
pluginId: 'bluehost',
appId: 'wppbh',
pluginSlug: 'wp-plugin-bluehost',
pluginSlug: 'wp-plugin-bluehost'
},
downloadsFolder: 'tests/cypress/downloads',
fixturesFolder: 'tests/cypress/fixtures',
Expand Down
Loading