-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (50 loc) · 2.15 KB
/
deploy-stag.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
name: Deploy staging
on:
push:
branches:
- main
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Deploy staging from git
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
root_directory="/home/bitnami/htdocs-test"
repo_directory="$root_directory/repo"
release_directory="$root_directory/releases"
current_directory="$release_directory/$(date '+%Y%m%d%H%M%S')"
# Clone bare repository
[ -d $repo_directory ] || git clone --mirror --depth 1 https://github.com/pjshwa/apnee.git $repo_directory
# Make new release directory, and shared links
mkdir -p $current_directory
mkdir -p $root_directory/shared/static
# Keep only 5 recent releases
cd $release_directory
rm -rf `ls -t | tail -n +6`
# Clone materials into new release directory from git branch
cd $repo_directory
git fetch --depth 1 origin main
git archive main | /usr/bin/env tar -x -f - -C $current_directory
# Symlink shared materials
cd $current_directory
ln -sfn $root_directory/shared/static
# Fill credentials
echo "<?php \$credentials = array('host' => 'localhost', 'user' => '${{ secrets.DBUSER }}', 'pass' => '${{ secrets.DBPASS }}', 'database' => 'pjshwa_test'); ?>" | tee -a $current_directory/credentials.php
# Sync assets
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} aws s3 sync s3://pjshwa-homepage-assets/static ./static --delete
# Symlink current directory
cd $root_directory
ln -sfn $current_directory current
- name: Flush the PHP opcache
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
script: sudo /opt/bitnami/php/bin/cachetool opcache:reset --fcgi=/opt/bitnami/php/var/run/www.sock