From 6b21932da89bd8498a98510b2cdd91c97ad3f858 Mon Sep 17 00:00:00 2001 From: aaron Date: Sat, 10 Feb 2024 15:58:33 -0600 Subject: [PATCH] WIP: build: set up GitHub actions --- .env.testing | 59 ++++++++++++ .github/workflows/ci.yml | 199 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 .env.testing create mode 100644 .github/workflows/ci.yml diff --git a/.env.testing b/.env.testing new file mode 100644 index 0000000..872a52d --- /dev/null +++ b/.env.testing @@ -0,0 +1,59 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=pgsql +DB_HOST=pgsql +DB_PORT=5432 +DB_DATABASE=simple_slides_app +DB_USERNAME=root +DB_PASSWORD=secret + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +FILESYSTEM_DISK=local +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +MEMCACHED_HOST=127.0.0.1 + +REDIS_HOST=redis +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=mailpit +MAIL_PORT=1025 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS="hello@example.com" +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_HOST= +PUSHER_PORT=443 +PUSHER_SCHEME=https +PUSHER_APP_CLUSTER=mt1 + +VITE_APP_NAME="${APP_NAME}" +VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +VITE_PUSHER_HOST="${PUSHER_HOST}" +VITE_PUSHER_PORT="${PUSHER_PORT}" +VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" +VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ddb37b4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,199 @@ +name: ci + +on: push + +env: + php_version: "8.2" + node_version: "20.x" + +jobs: + frontend-lint: + name: Front-end Lint + runs-on: ubuntu-latest + steps: + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.node_version }} + - name: Checkout code + uses: actions/checkout@v4 + - name: Cache frontend dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install npm dependencies + run: npm ci --prefer-offline + - name: Run Typescript lint + run: node_modules/.bin/vue-tsc + backend-lint: + name: Back-end Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ env.php_version }} + extensions: bcmath, dom, fileinfo, gd, imagick, mbstring, pgsql, zip + tools: composer, pecl + - name: Get composer cache directory + id: composer-cache + run: | + printf '::set-output name=dir::%s' "$(composer config cache-files-dir)" + - name: Cache Composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install Composer dependencies + run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + - name: PHP Lint + run: ./vendor/bin/phpstan analyse + frontend-test: + name: Front-end Test + runs-on: ubuntu-latest + steps: + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.node_version }} + - name: Checkout code + uses: actions/checkout@v4 + - name: Cache frontend dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install npm dependencies + run: npm ci --prefer-offline + - name: Run Vitest + run: node_modules/.bin/vitest --run + backend-test: + name: Back-end Test + runs-on: ubuntu-latest + env: + BROADCAST_DRIVER: log + CACHE_DRIVER: redis + DB_CONNECTION: pgsql + DB_DATABASE: laravel + DB_HOST: localhost + DB_PASSWORD: password + DB_USERNAME: username + QUEUE_CONNECTION: redis + REDIS_HOST: localhost + SESSION_DRIVER: redis + services: + postgres: + image: postgres:11-alpine + env: + POSTGRES_USER: username + POSTGRES_PASSWORD: password + POSTGRES_DB: laravel + ports: + - 5432/tcp + options: --health-cmd pg_isready --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 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ env.php_version }} + extensions: bcmath, dom, fileinfo, gd, imagick, mbstring, pgsql, zip + coverage: xdebug + tools: composer, pecl + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.node_version }} + - name: Get composer cache directory + id: composer-cache + run: | + printf '::set-output name=dir::%s' "$(composer config cache-files-dir)" + - name: Cache Composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - name: Prepare the application + env: + DB_PORT: ${{ job.services.postgres.ports[5432] }} + REDIS_PORT: ${{ job.services.redis.ports[6379] }} + run: | + cp .env.testing .env + rm -f .env.testing + echo "DB_PORT=$DB_PORT" >> $GITHUB_ENV + echo "REDIS_PORT=$REDIS_PORT" >> $GITHUB_ENV + - name: Install Composer dependencies + run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + - name: Cache frontend dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install npm dependencies + run: npm ci --prefer-offline + - name: Publish public assets + run: php artisan vendor:publish --tag=public + - name: Build frontend + run: npm run build + - name: Generate app key + run: php artisan key:generate + - name: Clear Config + run: php artisan config:clear + - name: Run Migration + run: php artisan migrate -v + - name: Test with pest + run: vendor/bin/pest + build: + name: Build + needs: ['frontend-lint', 'backend-lint', 'frontend-test', 'backend-test'] + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: alkrauss48/simple-slides-sail + tags: | + type=ref,prefix=dev-,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + id: docker_build + uses: docker/build-push-action@v4 + with: + context: . + file: docker/sail-prod/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}