Skip to content

Commit

Permalink
feat: separate deployment workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed May 9, 2023
1 parent d5854e2 commit 1386622
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 51 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/deploy_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---

on: # yamllint disable-line rule:truthy
push:
branches:
- master
# release:
# types:
# - released
# push:
# tags:
# - 'v*'

name: 📦 Deploy to production

defaults:
run:
working-directory: app

jobs:
integration:
runs-on: "ubuntu-22.04"
strategy:
fail-fast: true
environment:
name: production
url: https://prod.laravel-starter-tpl.wayof.dev

steps:
- name: 📦 Check out the codebase
uses: actions/checkout@v3

- name: 🛠️ Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
ini-values: error_reporting=E_ALL
tools: composer:v2

- name: ♻️ Restore cached backend dependencies
id: cached-composer-dependencies
uses: actions/cache@v3
with:
path: vendor
key: vendor-${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: 📥 Install backend dependencies
if: steps.cached-composer-dependencies.outputs.cache-hit != 'true'
run: composer install

- name: 📤 Deploy production environment
uses: deployphp/action@v1
with:
private-key: ${{ secrets.DEPLOYER_PRIVATE_KEY }}
dep: deploy prod
env:
DEPLOYER_STAGING_SLACK_WEBHOOK: ${{ secrets.DEPLOYER_STAGING_SLACK_WEBHOOK }}
DEPLOYER_STAGING_REMOTE_USER: ${{ secrets.DEPLOYER_STAGING_REMOTE_USER }}
DEPLOYER_STAGING_HOST: "staging.laravel-starter-tpl.wayof.dev"
DEPLOYER_STAGING_BRANCH: "develop"
DEPLOYER_PROD_SLACK_WEBHOOK: ${{ secrets.DEPLOYER_PROD_SLACK_WEBHOOK }}
DEPLOYER_PROD_REMOTE_USER: ${{ secrets.DEPLOYER_PROD_REMOTE_USER }}
DEPLOYER_PROD_HOST: "prod.laravel-starter-tpl.wayof.dev"
DEPLOYER_PROD_BRANCH: "master"

- name: 📦 Create sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.DEPLOYER_SENTRY_TOKEN }}
SENTRY_ORG: ${{ secrets.DEPLOYER_SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.DEPLOYER_SENTRY_PROJECT }}
with:
environment: ${{ github.ref == 'refs/heads/master' && 'production' || 'staging' }}
set_commits: auto

...
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
on: # yamllint disable-line rule:truthy
push:
branches:
- master
- develop

name: 📦 Deploy to server
name: 📦 Deploy to staging

defaults:
run:
working-directory: app

jobs:
integration:
needs:
- integration
- shellcheck
runs-on: "ubuntu-22.04"
strategy:
fail-fast: true
environment:
name: staging
url: https://staging.laravel-starter-tpl.wayof.dev

steps:
- name: 📦 Check out the codebase
Expand All @@ -29,15 +28,9 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
extensions: dom, curl, libxml, mbstring, zip, fileinfo, xdebug
ini-values: error_reporting=E_ALL
tools: composer:v2

- name: 🛠️ Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: ♻️ Restore cached backend dependencies
id: cached-composer-dependencies
uses: actions/cache@v3
Expand All @@ -49,24 +42,11 @@ jobs:
if: steps.cached-composer-dependencies.outputs.cache-hit != 'true'
run: composer install

- name: 🛠️ Prepare environment
run: |
cd ../ && make env && cd app
cp ../.env .env
mkdir -p ./.build/php-cs-fixer
mkdir -p ./.build/phpstan
mkdir -p ./.build/phpunit
env:
APP_NAME: laravel
SHARED_SERVICES_NAMESPACE: ss
PROJECT_SERVICES_NAMESPACE: wod
COMPOSE_PROJECT_NAME: laravel-starter-tpl

- name: 📤 Deploy ${{ github.ref == 'refs/heads/master' && 'production' || 'staging' }} environment
- name: 📤 Deploy staging environment
uses: deployphp/action@v1
with:
private-key: ${{ secrets.DEPLOYER_PRIVATE_KEY }}
dep: deploy ${{ github.ref == 'refs/heads/master' && 'prod' || 'staging' }}
dep: deploy staging
env:
DEPLOYER_STAGING_SLACK_WEBHOOK: ${{ secrets.DEPLOYER_STAGING_SLACK_WEBHOOK }}
DEPLOYER_STAGING_REMOTE_USER: ${{ secrets.DEPLOYER_STAGING_REMOTE_USER }}
Expand All @@ -76,7 +56,15 @@ jobs:
DEPLOYER_PROD_REMOTE_USER: ${{ secrets.DEPLOYER_PROD_REMOTE_USER }}
DEPLOYER_PROD_HOST: "prod.laravel-starter-tpl.wayof.dev"
DEPLOYER_PROD_BRANCH: "master"
DEPLOYER_SENTRY_TOKEN: ${{ secrets.DEPLOYER_SENTRY_TOKEN }}
DEPLOYER_SENTRY_ORG: "wayofdev"
DEPLOYER_SENTRY_PROJECT: "laravel-starter-tpl"
DEPLOYER_SENTRY_SERVER: "https://wayofdev.sentry.io"

- name: 📦 Create sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.DEPLOYER_SENTRY_TOKEN }}
SENTRY_ORG: ${{ secrets.DEPLOYER_SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.DEPLOYER_SENTRY_PROJECT }}
with:
environment: ${{ github.ref == 'refs/heads/master' && 'production' || 'staging' }}
set_commits: auto

...
23 changes: 2 additions & 21 deletions app/deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
require 'recipe/laravel.php';
require 'contrib/slack.php';

if (getenv('DEPLOYER_SENTRY_TOKEN')) {
require 'contrib/sentry.php';
}

set('application', 'laravel-starter-tpl');
set('repository', 'git@github.com:wayofdev/laravel-starter-tpl.git');
set('base_deploy_path', '/home/ploi');
Expand Down Expand Up @@ -46,15 +42,6 @@ function getDefaultEnv(mixed $variable, mixed $default = null)
->set('slack_webhook', getDefaultEnv('DEPLOYER_PROD_SLACK_WEBHOOK'))
->set('sub_directory', 'app');

if (getenv('DEPLOYER_SENTRY_TOKEN')) {
set('sentry', [
'organization' => getDefaultEnv('DEPLOYER_SENTRY_ORG', 'wayofdev'),
'projects' => [getDefaultEnv('DEPLOYER_SENTRY_PROJECT', 'laravel-starter-tpl')],
'token' => getDefaultEnv('DEPLOYER_SENTRY_TOKEN'),
'sentry_server' => getDefaultEnv('DEPLOYER_SENTRY_SERVER', 'https://sentry.io/'),
]);
}

before('deploy', 'slack:notify');

task('deploy', [
Expand All @@ -69,13 +56,7 @@ function getDefaultEnv(mixed $variable, mixed $default = null)
'deploy:publish',
]);

after('deploy:failed', [
'deploy:unlock',
'slack:notify:failure',
]);
after('deploy:failed', 'deploy:unlock');
after('deploy:failed', 'slack:notify:failure');

after('deploy:success', 'slack:notify:success');

if (getenv('DEPLOYER_SENTRY_TOKEN')) {
after('deploy', 'deploy:sentry');
}

0 comments on commit 1386622

Please sign in to comment.