From 2e441186852f203d91747940595a641f8c8cace1 Mon Sep 17 00:00:00 2001 From: Alex Lubbock Date: Thu, 10 Oct 2024 10:24:05 +0100 Subject: [PATCH] ci: test using containers, unify build script --- .github/workflows/backend.yml | 44 ----------------------- .github/workflows/ci.yml | 62 ++++++++++++++++++++++++++++++++ .github/workflows/containers.yml | 45 ----------------------- .github/workflows/frontend.yml | 49 ------------------------- README.md | 2 +- backend/Dockerfile | 2 ++ frontend/src/App.test.js | 11 +++--- 7 files changed, 71 insertions(+), 144 deletions(-) delete mode 100644 .github/workflows/backend.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/containers.yml delete mode 100644 .github/workflows/frontend.yml diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml deleted file mode 100644 index b6364f2..0000000 --- a/.github/workflows/backend.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Backend Code CI - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build: - strategy: - fail-fast: false - matrix: - os: ["ubuntu-latest"] # can add windows-latest, macos-latest - python: ["3.11"] - - name: build/${{ matrix.python }}/${{ matrix.os }} - runs-on: ${{ matrix.os }} - timeout-minutes: 60 - defaults: - run: - working-directory: backend - - steps: - - name: Checkout Source - uses: actions/checkout@v4 - with: - # require history to get back to last tag for version number of branches - fetch-depth: 0 - - - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - - - name: Install Python Dependencies - run: | - pip install pipenv build - pipenv sync --dev --python $(python -c 'import sys; print(sys.executable)') && pipenv graph - - - name: Run Tests - run: DJANGO_CI=true pipenv run tests diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..02623b8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: Build, test and push backend container + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + component: [backend, frontend] + + steps: + - name: Checkout Source + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Quay.io + uses: docker/login-action@v2 + with: + registry: quay.io + username: rosalindfranklininstitute+github_antigenapp + password: ${{ secrets.QUAYIO_TOKEN }} + + - name: Build image + uses: docker/build-push-action@v3 + with: + context: ${{ matrix.component }} + target: dev + platforms: linux/amd64 + load: true + tags: antigen-app-dev-${{ matrix.component }}:latest + + - name: Run backend tests + if: ${{ matrix.component == 'backend' }} + run: | + docker run --rm -e DJANGO_CI=true antigen-app-dev-backend:latest pipenv run tests + + - name: Run frontend tests + if: ${{ matrix.component == 'frontend' }} + run: | + docker run --rm -e CI=true antigen-app-dev-frontend:latest npm test + docker run --rm antigen-app-dev-frontend:latest npx prettier --check . + + - name: Push image + uses: docker/build-push-action@v3 + with: + context: ${{ matrix.component }} + target: prod + platforms: linux/amd64 + push: ${{ github.event_name != 'pull_request' }} + tags: quay.io/rosalindfranklininstitute/antigen-app-${{ matrix.component }}:latest diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml deleted file mode 100644 index cc36ab9..0000000 --- a/.github/workflows/containers.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Container Images push to quay.io - -on: - push: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout Source - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Quay.io - uses: docker/login-action@v2 - with: - registry: quay.io - username: rosalindfranklininstitute+github_antigenapp - password: ${{ secrets.QUAYIO_TOKEN }} - - - name: Build and push backend image - uses: docker/build-push-action@v3 - with: - context: backend - target: prod - platforms: linux/amd64 - push: ${{ github.event_name != 'pull_request' }} - tags: quay.io/rosalindfranklininstitute/antigen-app-backend:latest - - - name: Build and push frontend image - uses: docker/build-push-action@v3 - with: - context: frontend - target: prod - platforms: linux/amd64 - push: ${{ github.event_name != 'pull_request' }} - tags: quay.io/rosalindfranklininstitute/antigen-app-frontend:latest diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml deleted file mode 100644 index 6d73293..0000000 --- a/.github/workflows/frontend.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Frontend Code CI - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build: - strategy: - matrix: - os: ["ubuntu-latest"] # can add windows-latest, macos-latest - node-version: [22.x] - - name: build/${{ matrix.node-version }}/${{ matrix.os }} - runs-on: ${{ matrix.os }} - timeout-minutes: 60 - defaults: - run: - working-directory: frontend - - steps: - - name: Checkout Source - uses: actions/checkout@v4 - with: - # require history to get back to last tag for version number of branches - fetch-depth: 0 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - cache: "npm" - cache-dependency-path: frontend/package-lock.json - - - name: Install - run: npm ci - - - name: Build - run: npm run build --if-present - - - name: Unit Tests - run: npm test - - - name: Prettier - run: npx prettier --check . diff --git a/README.md b/README.md index 7697772..8f72dcc 100644 --- a/README.md +++ b/README.md @@ -37,4 +37,4 @@ To run the backend (Python+Django) test suite: To run the test suite: - docker compose exec app npm test + docker compose exec -e CI=true app npm test diff --git a/backend/Dockerfile b/backend/Dockerfile index 4321d13..1d7d709 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -44,4 +44,6 @@ FROM builder AS dev ENV PATH="$PATH:/root/.local/bin:/usr/src/.venv/bin" +RUN pipenv sync --dev + CMD ["pipenv", "run", "python", "manage.py", "runserver", "0.0.0.0:8080"] diff --git a/frontend/src/App.test.js b/frontend/src/App.test.js index 583349f..c6dea66 100644 --- a/frontend/src/App.test.js +++ b/frontend/src/App.test.js @@ -1,8 +1,9 @@ -import { render, screen } from "@testing-library/react"; +import React from "react"; import App from "./App"; +import { createRoot } from "react-dom/client"; -test("renders learn react link", () => { - render(); - const linkElement = screen.getByText(/Named Nanobodies/); - expect(linkElement).toBeInTheDocument(); +it("renders without crashing", () => { + const container = document.createElement("div"); + const root = createRoot(container); + root.render(); });