-
Notifications
You must be signed in to change notification settings - Fork 20
132 lines (113 loc) · 4.49 KB
/
deploy-stage.yml
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Deploy Staging
on:
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
env:
BUILD_FOLDER: ./build
DEPLOY_FOLDER: ./deploy
ENVIRONMENT: staging
DEPLOY_REPO: ${{ secrets.STAGE_DEPLOY_REPO }}
steps:
##########
### BUILD: General SquareOne build steps
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: '8.0'
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Get Build Repository
- name: Check out build branch
uses: actions/checkout@v3
with:
path: ${{ env.BUILD_FOLDER }}
ref: ${{ github.ref }}
- name: Configure composer
working-directory: ${{ env.BUILD_FOLDER }}
run: echo "${{ secrets.COMPOSER_ENV }}" > .env
- name: Install composer dependencies
uses: ramsey/composer-install@v2
with:
working-directory: ${{ env.BUILD_FOLDER }}
composer-options: "--optimize-autoloader --ignore-platform-reqs --no-dev"
- name: Clean up composer configuration
working-directory: ${{ env.BUILD_FOLDER }}
run: |
rm .env
rm -rf vendor/moderntribe/tribe-libs/.git
rm -rf wp-content/plugins/panel-builder/.git
# Set up node version
- name: Set up node
uses: actions/setup-node@v3
with:
node-version-file: "${{ env.BUILD_FOLDER }}/.nvmrc"
cache: 'yarn'
cache-dependency-path: "${{ env.BUILD_FOLDER }}/yarn.lock"
# Yarn Install and Build
- name: Yarn install and build
working-directory: ${{ env.BUILD_FOLDER }}
run: |
yarn install --prefer-offline
npm run validate
npm run server_dist
# Create local config for environment based settings
- name: Create local config
working-directory: ${{ env.BUILD_FOLDER }}
run: |
php -r "file_exists( 'local-config.php' ) || copy( 'local-config-sample.php', 'local-config.php' );"
php -r "file_exists( 'local-config.json' ) || copy( 'local-config-sample.json', 'local-config.json' );"
echo "define( 'WP_ENVIRONMENT_TYPE', ${{env.ENVIRONMENT}} );" >> local-config.php
##########
### DEPLOY: Use the WPE git deploy hook method. TLDR; rsync our repo on their repo and push.
# Setup SSH key for deploy environment
- name: HOST SCM SSH KEY
uses: webfactory/[email protected]
with:
ssh-private-key: ${{secrets.DEPLOY_PRIVATE_SSH_KEY}}
# Get Build Repository and add wpengine to allowed hosts
- name: HOST SCM
run: |
ssh-keyscan git.wpengine.com >> ~/.ssh/known_hosts
git clone ${{env.DEPLOY_REPO}} ${{env.DEPLOY_FOLDER}}
cd ${{env.DEPLOY_FOLDER}}
git config user.email "[email protected]"
git config user.name "devops"
# Rsync WordPress
- name: Sync Build WP folder to Deploy directory
run: |
rsync -rpv --delete ${{env.BUILD_FOLDER}}/wp/ ${{env.DEPLOY_FOLDER}} \
--exclude=.git \
--exclude=.gitmodules \
--exclude=.gitignore \
--exclude=.htaccess \
--exclude=wp-config.php \
--exclude=wp-content
# Rsync plugin and theme files
- name: Sync Build WP-CONTENT folder to Deploy directory
run: |
rsync -rpv --delete --exclude-from="${{env.BUILD_FOLDER}}/.deploy-ignore" ${{env.BUILD_FOLDER}}/wp-content ${{env.DEPLOY_FOLDER}} \
--exclude=dev \
--exclude=dev_components \
--exclude=docs \
--exclude=gulp_tasks \
--exclude=node_modules \
--exclude=wp-content/object-cache.php \
--exclude=wp-content/plugins/core/assets/templates/cli
# Rsync Composer Vendor files
- name: Sync Build VENDOR folder to Deploy directory
run: |
rsync -rpv ${{env.BUILD_FOLDER}}/ ${{env.DEPLOY_FOLDER}} \
--include=build-process.php \
--include=vendor/*** \
--exclude=*
# Git push to WPE to trigger deploy
- name: Git Push to Host SCM
working-directory: ${{ env.DEPLOY_FOLDER }}
run: |
echo 'Deploying ${{env.GITHUB_REF}} to ${{env.ENVIRONMENT}}'
git add -Av
git commit --allow-empty -m 'Deploying ${{env.BRANCH_NAME}} to ${{env.ENVIRONMENT}}'
git push origin master