diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..93421a7 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "composer" + directory: "/" # Location of package manifests + schedule: + interval: "daily" + + - package-ecosystem: "npm" + directory: "/" # Location of package manifests + schedule: + interval: "daily" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..d2bbd19 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,87 @@ +name: Build +on: + workflow_call: + +jobs: + build-php: + # See https://docs.github.com/en/actions/writing-workflows/choosing-where-your-workflow-runs/choosing-the-runner-for-a-job#standard-github-hosted-runners-for-public-repositories + runs-on: ubuntu-24.04 + environment: testing + + strategy: + matrix: + operating-system: [ ubuntu-24.04 ] + # Limited by https://github.com/shivammathur/setup-php#github-hosted-runners + php-version: [ '8.3' ] + dependency-stability: [ prefer-stable ] + + name: build-laravel - PHP ${{ matrix.php-version }} (${{ matrix.operating-system }}) + + steps: + - uses: actions/checkout@v4.1.7 # Even better: using @ + + - name: Install PHP + uses: shivammathur/setup-php@2.31.1 + with: + php-version: ${{ matrix.php-version }} + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v4.0.2 + id: actions-cache + with: + path: ${{ steps.composer-cache.outputs.dir }} + # could be extended in case multiple PHP versions are in use + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Restore vendor from cache + uses: actions/cache@v4.0.2 + id: vendor-cache + with: + path: vendor + key: ${{ runner.os }}-build-${{ hashFiles('**/composer.lock') }} + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Install PHP Dependencies + if: steps.vendor-cache.outputs.cache-hit != 'true' + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + + - name: Directory Permissions + run: chmod -R 777 storage bootstrap/cache + + build-node: + runs-on: ubuntu-24.04 + environment: testing + + strategy: + matrix: + operating-system: [ ubuntu-24.04 ] + + steps: + - uses: actions/checkout@v4.1.7 # Even better: using @ + + - name: Setup Node + uses: actions/setup-node@v4.0.4 + with: + node-version: 20 + cache: 'npm' + + - name: Install Node Dependencies + # TODO: Test, whether --ignore-scripts work here, as this is helping in hardening (preventing postinstall scripts) + run: npm ci + + - name: Build Frontend Assets + run: npm run build + + - name: Upload Build Artifacts + uses: actions/upload-artifact@v4.4.0 + with: + name: eventguru-build-${{ github.run_id }} + path: public/build diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index dbeda2d..c4ea880 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,4 +1,4 @@ -name: Test Laravel Github action +name: Tests on: pull_request: branches: @@ -14,67 +14,56 @@ env: DB_DATABASE: testing jobs: - laravel-tests: + build: + uses: './.github/workflows/build.yaml' + + php-tests: + needs: [ build ] # See https://docs.github.com/en/actions/writing-workflows/choosing-where-your-workflow-runs/choosing-the-runner-for-a-job#standard-github-hosted-runners-for-public-repositories runs-on: ubuntu-24.04 environment: testing strategy: matrix: - operating-system: [ubuntu-24.04] + operating-system: [ ubuntu-24.04 ] # Limited by https://github.com/shivammathur/setup-php#github-hosted-runners - php-versions: [ '8.3' ] + php-version: [ '8.3' ] dependency-stability: [ prefer-stable ] - name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}} + name: php-tests - PHP ${{ matrix.php-version }} (${{ matrix.operating-system }}) steps: - - uses: actions/checkout@v4.1.7 # Even better: using @ + - uses: actions/checkout@v4.1.7 - - name: Start MySQL service - run: sudo systemctl start mysql.service + - name: Start MySQL service & create testing database + run: | + sudo systemctl start mysql.service + mysql -e "CREATE DATABASE IF NOT EXISTS $DB_DATABASE;" -u"$DB_USER" -p"$DB_PASSWORD" - - name: Install PHP versions + - name: Install PHP uses: shivammathur/setup-php@2.31.1 with: - php-version: ${{ matrix.php-versions }} + php-version: ${{ matrix.php-version }} - - name: Setup Node - uses: actions/setup-node@v4 + - name: Download build artifact + id: download-build-artifact + uses: actions/download-artifact@v4.1.8 with: - node-version: 20 - cache: 'npm' - - - name: Get Composer Cache Directory - id: composer-cache - run: | - echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + # Pick up the folder from build.yaml Upload (name must match) + name: eventguru-build-${{ github.run_id }} + path: public/build - - uses: actions/cache@v4.0.2 - id: actions-cache - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: Cache PHP dependencies + - name: Restore vendor from Cache uses: actions/cache@v4.0.2 id: vendor-cache with: path: vendor key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }} - - name: Install PHP Dependencies - if: steps.vendor-cache.outputs.cache-hit != 'true' - run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - - - name: Install Node Dependencies - # TODO: Test, whether --ignore-scripts work here, as this is helping in hardening (preventing postinstall scripts) - run: npm ci - - - name: Directory Permissions - run: chmod -R 777 storage bootstrap/cache + - name: Prepare Laravel Application + run: | + php -r "file_exists('.env') || copy('.env.example', '.env');" + php artisan key:generate - name: Prepare Laravel Application run: | @@ -84,8 +73,5 @@ jobs: - name: Run Migrations run: php artisan migrate - - name: Build Frontend Assets - run: npm run build - - name: Execute tests (Unit and Feature tests) via PestPHP run: php artisan test