From 138662290b879a91a8c4be43c9531960f17bac92 Mon Sep 17 00:00:00 2001 From: lotyp Date: Tue, 9 May 2023 14:19:07 +0300 Subject: [PATCH] feat: separate deployment workflows --- .github/workflows/deploy_release.yml | 76 +++++++++++++++++++ .../{deployment.yml => deploy_staging.yml} | 48 +++++------- app/deploy.php | 23 +----- 3 files changed, 96 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/deploy_release.yml rename .github/workflows/{deployment.yml => deploy_staging.yml} (57%) diff --git a/.github/workflows/deploy_release.yml b/.github/workflows/deploy_release.yml new file mode 100644 index 00000000..44abf944 --- /dev/null +++ b/.github/workflows/deploy_release.yml @@ -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 + +... diff --git a/.github/workflows/deployment.yml b/.github/workflows/deploy_staging.yml similarity index 57% rename from .github/workflows/deployment.yml rename to .github/workflows/deploy_staging.yml index 1a4da4f1..eb2603e1 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deploy_staging.yml @@ -3,10 +3,9 @@ on: # yamllint disable-line rule:truthy push: branches: - - master - develop -name: 📦 Deploy to server +name: 📦 Deploy to staging defaults: run: @@ -14,12 +13,12 @@ defaults: 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 @@ -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 @@ -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 }} @@ -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 + +... diff --git a/app/deploy.php b/app/deploy.php index 89c1f404..3ef49ff7 100644 --- a/app/deploy.php +++ b/app/deploy.php @@ -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'); @@ -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', [ @@ -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'); -}