-
-
Notifications
You must be signed in to change notification settings - Fork 1
190 lines (161 loc) · 6.44 KB
/
deploy.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# script to deploy the laravel upstream to the dev server
# required secrets: HOST, USERNAME, PASSWORD, APP_PATH, APPNAME, SLACK_NOTIFICATIONS_BOT_TOKEN, SSH_PRIVATE_KEY
# If you are using OpenSSH
# If you are currently using OpenSSH and are getting the following error:
# ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey]
# Make sure that your key algorithm of choice is supported. On Ubuntu 20.04 or later you must explicitly allow the use of the ssh-rsa algorithm. Add the following line to your OpenSSH daemon file (which is either /etc/ssh/sshd_config or a drop-in file under /etc/ssh/sshd_config.d/):
# CASignatureAlgorithms +ssh-rsa
name: Deploy LaraNext to Production
# Controls when the workflow will run
on:
push:
# Trigger the workflow only when something is pushed to the repository
branches:
- main # Update with your main branch, or use '*' for all branches
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
permissions: write-all
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Notify slack success
id: slack # IMPORTANT: reference this step ID value in future Slack steps
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: bot-github
status: STARTING Deployment
color: warning
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 # https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, mysql, libxml, xml, xmlwriter, dom, tokenizer, filter, json, phar, pcre, openssl, pdo, intl, curl
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
# Run tests on Laravel
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.testing', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Create Database
run: |
mkdir -p database
touch database/database.sqlite
- name: Run Migrations
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: php artisan migrate --force
- name: Generate key
run: php artisan key:generate --force
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
# Run npm tests
- uses: actions/setup-node@v4
with:
node-version: 20
check-latest: true
- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
version: 9
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Build and Test Node Packages
run: |
pnpm install
npm run build
# Run php tests
- name: Execute tests (Unit and Feature tests) via Pest
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: ./vendor/bin/pest --parallel
- name: Notify slack success
if: ${{ success() }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
# Updates existing message from the first step
message_id: ${{ steps.slack.outputs.message_id }}
channel: bot-github
status: DEPLOYING LaraNext
color: warning
- name: Notify slack fail
if: ${{ failure() }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: bot-github
status: FAILED
color: danger
# Deploy to prod server
- name: Deploying System
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Deploying LaraNext"
set -e
whoami
pwd
cd ${{ secrets.APP_PATH }}
git reset --hard
git clean -fd
git pull --ff
chmod +x run-ci-cd-updater.sh
./run-ci-cd-updater.sh
- name: Notify slack success
if: ${{ success() }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
# Updates existing message from the first step
message_id: ${{ steps.slack.outputs.message_id }}
channel: bot-github
status: SUCCESS Deployment
color: good
- name: Notify slack fail
if: ${{ failure() }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: bot-github
status: FAILED Deployment
color: danger