deploy main to staging #210
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy | |
run-name: >- | |
deploy ${{ github.ref_name }} to ${{ github.event_name == 'workflow_dispatch' && inputs.target || 'staging' }} | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
inputs: | |
target: | |
description: Deployment target | |
required: true | |
type: environment | |
reset: | |
description: Reset database | |
default: false | |
type: boolean | |
workflow_run: | |
workflows: [Code Quality] | |
types: [completed] | |
branches: [main] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
prepare: | |
name: Prepare | |
uses: projek-xyz/actions/.github/workflows/configure.yml@main | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
with: | |
php-version: 8.2 | |
secrets: | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | |
build: | |
name: Build | |
needs: prepare | |
uses: projek-xyz/actions/.github/workflows/build.yml@main | |
secrets: | |
ACCESS_TOKEN: ${{ secrets.PAT }} | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
SENTRY_DSN: ${{ secrets.SENTRY_DSN }} | |
with: | |
branch: ${{ needs.prepare.outputs.target-branch }} | |
composer-cache: ${{ needs.prepare.outputs.composer-cache }} | |
composer-cache-key: ${{ needs.prepare.outputs.composer-cache-key }} | |
sentry-project: ${{ vars.SENTRY_PROJECT }} | |
target-env: ${{ github.event_name == 'workflow_dispatch' && inputs.target || matrix.target }} | |
target-url: ${{ vars.APP_URL }} | |
strategy: | |
matrix: | |
target: [staging] | |
deploy: | |
runs-on: ubuntu-latest | |
name: Deploy to ${{ needs.build.outputs.target-env }} | |
if: ${{ success() }} | |
needs: build | |
environment: | |
name: ${{ needs.build.outputs.target-env }} | |
url: ${{ needs.build.outputs.target-url }} | |
env: | |
APP_ENV: ${{ needs.build.outputs.target-env }} | |
APP_URL: ${{ needs.build.outputs.target-url }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 8.2 | |
extensions: curl, pcntl, ssh2, zip | |
tools: composer:v2 | |
coverage: none | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
- name: Download assets | |
id: download | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-${{ env.APP_ENV }} | |
path: public | |
- name: Prepare environment | |
env: | |
SSH_RSAKEY: ${{ secrets.DEPLOY_SSH_RSAKEY }} | |
SSH_CONFIG: ${{ secrets.DEPLOY_SSH_CONFIG }} | |
run: | | |
[[ ! -d $HOME/.ssh ]] && mkdir $HOME/.ssh | |
echo "$SSH_RSAKEY" >> $HOME/.ssh/id_rsa | |
echo "$SSH_CONFIG" >> $HOME/.ssh/config | |
chmod 600 $HOME/.ssh/* | |
- name: Deploy | |
run: | | |
git config --global user.name "Creasi.HQ" && git config --global user.email "[email protected]" | |
git clone creasi.co:~/git/creasico-skeleton.git storage/deploy-tmp | |
./scripts/deploy.sh ${{ env.APP_ENV }} | |
# - name: Cache Composer dependencies | |
# uses: actions/cache@v4 | |
# with: | |
# path: ${{ needs.prepare.outputs.composer-cache }} | |
# key: php-8.2-composer-${{ hashFiles('**/composer.lock') }} | |
# restore-keys: php-8.2-composer- | |
# - name: Install dependencies | |
# run: composer install --prefer-dist --no-interaction --no-progress --ansi | |
# - name: Deploy | |
# uses: deployphp/action@master | |
# env: | |
# DB_USERNAME: ${{ secrets.DB_USERNAME }} | |
# DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
# DB_RESET: ${{ github.event_name == 'workflow_dispatch' && inputs.reset || false }} | |
# DEPLOY_ARGS: --branch ${{ needs.prepare.outputs.target-branch }} --${{ env.DB_RESET == 'true' && 'reset' || 'no-reset' }} | |
# with: | |
# private-key: ${{ secrets.DEPLOY_SSH_RSAKEY }} | |
# ssh-config: ${{ secrets.DEPLOY_SSH_CONFIG }} | |
# verbosity: '' | |
# dep: deploy -f scripts/deploy.php env=staging ${{ env.DEPLOY_ARGS }} |