Skip to content

Commit

Permalink
Merge branch 'feat-deployer-actions'
Browse files Browse the repository at this point in the history
* feat-deployer-actions:
  chore(deploy): ensure `deploy:assets` has same connection string as the current host
  test(ci): try using `deployphp/action` again
  chore(ci): inherits the secrets
  test(ci): workaround with organization secrets for deployment
  feat: initialize `deployphp/action` as deployment tool
  • Loading branch information
feryardiant committed Jul 12, 2023
2 parents b08828d + 812c220 commit 28d3041
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 92 deletions.
60 changes: 24 additions & 36 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:

env:
APP_NAME: ${{ vars.APP_NAME }}
APP_ENV: staging
APP_KEY: ${{ secrets.APP_KEY }}
APP_LOCALE: id
VITE_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
Expand All @@ -19,7 +18,7 @@ concurrency:
cancel-in-progress: true

jobs:
build-deploy:
deploy:
runs-on: ubuntu-latest
name: Build and Deploy

Expand All @@ -29,11 +28,7 @@ jobs:

env:
APP_URL: ${{ vars.APP_URL }}

strategy:
fail-fast: false
matrix:
php: ['8.1']
APP_ENV: ${{ vars.APP_ENV }}

steps:
- name: Checkout
Expand All @@ -44,20 +39,27 @@ jobs:
- name: Prepare Environments
run: |
echo "GIT_BRANCH=$(echo ${GIT_BRANCH##*/} | tr / -)" >> $GITHUB_ENV
[[ ! -d $HOME/.ssh ]] && mkdir $HOME/.ssh
echo "${{ secrets.STAGING_SERVER_RSAKEY }}" >> $HOME/.ssh/id_rsa
echo "${{ secrets.STAGING_SERVER_SSH_CONFIG }}" >> $HOME/.ssh/config
chmod 600 $HOME/.ssh/* && ls -al $HOME/.ssh/
git config user.name "Creasi.HQ" && git config user.email "dev@creasi.co"
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
php-version: 8.1
extensions: curl, intl, libxml, mbstring, pcntl, ssh2, zip
tools: composer:v2
coverage: none

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Setup node.js
uses: actions/setup-node@v3
with:
cache: pnpm
node-version: 18.x

- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
Expand All @@ -66,8 +68,8 @@ jobs:
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-composer-
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install PHP dependencies
uses: nick-invision/retry@v2
Expand All @@ -79,29 +81,15 @@ jobs:
composer install --prefer-dist --no-interaction --no-progress
composer ziggy:generate
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Setup Node.JS
uses: actions/setup-node@v3
with:
cache: pnpm
node-version: 18.x

- name: Install Node.JS dependencies
- name: Install node.js dependencies
run: pnpm install

- name: Build frontend assets
run: pnpm build
- name: Build frontend
run: pnpm build --mode ${{ vars.APP_ENV }}

- name: Deploy repo
uses: nick-invision/retry@v2
- name: Deploy
uses: deployphp/action@v1
with:
timeout_minutes: 2
max_attempts: 3
command: |
composer dep deploy:unlock
composer dep deploy
private-key: ${{ secrets.STAGING_SERVER_RSAKEY }}
ssh-config: ${{ secrets.STAGING_SERVER_SSH_CONFIG }}
dep: deploy -f scripts/deploy.php
98 changes: 46 additions & 52 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,53 +39,50 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.1
extensions: curl, dom, gd, imagick, intl, libxml, mbstring, pcntl, pdo, pdo_pgsql, zip
tools: composer:v2
coverage: none

- name: Get Composer cache directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 3
command: |
composer install --prefer-dist --no-interaction --no-progress
composer ziggy:generate
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Setup Node.JS
- name: Setup node.js
uses: actions/setup-node@v3
with:
cache: pnpm
node-version: 18.x
registry-url: https://registry.npmjs.org

- name: Install dependencies
- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install PHP dependencies
run: |
composer config -g github-oauth.github.com ${{ secrets.PAT }}
composer install --prefer-dist --no-interaction --no-progress
composer ziggy:generate
- name: Install node.js dependencies
run: pnpm install

- name: Build assets
run: pnpm build
- name: Build frontend
run: pnpm build --mode ${{ env.APP_ENV }}

- name: Store assets
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -115,7 +112,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2']
php: [8.1, 8.2]

steps:
- name: Checkout sources
Expand All @@ -139,30 +136,28 @@ jobs:

- name: Get Composer cache directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-composer-
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 3
command: composer update --prefer-dist --no-interaction --no-progress
- name: Install PHP dependencies
run: |
composer config -g github-oauth.github.com ${{ secrets.PAT }}
composer update --prefer-dist --no-interaction --no-progress
composer ziggy:generate
- name: Run unit tests
run: php artisan test --coverage

- name: Generate reports for CodeClimate
env:
COVERAGE_FILE: tests/reports/clover.xml
CODECLIMATE_REPORT: ${{ github.workspace }}/tests/reports/codeclimate.${{ matrix.php }}.json
CODECLIMATE_REPORT: tests/reports/codeclimate.${{ matrix.php }}.json
run: |
curl -LSs $CC_TEST_REPORTER_URL > ./cc-test-reporter && chmod +x ./cc-test-reporter
./cc-test-reporter format-coverage -t clover -o $CODECLIMATE_REPORT $COVERAGE_FILE
Expand Down Expand Up @@ -202,7 +197,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.1
extensions: curl, dom, gd, igbinary, imagick, intl, libxml, mbstring, pcntl, pdo, pdo_pgsql, zip
ini-values: error_reporting=E_ALL
tools: composer:v2
Expand All @@ -217,22 +212,20 @@ jobs:

- name: Get Composer cache directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 3
command: composer install --prefer-dist --no-interaction --no-progress
- name: Install PHP dependencies
run: |
composer config -g github-oauth.github.com ${{ secrets.PAT }}
composer install --prefer-dist --no-interaction --no-progress
composer ziggy:generate
- name: Setup BrowserStack env # Invokes the setup-env action
uses: browserstack/github-actions/setup-env@master
Expand Down Expand Up @@ -277,15 +270,16 @@ jobs:
uses: actions/download-artifact@v3
with:
name: test-reports
path: tests

- name: Report to CodeClimate
run: |
curl -LSs $CC_TEST_REPORTER_URL > ./cc-test-reporter && chmod +x ./cc-test-reporter
./cc-test-reporter sum-coverage -o - tests/reports/codeclimate.*.json | ./cc-test-reporter upload-coverage --input -
./cc-test-reporter sum-coverage -o - reports/codeclimate.*.json | ./cc-test-reporter upload-coverage --input -
deploy:
name: Deployment
needs: e2e
uses: creasico/laravel-project/.github/workflows/deploy.yml@main
# uses: creasico/laravel-project/.github/workflows/deploy.yml@main
uses: ./.github/workflows/deploy.yml
secrets: inherit
# if: ${{ github.ref_name == 'main' && github.event_name == 'push' }}
9 changes: 5 additions & 4 deletions scripts/deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
// Hosts

host('creasi.dev')
->set('remote_user', 'creasi')
->set('remote_user', 'deployer')
->set('deploy_path', '/var/www/skeleton');

// Tasks

desc('Deploy static assets');
task('deploy:assets', function () {
runLocally('rsync -zrtv ../public/build/* creasi.dev:{{release_or_current_path}}/public/build');
});
$host = currentHost();

runLocally("rsync -zrtv ../public/build/* {$host->connectionString()}:{{release_or_current_path}}/public/build");
})->desc('Deploy static assets');

// Hooks

Expand Down

0 comments on commit 28d3041

Please sign in to comment.