Skip to content

ci: added testing of the app before deployment #4

ci: added testing of the app before deployment

ci: added testing of the app before deployment #4

Workflow file for this run

# 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