Skip to content

Commit

Permalink
feat: Add action to deploy to Pantheon
Browse files Browse the repository at this point in the history
Signed-off-by: Souptik Datta <[email protected]>
  • Loading branch information
Souptik2001 committed Nov 25, 2023
1 parent f25b0ea commit f8a6b8e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
39 changes: 39 additions & 0 deletions .bin/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -x
set -euo pipefail

# Add SSH Key
eval $(ssh-agent -s)
ssh-agent -a /tmp/ssh_agent.sock > /dev/null
echo "$PANTHEON_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
mkdir -p ~/.ssh && echo "StrictHostKeyChecking no" >> ~/.ssh/config

# Git Config
git config --global user.email "[email protected]"
git config --global user.name "GitHub Deploy"

# Clone Pantheon Repo
git clone --single-branch --branch $PANTHEON_GIT_BRANCH $PANTHEON_GIT_REPOSITORY $HOME/pantheon-deploy --depth 1
cd $HOME/pantheon-deploy

# Copy Plugins
rm -rf wp-content/plugins
cp -r $GITHUB_WORKSPACE/backend/plugins wp-content

# Copy Themes
rm -rf wp-content/themes
mv $GITHUB_WORKSPACE/backend/themes wp-content

# Check if we have changes
if [[ -z $(git status -s) ]]; then
# No changes
echo "No changes to push"
else
# Push changes to Pantheon
git add .
git status
git commit -m "Deploy from GitHub $GITHUB_SHA"
git push origin $PANTHEON_GIT_BRANCH
fi

set +x
39 changes: 39 additions & 0 deletions .github/workflows/backend-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Backend Deploy

concurrency: backend

on:
release:
types: [ published ]

env:
COMPOSER_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: backend

steps:
- name: Checkout to repository.
uses: actions/checkout@v2

- uses: actions/setup-node@v3
with:
node-version-file: './backend/plugins/souptik2001/.nvmrc'

- name: Install WordPress plugins
run: |
composer install --working-dir=backend
- name: Build the souptik2001 plugin's assets
run: cd backend/plugins/souptik2001 && npm ci && npm run build && rm -rf node_modules

- name: Deploy to Pantheon
env:
PANTHEON_SSH_PRIVATE_KEY: ${{ secrets.PANTHEON_SSH_PRIVATE_KEY }}
PANTHEON_GIT_REPOSITORY: ${{ secrets.PANTHEON_GIT_REPOSITORY }}
PANTHEON_GIT_BRANCH: master
RELEASE_VERSION: ${{ github.ref_name }}
run: bash .bin/deploy.sh
5 changes: 3 additions & 2 deletions .github/workflows/build-backend-image.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Backend Image build
name: Backend Image build - This is not used used in deployment, but just building it.

on:
push:
Expand All @@ -11,7 +11,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Checkout to repository.
uses: actions/checkout@v2

- uses: actions/setup-node@v3
with:
Expand Down

1 comment on commit f8a6b8e

@vercel
Copy link

@vercel vercel bot commented on f8a6b8e Nov 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.