-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (96 loc) · 3.74 KB
/
deploy-theme.yml
File metadata and controls
108 lines (96 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Deploy to Siteground (SSH)
on:
workflow_call:
inputs:
REMOTE:
type: string
description: "The remote folder to deploy to (e.g. 'remote:www/{REMOTE}/public_html/wp-content/themes/{theme_name}/')"
required: true
asset_folder_name:
type: string
default: "build"
description: "The name of the folder that gets generated in the build step. Default: build"
required: false
theme_name:
type: string
default: "macros-by-sara"
description: "The name of the theme to deploy. Default: macros-by-sara"
required: false
flags:
type: string
default: "-azr --delete"
description: "Optional additional flags to pass to the rsync command during deployment. Default: `-azr --delete`."
required: false
with_autoload:
type: boolean
default: false
description: "Whether to include autoload files in the deployment. Default: false"
required: false
php_version:
type: string
default: "latest"
description: "The version of PHP to use when installing dependencies. Default: latest"
required: false
jobs:
build-and-bundle:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Set up Node.js
uses: actions/setup-node@main
with:
node-version: "lts/*"
- name: Install dependencies
run: npm ci
- name: Run build
run: npm run build
- name: Read files array from package.json
id: files
run: |
FILES=$(jq -r '.files | join(" ")' package.json)
echo "files=$FILES" >> $GITHUB_OUTPUT
- name: Setup PHP with Composer
uses: shivammathur/setup-php@main
if: ${{ inputs.with_autoload }}
with:
php-version: ${{ inputs.php_version }}
tools: composer
- name: Install Composer dependencies
if: ${{ inputs.with_autoload }}
run: composer install --no-dev --prefer-dist --no-interaction --no-progress --optimize-autoloader
- name: Bundle theme
run: |
mkdir "${{ inputs.theme_name }}"
cp -r ${{ steps.files.outputs.files }} "${{ inputs.theme_name }}/"
if [ -d vendor ]; then
cp -r vendor "${{ inputs.theme_name }}/"
fi
- name: Upload theme bundle artifact
uses: actions/upload-artifact@main
with:
name: ${{ inputs.theme_name }}
path: ${{ inputs.theme_name }}/
deploy:
runs-on: ubuntu-latest
needs: build-and-bundle
steps:
- name: Download theme bundle artifact
uses: actions/download-artifact@main
with:
name: ${{ inputs.theme_name }}
path: ${{ inputs.theme_name }}
- name: Configure SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.REMOTE_HOST }} >> ~/.ssh/known_hosts 2>/dev/null || true
- name: Deploy theme via rsync
run: |
echo "Deploying theme directory to ${{ inputs.REMOTE }}"
RSYNC_OPTS="${{ inputs.flags }} --inplace --exclude='.*' --exclude='node_modules' --exclude='src' --exclude='*.log' --exclude='*.zip' --exclude='*.md' --exclude='*.json' --exclude='*.yml' --exclude='*.yaml' --exclude='*.env'"
rsync $RSYNC_OPTS \
-e "ssh -i ~/.ssh/id_rsa -p ${{ secrets.REMOTE_PORT }} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
"${{ inputs.theme_name }}/" \
"${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}:www/${{ inputs.REMOTE }}/public_html/wp-content/themes/${{ inputs.theme_name }}/"