Skip to content

Commit eae1b4b

Browse files
author
alokVishu
committed
feat: add deployment workflow for free demos
1 parent 66e56e9 commit eae1b4b

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Deploy - Demos Free
2+
run-name: ${{ inputs.is_production && '🚀' || '🧪' }} Deploy - Demos Free
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
is_production:
8+
type: boolean
9+
description: Is production deployment
10+
11+
jobs:
12+
deployment:
13+
runs-on: ubuntu-latest
14+
env:
15+
STAG_DIR: ${{ secrets.PROD_DIR }}staging/
16+
DEPLOY_DIR: ${{ secrets.PROD_DIR }}${{ !inputs.is_production && 'staging/' || '' }}
17+
steps:
18+
19+
- name: ⚙️ Setup pnpm
20+
uses: pnpm/action-setup@v2
21+
with:
22+
version: 8
23+
24+
- name: ⚙️ Set BRAND_NAME environment variable from repo name
25+
run: echo BRAND_NAME=${{ github.event.repository.name }} | cut -d '-' -f1 >> $GITHUB_ENV
26+
27+
- name: ⬇️ Clone current repo under /<template-name>/vue-laravel-free
28+
uses: actions/checkout@v3
29+
with:
30+
path: ${{ env.BRAND_NAME }}/vue-laravel-free
31+
32+
- name: ⬇️ Clone automation scripts repo under /automation-scripts
33+
uses: actions/checkout@v3
34+
with:
35+
repository: themeselection/automation-scripts
36+
token: ${{ secrets.GH_PAT }}
37+
path: automation-scripts
38+
39+
- name: ⬇️ Install packages in automation-scripts dir
40+
working-directory: automation-scripts/vue
41+
run: pnpm install
42+
43+
- name: ⚙️ Set LARAVEL_CORE_DIR_NAME environment variable from generated env file
44+
working-directory: automation-scripts/vue
45+
run: pnpm tsx src/templates/${{ env.BRAND_NAME }}/scripts/genLaravelCoreDirNameEnvFile.ts --isFree $([[ "${{ inputs.is_production }}" != "true" ]] && echo --staging) && cat .env.laravel-core-dir-name >> $GITHUB_ENV
46+
47+
- name: ⬇️ Install packages in typescript full version
48+
working-directory: ${{ env.BRAND_NAME }}/vue-laravel-free/typescript-version
49+
run: pnpm i && composer install
50+
51+
- name: 🎭 Create .env file from .env.example & generate APP_KEY via `php artisan key:generate`
52+
working-directory: ${{ env.BRAND_NAME }}/vue-laravel-free/typescript-version
53+
run: cp .env.example .env && php artisan key:generate
54+
55+
- name: 📦 Generate demos
56+
working-directory: automation-scripts/vue
57+
run: pnpm tsx src/templates/${{ env.BRAND_NAME }}/scripts/genLaravelDemos.ts --isFree $([[ "${{ inputs.is_production }}" != "true" ]] && echo --staging)
58+
59+
- name: 🚀 Upload demos zip
60+
uses: appleboy/scp-action@master
61+
with:
62+
host: ${{ secrets.HOST }}
63+
username: ${{ secrets.USERNAME }}
64+
port: ${{ secrets.PORT }}
65+
key: ${{ secrets.SSHKEY }}
66+
source: ${{ env.BRAND_NAME }}/vue-laravel-free/typescript-version/*.zip
67+
target: ${{ secrets.LARAVEL_CORE_CONTAINER_DIR }}
68+
strip_components: 3
69+
70+
- name: 🪄 Setup demos
71+
uses: appleboy/ssh-action@v0.1.5
72+
with:
73+
host: ${{ secrets.HOST }}
74+
username: ${{ secrets.USERNAME }}
75+
port: ${{ secrets.PORT }}
76+
key: ${{ secrets.SSHKEY }}
77+
script: |
78+
# create deployment dir if doesn't exist
79+
mkdir -p ${{ env.DEPLOY_DIR }}
80+
81+
# navigate to laravel core container dir
82+
cd ${{ secrets.LARAVEL_CORE_CONTAINER_DIR }}
83+
84+
# Remove existing backup zip
85+
rm -rf bak-${{ env.LARAVEL_CORE_DIR_NAME }}-*.zip
86+
87+
# Remove existing laravel core dir
88+
rm -rf ${{ env.LARAVEL_CORE_DIR_NAME }}
89+
90+
# if prod => zip existing laravel core
91+
DEMO_ZIP_NAME="bak-${{ env.LARAVEL_CORE_DIR_NAME }}-$(date +"%Y-%m-%d-%H-%M-%S").zip"
92+
[[ "${{ inputs.is_production }}" == "true" ]] && zip -r $DEMO_ZIP_NAME ${{ env.LARAVEL_CORE_DIR_NAME }} -x "*.zip"
93+
94+
# remove existing staging laravel core & staging demos
95+
# ℹ️ Previously we were only performing this removal if `inputs.is_production` is true but doing this for staging as well might remove permission issue in future
96+
rm -rf ${{ env.STAG_DIR }}/demo
97+
98+
# Remove staging laravel core dir
99+
# ℹ️ This is tricky because if it's staging then `env.LARAVEL_CORE_DIR_NAME` will have `-staging` already suffixed and work perfectly without below command.
100+
# Additionally, below command will result in something like this (that won't do anything) in staging env: `rm -rf <brand>-vuejs-laravel-admin-template-staging-staging`
101+
# However, in production it will allow us to remove staging laravel core dir
102+
rm -rf ${{ env.LARAVEL_CORE_DIR_NAME }}-staging
103+
104+
# remove existing demos
105+
rm -rf ${{ env.DEPLOY_DIR }}/demo
106+
107+
# unzip the uploaded laravel core. "-q" option will silently unzip without logs
108+
unzip -q ${{ env.LARAVEL_CORE_DIR_NAME }}.zip
109+
110+
# remove the uploaded zip
111+
rm -rf ${{ env.LARAVEL_CORE_DIR_NAME }}.zip
112+
113+
# ATM, we have successfully, uploaded the zip to server with file cleanup. Next, just move the demo in its place
114+
115+
mv ${{ env.LARAVEL_CORE_DIR_NAME }}/demo ${{ env.DEPLOY_DIR }}
116+
117+
# create logs dir & laravel.log file in laravel core if doesn't exist. We are doing "echo ls $" because if we don't, "mkdir -p" will create dir as "<brand>*" instead of full name "<brand>-xxx"
118+
mkdir -p ${{ env.LARAVEL_CORE_DIR_NAME }}/storage/logs/ && touch ${{ env.LARAVEL_CORE_DIR_NAME }}/storage/logs/laravel.log
119+
120+
# grant read & write permission to group & other
121+
chmod -R g+rw ${{ env.LARAVEL_CORE_DIR_NAME }}/storage

0 commit comments

Comments
 (0)