diff --git a/.github/workflows/dev-cicd.yml b/.github/workflows/dev-cicd.yml index 15779e3..8f99cb0 100644 --- a/.github/workflows/dev-cicd.yml +++ b/.github/workflows/dev-cicd.yml @@ -1,4 +1,4 @@ -name: Dev CI/CD Pipeline +name: Dev - CI/CD Pipeline on: push: @@ -62,11 +62,11 @@ jobs: run: echo "${{ secrets.DOCKER_PASSWORD_DEV }}" | docker login -u "${{ secrets.DOCKER_USERNAME_DEV }}" --password-stdin - name: Push Docker image to Docker Hub (dev) run: docker push ${{ env.IMAGE_NAME }}:dev - - name: Deploy to Dev Server - run: | - ssh -o StrictHostKeyChecking=no ${{ secrets.DEV_SERVER_USER }}@${{ secrets.DEV_SERVER_IP }} << 'EOF' - docker pull ${{ env.IMAGE_NAME }}:dev - docker stop dev-container || true - docker rm dev-container || true - docker run -d --name dev-container -p 3000:3000 ${{ env.IMAGE_NAME }}:dev - EOF + # - name: Deploy to Dev Server + # run: | + # ssh -o StrictHostKeyChecking=no ${{ secrets.DEV_SERVER_USER }}@${{ secrets.DEV_SERVER_IP }} << 'EOF' + # docker pull ${{ env.IMAGE_NAME }}:dev + # docker stop dev-container || true + # docker rm dev-container || true + # docker run -d --name dev-container -p 3000:3000 ${{ env.IMAGE_NAME }}:dev + # EOF diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml deleted file mode 100644 index a7a4034..0000000 --- a/.github/workflows/integration.yml +++ /dev/null @@ -1,53 +0,0 @@ - -# name: Integration - -# on: -# push: -# branches: [ "main" ] -# pull_request: -# branches: [ "main" ] - -# jobs: -# build: - -# runs-on: ubuntu-latest - -# strategy: -# matrix: -# node-version: [18.x, 20.x, 22.x] - -# steps: -# - uses: actions/checkout@v4 -# - name: Use Node.js ${{ matrix.node-version }} -# uses: actions/setup-node@v3 -# with: -# node-version: ${{ matrix.node-version }} -# cache: 'npm' - -# - name: "Installing Dependencies" -# run: npm i - -# - name: "Build command" -# run: npm run build - -# unit-tests: - -# runs-on: ubuntu-latest - -# strategy: -# matrix: -# node-version: [18.x, 20.x, 22.x] - -# steps: -# - uses: actions/checkout@v4 -# - name: Use Node.js ${{ matrix.node-version }} -# uses: actions/setup-node@v3 -# with: -# node-version: ${{ matrix.node-version }} -# cache: 'npm' - -# - name: "Installing Dependencies" -# run: npm i - -# - name: "Running test cases" -# run: npm run test \ No newline at end of file diff --git a/.github/workflows/prod-cicd.yml b/.github/workflows/prod-cicd.yml new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/stagging-cicd.yml b/.github/workflows/stagging-cicd.yml new file mode 100644 index 0000000..b29946e --- /dev/null +++ b/.github/workflows/stagging-cicd.yml @@ -0,0 +1,72 @@ +name: Staging CI/CD Pipeline + +on: + push: + branches: + - staging + pull_request: + branches: + - dev + +env: + IMAGE_NAME: daoudhussaindev/next-js-app + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + + steps: + - uses: actions/checkout@v4 + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Install dependencies + run: npm ci + - name: Build Next.js application + run: npm run build + + test: + runs-on: ubuntu-latest + needs: build + strategy: + matrix: + node-version: [18.x] + + steps: + - uses: actions/checkout@v4 + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Install dependencies + run: npm ci + - name: Run tests + run: npm run test + + deploy: + runs-on: ubuntu-latest + needs: [test] + if: github.ref == 'refs/heads/staging' + + steps: + - uses: actions/checkout@v4 + - name: Build Docker image for staging + run: docker build -t ${{ env.IMAGE_NAME }}:staging . + - name: Login to Docker Hub + run: echo "${{ secrets.DOCKER_PASSWORD_DEV }}" | docker login -u "${{ secrets.DOCKER_USERNAME_DEV }}" --password-stdin + - name: Push Docker image to Docker Hub (staging) + run: docker push ${{ env.IMAGE_NAME }}:staging + # - name: Deploy to Staging Server + # run: | + # ssh -o StrictHostKeyChecking=no ${{ secrets.STAGING_SERVER_USER }}@${{ secrets.STAGING_SERVER_IP }} << 'EOF' + # docker pull ${{ env.IMAGE_NAME }}:staging + # docker stop staging-container || true + # docker rm staging-container || true + # docker run -d --name staging-container -p 3001:3000 ${{ env.IMAGE_NAME }}:staging + # EOF diff --git a/app/page.test.tsx b/app/page.test.tsx index e94d24c..481e70e 100644 --- a/app/page.test.tsx +++ b/app/page.test.tsx @@ -1,10 +1,15 @@ -/** - * @jest-environment jsdom - */ -import { render, screen } from "@testing-library/react"; -import Page from "./page"; +import { render, screen } from '@testing-library/react'; +import Page from './page'; // Adjust the import if necessary -it("App Router: Works with Server Components", () => { - render(); - expect(screen.getByRole("heading")).toHaveTextContent("App Router"); +describe("App Router", () => { + it("Works with Server Components", () => { + render(); + + // Check for specific heading (e.g.,

text) + expect(screen.getByRole('heading', { name: /My Next\.js Site/i })).toBeInTheDocument(); + + // Alternatively, you can check for other headings or count the number of heading elements + const headings = screen.getAllByRole('heading'); + expect(headings).toHaveLength(8); // Ensure there are 7 headings + }); });