posthog update #7
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: Test and Deploy Application | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
ci: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@master | |
with: | |
php-version: 8.3 | |
extensions: mbstring, ctype, fileinfo, openssl, PDO, bcmath, json, tokenizer, xml | |
tools: composer:v2 | |
coverage: xdebug | |
- name: Composer install | |
run: | | |
composer install --no-interaction --prefer-dist --optimize-autoloader | |
- name: Install Dependencies | |
run: | | |
npm install | |
npm run build | |
- name: Stan | |
run: | | |
make stan | |
- name: Tests | |
run: | | |
touch database/database.sqlite | |
make test | |
create-deployment-matrix: | |
name: Create deployment matrix | |
runs-on: ubuntu-latest | |
needs: ci | |
outputs: | |
DEPLOYMENT_MATRIX: ${{ steps.export-deployment-matrix.outputs.DEPLOYMENT_MATRIX }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Export deployment matrix | |
id: export-deployment-matrix | |
run: | | |
delimiter="$(openssl rand -hex 8)" | |
JSON="$(cat ./deployment-config.json)" | |
echo "DEPLOYMENT_MATRIX<<${delimiter}" >> "${GITHUB_OUTPUT}" | |
echo "$JSON" >> "${GITHUB_OUTPUT}" | |
echo "${delimiter}" >> "${GITHUB_OUTPUT}" | |
prepare-release-on-servers: | |
name: "${{ matrix.server.name }}: Prepare release" | |
runs-on: ubuntu-latest | |
needs: create-deployment-matrix | |
strategy: | |
matrix: | |
server: ${{ fromJson(needs.create-deployment-matrix.outputs.DEPLOYMENT_MATRIX) }} | |
steps: | |
- name: Create directories | |
uses: appleboy/ssh-action@master | |
env: | |
GITHUB_SHA: ${{ github.sha }} | |
with: | |
host: ${{ matrix.server.ip }} | |
username: ${{ matrix.server.username }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ matrix.server.port }} | |
envs: GITHUB_SHA | |
script: | | |
mkdir -p "${{ matrix.server.path }}/releases/${GITHUB_SHA}" | |
rm -rf ${{ matrix.server.path }}/releases/${GITHUB_SHA}/storage | |
mkdir -p ${{ matrix.server.path }}/storage/{app,public,framework,logs} | |
mkdir -p ${{ matrix.server.path }}/storage/framework/{cache,sessions,testing,views} | |
chmod -R 0777 ${{ matrix.server.path }}/storage | |
activate-release: | |
name: "${{ matrix.server.name }}: Activate release" | |
runs-on: ubuntu-latest | |
needs: [ create-deployment-matrix, prepare-release-on-servers ] | |
strategy: | |
matrix: | |
server: ${{ fromJson(needs.create-deployment-matrix.outputs.DEPLOYMENT_MATRIX) }} | |
steps: | |
- name: Activate release | |
uses: appleboy/ssh-action@master | |
env: | |
GITHUB_SHA: ${{ github.sha }} | |
RELEASE_PATH: ${{ matrix.server.path }}/releases/${{ github.sha }} | |
ACTIVE_RELEASE_PATH: ${{ matrix.server.path }}/current | |
STORAGE_PATH: ${{ matrix.server.path }}/storage | |
BASE_PATH: ${{ matrix.server.path }} | |
ENV_SECRET: ${{ secrets.ENV_SECRET }} | |
with: | |
host: ${{ matrix.server.ip }} | |
username: ${{ matrix.server.username }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ matrix.server.port }} | |
envs: GITHUB_SHA,RELEASE_PATH,ACTIVE_RELEASE_PATH,STORAGE_PATH,BASE_PATH,ENV_SECRET | |
script: | | |
echo "$RELEASE_PATH" | |
cd $RELEASE_PATH && git clone git@github.com:antonL95/artistshero-laravel.git ./ | |
cd $RELEASE_PATH && composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader | |
cd $RELEASE_PATH && source $BASE_PATH/../.nvm/nvm.sh && npm install --no-progress && npm run build | |
rm -rf $RELEASE_PATH/storage | |
ln -s -f $STORAGE_PATH $RELEASE_PATH | |
/usr/bin/php $RELEASE_PATH/artisan env:decrypt --key=$ENV_SECRET --env=production | |
mv $RELEASE_PATH/.env.production $RELEASE_PATH/.env | |
/usr/bin/php $RELEASE_PATH/artisan migrate --force | |
/usr/bin/php $RELEASE_PATH/artisan route:clear | |
/usr/bin/php $RELEASE_PATH/artisan event:clear | |
/usr/bin/php $RELEASE_PATH/artisan view:clear | |
/usr/bin/php $RELEASE_PATH/artisan config:clear | |
/usr/bin/php $RELEASE_PATH/artisan route:cache | |
/usr/bin/php $RELEASE_PATH/artisan event:cache | |
ln -s -n -f $RELEASE_PATH $ACTIVE_RELEASE_PATH | |
sudo systemctl restart php8.3-fpm |