From fbabdb6bcc1c6a1942cde075a820a9facbe25865 Mon Sep 17 00:00:00 2001 From: Curtis Delicata Date: Thu, 13 Jun 2024 03:11:42 +0000 Subject: [PATCH] Update workflows, setup.sh and env.testing --- .env.testing | 70 +++++++++++++++++++ .github/workflows/install.yml | 53 ++++++++++++++ .github/workflows/main.yml | 122 ++------------------------------- .github/workflows/security.yml | 56 +++++++++++++++ .github/workflows/tests.yml | 54 +++++++++++++++ setup.sh | 111 ++++++++++++++++++++++++++++++ 6 files changed, 349 insertions(+), 117 deletions(-) create mode 100644 .env.testing create mode 100644 .github/workflows/install.yml create mode 100644 .github/workflows/security.yml create mode 100644 .github/workflows/tests.yml create mode 100644 setup.sh diff --git a/.env.testing b/.env.testing new file mode 100644 index 00000000..5e7f353b --- /dev/null +++ b/.env.testing @@ -0,0 +1,70 @@ +APP_NAME=Liberu +APP_ENV=testing +APP_KEY=base64:GS0VwCqzgSVBnM0Wz/Ig610q86M+GIvyVmzQQvrL7Xw= +APP_DEBUG=true +APP_URL=http://localhost + +OWNER_COMPANY_ID=1 +DB_TENANT_DATABASE=tenant + +LOG_CHANNEL=stack + +DB_CONNECTION=mysql +DB_HOST=localhost +DB_PORT=3306 +DB_DATABASE=liberu +DB_USERNAME=root +DB_PASSWORD=root + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +FILESYSTEM_DISK=local +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +CACHE_LIFETIME=60 + +LOGIN_ATTEMPTS_PER_MINUTE=5 +PASSWORD_LIFETIME=0 +PASSWORD_MIN_LENGTH=6 +PASSWORD_MIXED_CASE=0 +PASSWORD_NUMERIC=0 +PASSWORD_SPECIAL=0 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=log +MAIL_HOST= +MAIL_PORT= +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME="${APP_NAME}" + +MAILGUN_DOMAIN= +MAILGUN_SECRET= +MAILGUN_ENDPOINT=api.mailgun.net + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +SENTRY_LARAVEL_DSN= + +TELESCOPE_ENABLED=0 +SCOUT_DRIVER=null + +ENSO_API_TOKEN= + +TINY_MCE_API_KEY= + +SANCTUM_STATEFUL_DOMAINS=localhost,127.0.0.1,127.0.0.1:8000,127.0.0.1:3000,localhost:3000,localhost:8080,::1 diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml new file mode 100644 index 00000000..65d6a845 --- /dev/null +++ b/.github/workflows/install.yml @@ -0,0 +1,53 @@ +name: Install + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + + install: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + + - name: Start database + run: sudo /etc/init.d/mysql start + + - name: Create database + run: mysql -e "CREATE DATABASE IF NOT EXISTS liberu;" -uroot -proot + + - name: Copy environment file + run: cp .env.testing .env + + - name: Install dependencies + run: composer install + + - name: Generate application key + run: php artisan key:generate + + - name: Run database migrations + run: php artisan migrate + + - name: Seed database + run: php artisan db:seed + + - name: Install npm dependencies + run: npm install + + - name: Build frontend assets + run: npm run build diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 83d46c47..3c4bed90 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,10 +1,10 @@ -name: CI +name: Docker on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] deployment: workflow_dispatch: @@ -14,118 +14,6 @@ env: DB_PASSWORD: secret jobs: - yarn: - runs-on: ubuntu-22.04 - env: - NODE_OPTIONS: --max_old_space_size=3072 - SENTRY_ORG: ${{ secrets.SENTRY_ORG }} - SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} - SENTRY_URL: ${{ secrets.SENTRY_URL }} - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: '14' - - uses: borales/actions-yarn@v4 - with: - cmd: install - - uses: shivammathur/setup-php@v2 - with: - php-version: '8.2' - - name: 'test node' - run: node -v - - name: 'install & build' - run: | - sudo composer install - sed -i 's/GOOGLE_ANALITICS_TOKEN/${{ secrets.GOOGLE_ANALITICS_TOKEN }}/g' resources/views/stubs/production-index.blade.stub - sudo cp -f resources/views/stubs/production-index.blade.stub vendor/laravel-liberu/core/stubs - - name: Archive production artifacts - uses: actions/upload-artifact@v3 - with: - name: resources - path: | - public/css/ - public/js/ - public/images/ - resources/views - - phpunit: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - - name: 'PhpUnit' - run: | - sudo composer install - sudo php artisan test - - phpcpd: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - - name: 'Run Phpcpd' - run: | - sudo composer install - sudo test -f phpcpd.phar || curl -L https://phar.phpunit.de/phpcpd.phar -o phpcpd.phar - sudo php phpcpd.phar app/ - - php-insights: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - - name: 'Run php-insight' - run: | - sudo composer install - sudo php artisan insights --min-quality=90 --min-complexity=90 --min-architecture=80 --min-style=90 --no-interaction - - security: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - - name: 'Run php-insight' - run: | - PHP_SC_VERSION=$(curl -s "https://api.github.com/repos/fabpot/local-php-security-checker/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/;s/^v//') - curl -LSs https://github.com/fabpot/local-php-security-checker/releases/download/v${PHP_SC_VERSION}/local-php-security-checker_${PHP_SC_VERSION}_linux_amd64 > ./php-security-checker - chmod +x ./php-security-checker - unset PHP_SC_VERSION - ./php-security-checker - migration: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - - uses: mirromutth/mysql-action@v1.1 - with: - mysql database: ${{env.DB_DATABASE}} - mysql user: ${{env.DB_USERNAME}} - mysql password: ${{env.DB_PASSWORD}} - - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - - name: 'Run migration' - run: | - sudo composer install - php artisan migrate --force - deploy: - runs-on: ubuntu-22.04 - if: ${{ github.event_name == 'deployment' || github.event_name == 'push' }} - needs: [phpunit, phpcpd, migration, yarn, security, php-insights] - steps: - - uses: actions/checkout@v4 - - name: 'Trig envoyer' - run: | - curl ${{ secrets.DEPLOY_WEBHOOK }} docker: if: github.event_name == 'push' runs-on: ubuntu-latest @@ -151,10 +39,10 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Build and push Docker image - uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 + uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 with: # context: "{{defaultContext}}:.docker/prod/app/" file: Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml new file mode 100644 index 00000000..436f39a5 --- /dev/null +++ b/.github/workflows/security.yml @@ -0,0 +1,56 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + deployment: + workflow_dispatch: + +env: + DB_DATABASE: liberu + DB_USERNAME: liberu + DB_PASSWORD: secret + +jobs: + + phpcpd: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + - name: 'Run Phpcpd' + run: | + sudo composer install + sudo test -f phpcpd.phar || curl -L https://phar.phpunit.de/phpcpd.phar -o phpcpd.phar + sudo php phpcpd.phar app/ + + php-insights: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + - name: 'Run php-insight' + run: | + sudo composer install + sudo php artisan insights --min-quality=90 --min-complexity=90 --min-architecture=80 --min-style=90 --no-interaction + + security: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + - name: 'Run php-insight' + run: | + PHP_SC_VERSION=$(curl -s "https://api.github.com/repos/fabpot/local-php-security-checker/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/;s/^v//') + curl -LSs https://github.com/fabpot/local-php-security-checker/releases/download/v${PHP_SC_VERSION}/local-php-security-checker_${PHP_SC_VERSION}_linux_amd64 > ./php-security-checker + chmod +x ./php-security-checker + unset PHP_SC_VERSION + ./php-security-checker diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..71d352b4 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,54 @@ +name: Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + + tests: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + + + - name: Start database + run: sudo /etc/init.d/mysql start + + - name: Create database + run: mysql -e "CREATE DATABASE IF NOT EXISTS liberu;" -uroot -proot + + - name: Copy environment file + run: cp .env.testing .env + + - name: Install dependencies + run: composer install + + - name: Generate application key + run: php artisan key:generate + + - name: Run database migrations + run: php artisan migrate + + - name: Seed database + run: php artisan db:seed + + - name: Run tests + run: vendor/bin/phpunit --coverage-clover=coverage.xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.xml + flags: unittests + name: codecov-umbrella + fail_ci_if_error: true + run: vendor/bin/phpunit --coverage-clover=coverage.xml diff --git a/setup.sh b/setup.sh new file mode 100644 index 00000000..ce7e4b53 --- /dev/null +++ b/setup.sh @@ -0,0 +1,111 @@ +#!/bin/bash +# Setup script for the genealogy-laravel project. +# +# This script prepares the project environment by copying the .env.example to .env (if necessary), +# installing dependencies, generating application keys, running database migrations, seeding the database, +# and executing Laravel optimization commands. It ensures the application is ready for development or production use. +clear +echo "==================================" +echo "===== USER: [$(whoami)]" +echo "===== [PHP $(php -r 'echo phpversion();')]" +echo "==================================" +echo "" +echo "" +echo "==================================" +echo "===== PREPARING YOUR PROJECT..." +echo "==================================" +echo "" +# Setup the .env file +copy=true +while $yn; do + read -p "🎬 DEV ---> DID YOU WANT TO COPY THE .ENV.EXAMPLE TO .ENV? (y/n) " yn + case $yn in + [Yy]* ) echo -e "\e[92mCopying .env.example to .env \e[39m"; cp .env.example .env; copy=true; break;; + [Nn]* ) echo -e "\e[92mContinuing with your .env configuration \e[39m"; copy=false; break;; + * ) echo "Please answer yes or no."; copy=true; ;; + esac +done +echo "" +echo "==================================" +echo "" +echo "" +# Ask user to confirm that .env file is properly setup before continuing +if [ "$copy" = true ]; then + answ=true + while $cond; do + read -p "🎬 DEV ---> DID YOU SETUP YOUR DATABASE CREDENTIALS IN THE .ENV FILE? (y/n) " cond + case $cond in + [Yy]* ) echo -e "\e[92mPerfect let's continue with the setup"; answ=false; break;; + [Nn]* ) exit;; + * ) echo "Please answer yes or no."; answ=false; ;; + esac + done +fi +echo "" +echo "==================================" +echo "" +echo "" +# Install laravel dependencies with composer +echo "🎬 DEV ---> COMPOSER INSTALL" +composer install +echo "" +echo "==================================" +echo "" +echo "" +# Generate larave key +echo "🎬 DEV ---> PHP ARTISAN KEY:GENERATE" +php artisan key:generate +echo "" +echo "==================================" +echo "" +echo "" +# Run database migrations +echo "🎬 DEV ---> php artisan migrate:fresh" +php artisan migrate:fresh +echo "" +echo "" +echo "==================================" +echo "" +echo "" +# Seeding database +echo "🎬 DEV ---> php artisan db:seed" +if ! php artisan db:seed; then + echo "Database seeding failed." + exit 1 +fi +php artisan db:seed +if ! php artisan db:seed; then + echo "Database seeding failed." + exit 1 +fi +php artisan db:seed +echo "" + + echo "🎬 DEV ---> Running PHPUnit tests" + if ! ./vendor/bin/phpunit; then + echo "PHPUnit tests failed." + exit 1 + fi +echo "" +echo "==================================" +echo "" +echo "" +# Run optimization commands for laravel +echo "🎬 DEV ---> php artisan optimize:clear" +php artisan optimize:clear +php artisan route:clear +echo "" +echo "" +echo "\e[92m==================================\e[39m" +echo "\e[92m============== DONE ==============\e[39m" +echo "\e[92m==================================\e[39m" +echo "" +echo "" +while $cond; do + read -p "🎬 DEV ---> DID YOU WANT TO START THE SERVER? (y/n) " cond + case $cond in + [Yy]* ) echo -e "\e[92mStarting server\e[39m"; php artisan serve; break;; + [Nn]* ) exit;; + * ) echo "Please answer yes or no."; ;; + esac +done