fix: Update logout test to handle both / and /login redirects #132
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This workflow is dedicated to the frontend application. | |
| # It handles linting, end-to-end testing with Cypress, and publishing the Docker image. | |
| name: Frontend CI - Build, Test & Push | |
| on: | |
| push: | |
| branches: [ "feature/**", "develop/**", "release/**" ] # Triggers on pushes to the 'frontend' branch | |
| paths: | |
| - 'frontend/**' | |
| - '.github/workflows/ci-frontend.yml' | |
| pull_request: | |
| branches: [ "main", "develop", "feature/**", "release/**" ] # Triggers on pull requests targeting 'main' or 'develop' | |
| paths: | |
| - 'frontend/**' | |
| env: | |
| DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
| DOCKER_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
| TERM: xterm # Fix for tput: No value for $TERM error | |
| jobs: | |
| frontend-ci: | |
| runs-on: ubuntu-latest | |
| name: Frontend Build, Test & Push | |
| steps: | |
| # 1. Checkout the repository's code | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # 2. Set up the Node.js environment | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| cache: 'npm' | |
| cache-dependency-path: 'frontend/package-lock.json' | |
| # 3. Cache Cypress binary to avoid download issues | |
| - name: Cache Cypress binary | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/Cypress | |
| key: cypress-${{ runner.os }}-${{ hashFiles('frontend/package-lock.json') }} | |
| restore-keys: | | |
| cypress-${{ runner.os }}- | |
| # 4. Install frontend dependencies securely and efficiently | |
| - name: Install dependencies | |
| working-directory: ./frontend | |
| env: | |
| CYPRESS_INSTALL_BINARY: 0 | |
| run: npm ci | |
| # 5. Install Cypress binary separately with retry | |
| - name: Install Cypress binary | |
| working-directory: ./frontend | |
| run: | | |
| for i in 1 2 3; do | |
| npx cypress install && break || sleep 10 | |
| done | |
| # 6. Run ESLint for code quality checks. The build fails if linting errors are found. | |
| # - name: Run ESLint | |
| # working-directory: ./frontend | |
| # run: npm run lint | |
| # 7. Set up Docker Buildx for advanced image building features | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # 8. Execute Cypress E2E tests within a Docker Compose environment | |
| # - name: Run Cypress E2E Tests with Docker Compose | |
| # # The working directory is set to the root because docker-compose.yml is there | |
| # run: | | |
| # # Build and start services in detached mode | |
| # echo "Building and starting services..." | |
| # docker compose up --build -d | |
| # # Health Check: Wait until the frontend service is responsive on port 80 | |
| # echo "Waiting for container to be ready..." | |
| # # This command waits for up to 3 minutes for the service to return a successful HTTP status | |
| # timeout 180s bash -c 'until curl --silent --fail http://localhost:80; do echo "Retrying in 5s..."; sleep 5; done' | |
| # # Once the service is ready, run the Cypress tests | |
| # echo "Container is ready! Running Cypress E2E tests..." | |
| # # Install dependencies and run Cypress in the host environment | |
| # cd ./frontend | |
| # npm ci | |
| # npm run cy:run | |
| # 9. Always stop and remove containers after the test run to clean up the runner | |
| # - name: Stop and Remove Containers | |
| # if: always() | |
| # run: docker compose down | |
| # 10. Log in to Docker Hub. This step only runs on pushes to the 'frontend' branch. | |
| - name: Log in to Docker Hub | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/frontend' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ env.DOCKER_USERNAME }} | |
| password: ${{ env.DOCKER_TOKEN }} | |
| # 11. Build and push the production Docker image to Docker Hub. | |
| # This step also only runs on pushes to the 'frontend' branch. | |
| - name: Build and push production image | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/frontend' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./frontend | |
| file: ./frontend/Dockerfile.prod | |
| push: true | |
| tags: | | |
| ${{ env.DOCKER_USERNAME }}/apartment-frontend:latest | |
| ${{ env.DOCKER_USERNAME }}/apartment-frontend:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| provenance: false |