deploy main to staging #192
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, 'feat/**'] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
prepare: | |
name: Prepare | |
if: ${{ github.event_name != 'workflow_dispatch' || inputs.target != 'testing' }} | |
# uses: creasico/laravel-project/.github/workflows/prepare.yml@main | |
uses: ./.github/workflows/prepare.yml | |
secrets: inherit | |
with: | |
target: ${{ github.event_name == 'workflow_dispatch' && inputs.target || matrix.target }} | |
strategy: | |
matrix: | |
target: [staging] | |
deploy: | |
runs-on: ubuntu-latest | |
name: Deploy to ${{ needs.prepare.outputs.target-env }} | |
needs: prepare | |
environment: | |
name: ${{ needs.prepare.outputs.target-env }} | |
url: ${{ env.APP_URL }} | |
env: | |
APP_ENV: ${{ needs.prepare.outputs.target-env }} | |
APP_URL: ${{ needs.prepare.outputs.target-url }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 8.1 | |
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.1-composer-${{ hashFiles('**/composer.lock') }} | |
# restore-keys: php-8.1-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 }} |