diff --git a/.github/actions/setup-dependencies/action.yml b/.github/actions/setup-dependencies/action.yml new file mode 100644 index 0000000..73ae58f --- /dev/null +++ b/.github/actions/setup-dependencies/action.yml @@ -0,0 +1,47 @@ +name: Setup dependencies + +inputs: + path: + description: Path to the checked out project + required: true + setup-node: + description: Whether to setup Node or not + default: 'false' + +runs: + using: composite + steps: + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3.2' + + - name: Validate composer + run: composer validate + shell: bash + working-directory: ./${{ inputs.path }} + + - name: Cache composer + uses: actions/cache@v4 + with: + path: ${{ inputs.path }}/vendor + key: composer-v1-${{ inputs.path }}-${{ hashFiles(format('{0}/composer.lock', inputs.path))}} + + - name: Install composer dependencies + run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist + shell: bash + working-directory: ./${{ inputs.path }} + + - name: Setup node + if: inputs.setup-node == 'true' + uses: actions/setup-node@v4 + with: + cache: 'npm' + cache-dependency-path: ${{ inputs.path }} + + - name: Install node dependencies + if: inputs.setup-node == 'true' + run: npm ci + shell: bash + working-directory: ./${{ inputs.path }} \ No newline at end of file diff --git a/.github/actions/setup-project/action.yml b/.github/actions/setup-project/action.yml new file mode 100644 index 0000000..bfe8d1d --- /dev/null +++ b/.github/actions/setup-project/action.yml @@ -0,0 +1,45 @@ +name: Setup project + +inputs: + path: + description: Path to the checked out project + required: true + setup-node: + description: Whether to setup Node or not + default: 'false' + seed-database: + description: Whether to seed the database or not + default: 'false' +runs: + using: composite + steps: + - name: Copy .env.example if available + run: "[[ ! -f .env ]] && [[ -f .env.example ]] && /bin/cp -f .env.example .env" + shell: bash + working-directory: ./${{ inputs.path }} + + - name: Copy .env.ci if available + run: "[[ -f .env.ci ]] && /bin/cp -f .env.ci .env || echo No .env.ci detected" + shell: bash + working-directory: ./${{ inputs.path }} + + - name: Generate key + run: php artisan key:generate + shell: bash + working-directory: ./${{ inputs.path }} + + - name: Directory Permissions + run: chmod -R 777 storage bootstrap/cache + shell: bash + working-directory: ./${{ inputs.path }} + + - name: Create database and run migrations + run: php artisan migrate --force + shell: bash + working-directory: ./${{ inputs.path }} + + - name: Seed the database + if: inputs.seed-database == 'true' + run: php artisan db:seed + shell: bash + working-directory: ./${{ inputs.path }} \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 51f3c4b..d636de5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,5 +1,5 @@ --- -name: "Build" +name: "Test & Build" on: push: @@ -7,19 +7,19 @@ on: - "**.md" env: - IMAGE_NAME: vatsim-scandinavia/handover + IMAGE_NAME: vatsim-scandinavia/events TARGET_PLATFORMS: linux/amd64,linux/arm64 jobs: build-container: - name: Build Events Container + name: Build Event Manager Container runs-on: ubuntu-latest steps: - name: configure docker buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: login to github container registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -27,7 +27,7 @@ jobs: - name: setup container metadata id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: | ghcr.io/${{ env.IMAGE_NAME }} @@ -39,10 +39,38 @@ jobs: type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - name: build & push container image - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v6 with: context: "{{defaultContext}}:." push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - platforms: ${{ env.TARGET_PLATFORMS }} \ No newline at end of file + platforms: ${{ env.TARGET_PLATFORMS }} + + test-app: + name: Event Manager Test Suite + runs-on: ubuntu-latest + steps: + - name: Checkout Event Manager + uses: actions/checkout@v4 + with: + path: events + + - name: Setup dependencies for Event Manager + uses: ./events/.github/actions/setup-dependencies + with: + path: events + setup-node: true + + - name: Setup Event Manager + uses: ./events/.github/actions/setup-project + with: + path: events + setup-node: true + seed-database: true + env: + DB_CONNECTION: sqlite-testing + + - name: Execute unit and feature tests via PHPUnit + run: ./vendor/bin/phpunit --color=always --testdox + working-directory: ./events \ No newline at end of file diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml deleted file mode 100644 index fda52cb..0000000 --- a/.github/workflows/test-application.yaml +++ /dev/null @@ -1,53 +0,0 @@ -name: CI -on: - pull_request: - branches: - - main - push: - branches: - - main -jobs: - test: - name: Run PHPUnit Tests - runs-on: ubuntu-latest - - services: - mysql: - image: mysql:8.0 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: yes - MYSQL_DATABASE: laravel - ports: - - 3306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - extensions: mbstring, pdo, pdo_mysql - - - name: Install dependencies - run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - - - name: Install NPM dependencies - run: npm install - - - name: Compile assets - run: npm run build - - - name: Create .env file - run: cp .env.example .env - - - name: Generate application key - run: php artisan key:generate - - - name: Run migrations - run: php artisan migrate --force --no-interaction - - - name: Run tests - run: vendor/bin/phpunit \ No newline at end of file diff --git a/container/example-prod.env b/container/example-prod.env new file mode 100644 index 0000000..8f16346 --- /dev/null +++ b/container/example-prod.env @@ -0,0 +1,56 @@ +APP_NAME="Event Manager" +APP_OWNER_NAME="VATSIM Scandinavia" +APP_OWNER_NAME_SHORT="SCA" +APP_OWNER_CODE="SCA" + +APP_ENV=local +APP_KEY=base64:l9zh+pX5n9ueU/UW7TygDoMVJj14zBo0MM13smdcfL0= +APP_DEBUG=true +APP_URL='' + +APP_LOGO="vatsca.svg" + +LOG_CHANNEL=stack +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE='events' +DB_USERNAME='' +DB_PASSWORD='' + +OAUTH_ID="" +OAUTH_SECRET="" +OAUTH_URL="" + +# If you use custom OAuth you can map these data variables, leave blank for VATSIM Connect +OAUTH_MAPPING_CID=data-cid +OAUTH_MAPPING_EMAIL=data-personal-email +OAUTH_MAPPING_FIRSTNAME=data-personal-name_first +OAUTH_MAPPING_LASTNAME=data-personal-name_last + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +FILESYSTEM_DISK=local +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=10080 + +MEMCACHED_HOST=127.0.0.1 + +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}" + +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}"