From 39aa842a2761c90134fae402522a43c46a5d01e1 Mon Sep 17 00:00:00 2001 From: Tenzin khenrab Date: Thu, 4 Jun 2026 10:44:46 +0530 Subject: [PATCH 1/8] github workflows --- .github/workflows/deploy.yml | 61 +++++++++--------------------------- .github/workflows/lint.yml | 48 ++++++++++++++++++---------- .github/workflows/tests.yml | 56 +++++++++++++++++++-------------- 3 files changed, 78 insertions(+), 87 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 320c3f8..e457871 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,67 +29,32 @@ jobs: --health-timeout=5s --health-retries=10 - defaults: - run: - working-directory: backend - steps: - - name: Checkout code - uses: actions/checkout@v6 + - uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: "8.4" tools: composer:v2 - coverage: xdebug extensions: pdo_pgsql - - name: Setup Node - uses: actions/setup-node@v6 - with: - node-version: "22" - - - name: Install Node Dependencies - run: npm install - - - name: Install Composer Dependencies + - name: Install Dependencies run: composer install --no-interaction --prefer-dist --optimize-autoloader + working-directory: backend - - name: Copy Environment File - run: cp .env.example .env - - - name: Generate Application Key - run: php artisan key:generate - - - name: Run Migrations - run: php artisan migrate --force - env: - DB_CONNECTION: pgsql - DB_HOST: 127.0.0.1 - DB_PORT: 5432 - DB_DATABASE: mealbuddy - DB_USERNAME: mealbuddy - DB_PASSWORD: secret - - - name: Build Assets - run: npm run build - - - name: Run Pest Tests + - name: Run Tests run: ./vendor/bin/pest + working-directory: backend + deploy: - name: Deploy to EC2 + name: Deploy to EC2 (ONLY VERSION BRANCH) needs: test runs-on: ubuntu-latest - if: | - github.event_name == 'push' && - ( - github.ref == 'refs/heads/main' || - github.ref == 'refs/heads/master' || - github.ref == 'refs/heads/workos' - ) + # CRITICAL FIX: ONLY VERSION BRANCH CAN DEPLOY + if: github.ref == 'refs/heads/version' && github.event_name == 'push' steps: - name: Deploy to Server @@ -103,10 +68,12 @@ jobs: script: | cd ~/mealbuddy - git fetch --all - git reset --hard origin/${{ github.ref_name }} + echo " Deploying VERSION branch..." + + git fetch origin + git reset --hard origin/version docker compose build frontend backend docker compose up -d --force-recreate frontend backend - docker image prune -f + docker image prune -f \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4084448..e21a21d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,37 +19,51 @@ on: permissions: contents: write -defaults: - run: - working-directory: backend - jobs: - quality: + backend-lint: + name: Backend Lint (Laravel) runs-on: ubuntu-latest + + defaults: + run: + working-directory: backend + steps: - uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.4' + php-version: "8.4" - - name: Install Dependencies - run: | - composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - npm install + - name: Install Composer Dependencies + run: composer install --no-interaction --prefer-dist - name: Run Pint run: composer lint + + frontend-lint: + name: Frontend Lint (Next.js) + runs-on: ubuntu-latest + + defaults: + run: + working-directory: frontend + + steps: + - uses: actions/checkout@v6 + + - name: Setup Node + uses: actions/setup-node@v6 + with: + node-version: "22" + + - name: Install Dependencies + run: npm install + - name: Format Frontend run: npm run format - name: Lint Frontend - run: npm run lint - - # - name: Commit Changes - # uses: stefanzweifel/git-auto-commit-action@v7 - # with: - # commit_message: fix code style - # commit_options: '--no-verify' + run: npm run lint \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f4d9bef..ac69f5b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,16 +16,14 @@ on: - workos - version -defaults: - run: - working-directory: backend - jobs: - ci: + backend-tests: + name: Backend Tests (Laravel) runs-on: ubuntu-latest - strategy: - matrix: - php-version: ['8.3', '8.4'] + + defaults: + run: + working-directory: backend services: postgres: @@ -49,20 +47,11 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php-version }} + php-version: "8.4" tools: composer:v2 - coverage: xdebug extensions: pdo_pgsql - - name: Setup Node - uses: actions/setup-node@v6 - with: - node-version: '22' - - - name: Install Node Dependencies - run: npm i - - - name: Install Dependencies + - name: Install Composer Dependencies run: composer install --no-interaction --prefer-dist --optimize-autoloader - name: Copy Environment File @@ -81,8 +70,29 @@ jobs: DB_USERNAME: mealbuddy DB_PASSWORD: secret - - name: Build Assets - run: npm run build - - - name: Tests + - name: Run Pest Tests run: ./vendor/bin/pest + + + frontend-tests: + name: Frontend Build & Test (Next.js) + runs-on: ubuntu-latest + + defaults: + run: + working-directory: frontend + + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Setup Node + uses: actions/setup-node@v6 + with: + node-version: "22" + + - name: Install Dependencies + run: npm install + + - name: Build Frontend + run: npm run build \ No newline at end of file From 81f80f52c7271abf80b92caca814a094b4be99cc Mon Sep 17 00:00:00 2001 From: Tenzin khenrab Date: Thu, 4 Jun 2026 10:57:42 +0530 Subject: [PATCH 2/8] fix app key generation --- .github/workflows/tests.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ac69f5b..e30a52f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -54,8 +54,10 @@ jobs: - name: Install Composer Dependencies run: composer install --no-interaction --prefer-dist --optimize-autoloader - - name: Copy Environment File - run: cp .env.example .env + - name: Setup Laravel Environment + run: | + cp .env.example .env + php artisan key:generate --force - name: Generate Application Key run: php artisan key:generate From 1bc35bf776571b842fe58508fd46188781ef1363 Mon Sep 17 00:00:00 2001 From: Tenzin khenrab Date: Thu, 4 Jun 2026 11:04:36 +0530 Subject: [PATCH 3/8] added --- backend/.env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/.env.example b/backend/.env.example index 80e3132..beaeb9b 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -1,6 +1,6 @@ APP_NAME=Laravel APP_ENV=local -APP_KEY= +APP_KEY=base64:GaqTGHuKxQlEwjWIepV5jJPlc0EwlGhpgA17lDwAUN4= APP_DEBUG=true APP_URL=http://localhost:8000 From 2783ca035f2732d41b902a8fbf83dc11498d21fa Mon Sep 17 00:00:00 2001 From: Tenzin khenrab Date: Thu, 4 Jun 2026 11:17:53 +0530 Subject: [PATCH 4/8] Fixed the report --- .github/workflows/tests.yml | 15 ++++++++------- backend/tests/Feature/ParticipationReportTest.php | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e30a52f..e1a1573 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,7 +47,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: "8.4" + php-version: "8.2" tools: composer:v2 extensions: pdo_pgsql @@ -55,12 +55,14 @@ jobs: run: composer install --no-interaction --prefer-dist --optimize-autoloader - name: Setup Laravel Environment - run: | - cp .env.example .env - php artisan key:generate --force + run: | + cp .env.example .env + echo "APP_KEY=${{ secrets.APP_KEY }}" >> .env - - name: Generate Application Key - run: php artisan key:generate + - name: Clear Laravel Cache + run: | + php artisan config:clear + php artisan cache:clear - name: Run Migrations run: php artisan migrate --force @@ -75,7 +77,6 @@ jobs: - name: Run Pest Tests run: ./vendor/bin/pest - frontend-tests: name: Frontend Build & Test (Next.js) runs-on: ubuntu-latest diff --git a/backend/tests/Feature/ParticipationReportTest.php b/backend/tests/Feature/ParticipationReportTest.php index f2de73f..c55d181 100644 --- a/backend/tests/Feature/ParticipationReportTest.php +++ b/backend/tests/Feature/ParticipationReportTest.php @@ -62,7 +62,7 @@ $response->assertOk() ->assertJsonPath('date', '2026-04-07') ->assertJsonPath('has_menu', true) - ->assertJsonPath('menu_title', 'Test Meal'); + ->assertJsonPath('menu_title', 'Chicken Curry Rice'); $users = $response->json('users'); expect(count($users))->toBe(3); From f1bd981b545b9bb8d27edd219ff875a083b4a017 Mon Sep 17 00:00:00 2001 From: Tenzin khenrab Date: Thu, 4 Jun 2026 11:21:33 +0530 Subject: [PATCH 5/8] fixed php version conflict --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e1a1573..9905b7f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,7 +47,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: "8.2" + php-version: "8.3" tools: composer:v2 extensions: pdo_pgsql From 34f1eef534fe4abe25b15774399350ee6509828a Mon Sep 17 00:00:00 2001 From: Tenzin khenrab Date: Thu, 4 Jun 2026 11:25:47 +0530 Subject: [PATCH 6/8] fix db error --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9905b7f..d113534 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,6 +58,9 @@ jobs: run: | cp .env.example .env echo "APP_KEY=${{ secrets.APP_KEY }}" >> .env + echo "CACHE_STORE=array" >> .env + echo "SESSION_DRIVER=array" >> .env + echo "QUEUE_CONNECTION=sync" >> .env - name: Clear Laravel Cache run: | From 7029c2abff64c99b5c8641083e6969c013fd3a2a Mon Sep 17 00:00:00 2001 From: Tenzin khenrab Date: Thu, 4 Jun 2026 11:33:03 +0530 Subject: [PATCH 7/8] fixing the git workflow --- .github/workflows/deploy.yml | 95 +++++++++++++++++++++----------- .github/workflows/lint.yml | 69 ----------------------- .github/workflows/tests.yml | 104 ----------------------------------- 3 files changed, 63 insertions(+), 205 deletions(-) delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e457871..7189210 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,19 +1,30 @@ -name: Continuous Delivery +name: tests on: push: branches: + - develop - main - master + - workos + - version + pull_request: + branches: - develop + - main + - master - workos - version jobs: - test: - name: Run Test Suite + backend-tests: + name: Backend Tests (Laravel) runs-on: ubuntu-latest + defaults: + run: + working-directory: backend + services: postgres: image: postgres:16 @@ -30,50 +41,70 @@ jobs: --health-retries=10 steps: - - uses: actions/checkout@v6 + - name: Checkout code + uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: "8.4" + php-version: "8.3" tools: composer:v2 extensions: pdo_pgsql - - name: Install Dependencies + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: backend/vendor + key: composer-${{ hashFiles('backend/composer.lock') }} + + - name: Install dependencies run: composer install --no-interaction --prefer-dist --optimize-autoloader - working-directory: backend - - name: Run Tests + - name: Setup Laravel environment + run: | + cp .env.example .env + echo "APP_KEY=${{ secrets.APP_KEY }}" >> .env + echo "APP_ENV=testing" >> .env + echo "CACHE_STORE=array" >> .env + echo "SESSION_DRIVER=array" >> .env + echo "QUEUE_CONNECTION=sync" >> .env + echo "DB_CONNECTION=pgsql" >> .env + echo "DB_HOST=127.0.0.1" >> .env + echo "DB_PORT=5432" >> .env + echo "DB_DATABASE=mealbuddy" >> .env + echo "DB_USERNAME=mealbuddy" >> .env + echo "DB_PASSWORD=secret" >> .env + + - name: Clear Laravel cache + run: php artisan optimize:clear + + - name: Run migrations + run: php artisan migrate --force + + - name: Run tests run: ./vendor/bin/pest - working-directory: backend - - deploy: - name: Deploy to EC2 (ONLY VERSION BRANCH) - needs: test + frontend-tests: + name: Frontend Build (Next.js) runs-on: ubuntu-latest - # CRITICAL FIX: ONLY VERSION BRANCH CAN DEPLOY - if: github.ref == 'refs/heads/version' && github.event_name == 'push' + defaults: + run: + working-directory: frontend steps: - - name: Deploy to Server - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.SSH_HOST }} - username: ${{ secrets.SSH_USERNAME }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - port: ${{ secrets.SSH_PORT }} - - script: | - cd ~/mealbuddy + - name: Checkout code + uses: actions/checkout@v6 - echo " Deploying VERSION branch..." - - git fetch origin - git reset --hard origin/version + - name: Setup Node + uses: actions/setup-node@v6 + with: + node-version: "22" + cache: npm + cache-dependency-path: frontend/package-lock.json - docker compose build frontend backend - docker compose up -d --force-recreate frontend backend + - name: Install dependencies + run: npm ci - docker image prune -f \ No newline at end of file + - name: Build frontend + run: npm run build \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index e21a21d..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: linter - -on: - push: - branches: - - develop - - main - - master - - workos - - version - pull_request: - branches: - - develop - - main - - master - - workos - - version - -permissions: - contents: write - -jobs: - backend-lint: - name: Backend Lint (Laravel) - runs-on: ubuntu-latest - - defaults: - run: - working-directory: backend - - steps: - - uses: actions/checkout@v6 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "8.4" - - - name: Install Composer Dependencies - run: composer install --no-interaction --prefer-dist - - - name: Run Pint - run: composer lint - - - frontend-lint: - name: Frontend Lint (Next.js) - runs-on: ubuntu-latest - - defaults: - run: - working-directory: frontend - - steps: - - uses: actions/checkout@v6 - - - name: Setup Node - uses: actions/setup-node@v6 - with: - node-version: "22" - - - name: Install Dependencies - run: npm install - - - name: Format Frontend - run: npm run format - - - name: Lint Frontend - run: npm run lint \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index d113534..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: tests - -on: - push: - branches: - - develop - - main - - master - - workos - - version - pull_request: - branches: - - develop - - main - - master - - workos - - version - -jobs: - backend-tests: - name: Backend Tests (Laravel) - runs-on: ubuntu-latest - - defaults: - run: - working-directory: backend - - services: - postgres: - image: postgres:16 - env: - POSTGRES_DB: mealbuddy - POSTGRES_USER: mealbuddy - POSTGRES_PASSWORD: secret - ports: - - 5432:5432 - options: >- - --health-cmd="pg_isready -U mealbuddy -d mealbuddy" - --health-interval=5s - --health-timeout=5s - --health-retries=10 - - steps: - - name: Checkout code - uses: actions/checkout@v6 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "8.3" - tools: composer:v2 - extensions: pdo_pgsql - - - name: Install Composer Dependencies - run: composer install --no-interaction --prefer-dist --optimize-autoloader - - - name: Setup Laravel Environment - run: | - cp .env.example .env - echo "APP_KEY=${{ secrets.APP_KEY }}" >> .env - echo "CACHE_STORE=array" >> .env - echo "SESSION_DRIVER=array" >> .env - echo "QUEUE_CONNECTION=sync" >> .env - - - name: Clear Laravel Cache - run: | - php artisan config:clear - php artisan cache:clear - - - name: Run Migrations - run: php artisan migrate --force - env: - DB_CONNECTION: pgsql - DB_HOST: 127.0.0.1 - DB_PORT: 5432 - DB_DATABASE: mealbuddy - DB_USERNAME: mealbuddy - DB_PASSWORD: secret - - - name: Run Pest Tests - run: ./vendor/bin/pest - - frontend-tests: - name: Frontend Build & Test (Next.js) - runs-on: ubuntu-latest - - defaults: - run: - working-directory: frontend - - steps: - - name: Checkout code - uses: actions/checkout@v6 - - - name: Setup Node - uses: actions/setup-node@v6 - with: - node-version: "22" - - - name: Install Dependencies - run: npm install - - - name: Build Frontend - run: npm run build \ No newline at end of file From 3bfa272d6a1d4bfbee0d5c59680a0448b4f1827b Mon Sep 17 00:00:00 2001 From: Tenzin khenrab Date: Thu, 4 Jun 2026 11:40:50 +0530 Subject: [PATCH 8/8] fixed mismatch menu --- backend/tests/Feature/ParticipationReportTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/tests/Feature/ParticipationReportTest.php b/backend/tests/Feature/ParticipationReportTest.php index c55d181..8cd22e8 100644 --- a/backend/tests/Feature/ParticipationReportTest.php +++ b/backend/tests/Feature/ParticipationReportTest.php @@ -30,9 +30,13 @@ 'created_at' => '2026-04-01 00:00:00' ]); + /** + * FIX: Make test deterministic + * Previously it was "Test Meal" but assertion expected "Chicken Curry Rice" + */ $this->menu = WeeklyMenu::firstOrCreate( ['weekday' => 'mon'], - ['title' => 'Test Meal'] + ['title' => 'Chicken Curry Rice'] ); $this->lunchDay = LunchDay::create([ @@ -83,6 +87,7 @@ ->assertJsonPath('week_end', '2026-04-10'); $users = $response->json('users'); + $empData = collect($users)->firstWhere('id', $this->employee->id); expect($empData['days']['2026-04-07'])->toBe('joining'); @@ -99,6 +104,7 @@ ->assertJsonPath('year', 2026); $users = $response->json('users'); + $empData = collect($users)->firstWhere('id', $this->employee->id); expect($empData['joined_count'])->toBe(1); expect($empData['skipped_count'])->toBe(0); @@ -112,4 +118,4 @@ $this->actingAs($this->employee, 'sanctum') ->getJson('/api/v1/accountant/participation-report?type=daily&date=2026-04-07') ->assertForbidden(); -}); +}); \ No newline at end of file