From f09793d6c2d1587595a688ca765b309de47950d9 Mon Sep 17 00:00:00 2001 From: Fady Mondy Date: Mon, 12 Feb 2024 11:44:07 +0200 Subject: [PATCH] add github workflow --- .github/workflows/ci.yaml | 86 +++++++++++++++++++++++++++++++++++++++ .scripts/deploy.sh | 33 +++++++++++++++ ubuntu-22-install-script | 30 ++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100755 .scripts/deploy.sh create mode 100755 ubuntu-22-install-script diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..ce34f3d --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,86 @@ +name: Tomato CI/CD +on: + pull_request: + branches: + - master + push: + branches: + - master +jobs: + laravel: + name: Laravel (PHP ${{ matrix.php-versions }}) + runs-on: ubuntu-latest + env: + DB_DATABASE: laravel + DB_USERNAME: root + DB_PASSWORD: password + services: + mysql: + image: mysql:latest + env: + MYSQL_ALLOW_EMPTY_PASSWORD: false + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: laravel + ports: + - 3306/tcp + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + redis: + image: redis + ports: + - 6379/tcp + options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3 + strategy: + fail-fast: false + matrix: + php-versions: ['8.2'] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: sqlite, pdo_sqlite, pcntl, zip, intl, exif, mbstring, dom, fileinfo, mysql + coverage: xdebug + + - name: Copy .env Before Install Composer + run: php -r "file_exists('.env') || copy('.env.example', '.env'); echo file_get_contents('.env');" + + - name: Start MySQL Service + run: sudo /etc/init.d/mysql start + + - 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 }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install Composer dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Generate Applications Key + run: php artisan key:generate + + - name: Clear Config + run: php artisan config:clear + + - name: Run Migration + run: php artisan migrate -v + env: + DB_PORT: ${{ job.services.mysql.ports['3306'] }} + REDIS_PORT: ${{ job.services.redis.ports['6379'] }} + + - name: Install Yarn dependencies + run: yarn + + - name: Compile assets + run: yarn build diff --git a/.scripts/deploy.sh b/.scripts/deploy.sh new file mode 100755 index 0000000..f942dbd --- /dev/null +++ b/.scripts/deploy.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +echo "Deployment started ..." + +# Enter maintenance mode or return true +# if already is in maintenance mode +(php artisan down) || true + +# Pull the latest version of the app +git reset --hard +git pull origin master + +# Install composer dependencies +composer install + +# Clear the old cache +php8.2 artisan clear-compiled + +# Recreate cache +php8.2 artisan optimize + +# Compile npm assets +yarn +yarn build + +# Run database migrations +php8.2 artisan migrate --force + +# Exit maintenance mode +php8.2 artisan up + +echo "Deployment finished!" diff --git a/ubuntu-22-install-script b/ubuntu-22-install-script new file mode 100755 index 0000000..01a7369 --- /dev/null +++ b/ubuntu-22-install-script @@ -0,0 +1,30 @@ +#!/bin/bash +sudo add-apt-repository ppa:ondrej/php +sudo apt-get update +sudo apt-get -y install curl git network-manager libnss3-tools jq xsel software-properties-common php8.2-fpm php8.2-cli php8.2-bcmath php8.2-common php8.2-curl php8.2-mbstring php8.2-opcache php8.2-readline php8.2-xml php8.2-zip php8.2-mysql php8.2-gd mysql-server supervisor +sudo mysql -e "create database bing;" +sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678';" +sudo mysql -e "FLUSH PRIVILEGES;" +curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer +composer --version +composer global require genesisweb/valet-linux-plus +export PATH="$PATH:$HOME/.config/composer/vendor/bin" +valet install +cd ~/Sites/bing +composer install +cp .env.example .env +php artisan key:generate +php artisan config:cache +valet link +valet secure +php artisan migrate +php artisan config:cache +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +nvm install 18 +nvm use 18 +npm -g i yarn +yarn +yarn build +valet open