-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yml
166 lines (151 loc) · 4.86 KB
/
action.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: Laravel Deployment Action
description: A currently opinionated github action for deploying laravel apps
author: 'Séan Poynter-Smith'
branding:
icon: 'send'
color: 'green'
inputs:
DEPLOY_KEY:
description: 'Deploy Key'
required: true
type: string
SERVER_IP:
description: 'SERVER_IP'
required: true
type: string
SERVER_PORT:
description: 'Custom port for ssh and rsync'
required: false
type: integer
default: 22
SSH_USER:
description: 'SSH user'
required: true
type: string
APP_NAME:
description: 'name of the app used on the server'
required: true
type: string
APP_PATH:
description: 'Path to the app'
required: false
type: string
COMPOSER_COMMAND:
description: 'composer command - defaults to "composer install --no-progress --optimize-autoloader"'
required: false
type: string
default: composer install --no-progress --optimize-autoloader
BUILD_COMMAND:
description: 'npm build command - defaults to "npm run dev"'
required: true
type: string
default: npm run dev
ARTISAN_COMMANDS:
description: 'Commands to run after build on remote server from the APP_PATH directory'
required: false
type: string
ARTISAN_FAIL_ON_ERROR:
description: 'Whether to fail the action if artisan commands fail'
required: false
type: boolean
default: false
PHP_VERSION:
description: 'Which version of PHP to use'
required: false
default: '8.0'
type: string
NODE_VERSION:
description: 'Which version of Node to use'
required: false
default: '16.14'
type: string
NPM_INSTALL_COMMAND:
description: 'npm install command - defaults to "npm install"'
required: false
type: string
default: npm ci
runs:
using: "composite"
steps:
- name: Setup PHP ${{ inputs.PHP_VERSION }} with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.PHP_VERSION }}
- name: Set the APP_PATH environment variable
id: step_one
if: ${{ inputs.APP_PATH == '' }}
shell: bash
run: |
echo "APP_PATH=/srv/users/${{inputs.SSH_USER}}/apps/${{inputs.APP_NAME}}" >> $GITHUB_ENV
- name: Use the value
id: step_two
shell: bash
run: |
echo "${{ inputs.APP_PATH || env.APP_PATH }}" # This will output the path
- name: Npm File Exists
id: check_npm_file
uses: andstor/[email protected]
with:
files: "package.json"
allow_failure: false
- name: Composer File Exists
id: check_composer_file
uses: andstor/[email protected]
with:
files: "composer.json"
allow_failure: false
- name: Cache Composer dependencies
if: steps.check_composer_file.outputs.files_exists == 'true'
id: composer-cache
uses: actions/cache@v2
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}-v2
- name: Install dependencies
if: steps.check_composer_file.outputs.files_exists == 'true' && steps.composer-cache.outputs.cache-hit != 'true'
shell: bash
run: ${{ inputs.COMPOSER_COMMAND }}
- name: Setup Node.js 16.14
if: steps.check_npm_file.outputs.files_exists == 'true'
uses: actions/setup-node@v2
with:
node-version: 16.14
- name: Cache Node Modules
if: steps.check_npm_file.outputs.files_exists == 'true' && steps.node-cache.outputs.cache-hit != 'true'
id: node-cache
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}-v2
- name: Install Dependencies
if: steps.check_npm_file.outputs.files_exists == 'true' && steps.node-cache.outputs.cache-hit != 'true'
shell: bash
run: ${{ inputs.NPM_INSTALL_COMMAND || 'npm ci' }}
- name: NPM Build
if: steps.check_npm_file.outputs.files_exists == 'true'
shell: bash
run: ${{ inputs.BUILD_COMMAND }}
- name: Sync
env:
dest: ${{inputs.SSH_USER}}@${{inputs.SERVER_IP}}:${{inputs.APP_PATH || env.APP_PATH}}
shell: bash
run: |
echo "${{inputs.DEPLOY_KEY}}" > deploy_key
chmod 600 ./deploy_key
rsync -vzr --stats --checksum \
-e 'ssh -i ./deploy_key -o StrictHostKeyChecking=no -p ${{inputs.SERVER_PORT || 22}}' \
--exclude /deploy_key \
--exclude /.git/ \
--exclude /.github/ \
--exclude /node_modules/ \
./ ${{env.dest}}
- name: multiple command
uses: appleboy/ssh-action@master
with:
host: ${{ inputs.SERVER_IP }}
username: ${{inputs.SSH_USER}}
key: ${{ inputs.DEPLOY_KEY }}
script_stop: ${{ inputs.ARTISAN_FAIL_ON_ERROR || false }}
script: |
cd ${{ inputs.APP_PATH || env.APP_PATH }}
${{ inputs.ARTISAN_COMMANDS }}