Skip to content

Commit

Permalink
Fix e2e github action
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Jun 14, 2024
1 parent f8096bb commit ec7b426
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 145 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test Coverage

on:
pull_request_target:
types:
- closed

jobs:
unit-tests:
if: github.event.pull_request.merged == true
timeout-minutes: 60
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [20]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8
run_install: false
- uses: actions/cache@v3
name: restore/setup pnpm cache
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Install dependencies
run: pnpm install

- name: Test
run: pnpm test:coverage

- name: Upload Coverage
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
fail_ci_if_error: false
files: ./coverage/lcov.info
flags: unittests
name: codecov-nectar
path_to_write_report: ./coverage/codecov_report.txt
verbose: true

140 changes: 79 additions & 61 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
name: Pull Request

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master

# Cancel in-progress workflows when we update the branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
build-and-lint:
timeout-minutes: 60
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [ 18 ]
node-version: [20]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
Expand All @@ -24,7 +34,6 @@ jobs:
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Install dependencies
if: steps.pnpm-cache.outputs.cache-hit != 'true'
run: pnpm install

- name: Lint
Expand All @@ -35,15 +44,14 @@ jobs:

unit-tests:
timeout-minutes: 60
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [ 18 ]
node-version: [20]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
Expand All @@ -54,72 +62,82 @@ jobs:
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Install dependencies
if: steps.pnpm-cache.outputs.cache-hit != 'true'
run: pnpm install

- name: Test
run: pnpm test:coverage
run: pnpm test:no-coverage

- name: Upload Coverage
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
fail_ci_if_error: false
files: ./coverage/lcov.info
flags: unittests
name: codecov-nectar
path_to_write_report: ./coverage/codecov_report.txt
verbose: true

e2e-tests:
integration-tests:
runs-on: ubuntu-22.04
timeout-minutes: 60
runs-on: ubuntu-latest
env:
CI: true
BASE_CANONICAL_URL: ${{ vars.BASE_CANONICAL_URL }}
API_HOST_CLIENT: ${{ vars.API_HOST_CLIENT }}
API_HOST_SERVER: ${{ vars.API_HOST_SERVER }}
COOKIE_SECRET: ${{ vars.COOKIE_SECRET }}
strategy:
matrix:
node-version: [ 18 ]
API_HOST_SERVER: https://devapi.adsabs.harvard.edu/v1
API_HOST_CLIENT: https://devapi.adsabs.harvard.edu/v1
SCIX_SESSION_COOKIE_NAME: test
COOKIE_SECRET: test

steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: 8
run_install: false
- uses: actions/cache@v3
name: restore/setup pnpm cache
install: true

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Install dependencies
if: steps.pnpm-cache.outputs.cache-hit != 'true'
run: pnpm install
- name: Create .env.local file
run: |
touch .env.local
echo "API_HOST_CLIENT=$API_HOST_CLIENT" >> .env.local
echo "API_HOST_SERVER=$API_HOST_SERVER" >> .env.local
echo "SCIX_SESSION_COOKIE_NAME=$SCIX_SESSION_COOKIE_NAME" >> .env.local
echo "COOKIE_SECRET=$COOKIE_SECRET" >> .env.local
- name: Build e2e Service (from cache if possible)
run: |
USER_UID=$(id -u) USER_GID=$(id -g) DOCKER_BUILDKIT=1 docker buildx build \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache,mode=max \
-t nectar-ci:e2e -f Dockerfile --target e2e .
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Create test-results directory
run: mkdir -p test-results && chmod 0777 test-results

- name: setup environment variables
- name: Run e2e tests
run: |
touch .env.local
echo "CI=${{ env.CI }}" >> .env.local
echo "BASE_CANONICAL_URL=${{ env.BASE_CANONICAL_URL }}" >> .env.local
echo "API_HOST_CLIENT=${{ env.API_HOST_CLIENT }}" >> .env.local
echo "API_HOST_SERVER=${{ env.API_HOST_SERVER }}" >> .env.local
echo "COOKIE_SECRET=${{ env.COOKIE_SECRET }}" >> .env.local
USER_UID=$(id -u) USER_GID=$(id -g) docker compose \
-f docker-compose.yml up --exit-code-from e2e e2e
- name: Run integration tests
run: pnpm integration
- name: Archive test results
if: failure()
run: |
zip -r test-results.zip test-results
- uses: actions/upload-artifact@v3
if: always()
- name: Upload test results
if: failure()
uses: actions/upload-artifact@v2
with:
name: playwright-report
path: playwright-report/
retention-days: 30
name: test-results
path: test-results.zip

- name: Get prod container logs
if: failure()
run: docker logs $(docker-compose ps -q prod) > prod-container-logs.txt

- name: Upload prod container logs
if: failure()
uses: actions/upload-artifact@v2
with:
name: prod-container-logs
path: prod-container-logs.txt

- name: Shutdown Docker Compose
run: docker compose down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,3 @@ storybook-static/

# Sentry Config File
.sentryclirc

# Sentry Config File
.sentryclirc
28 changes: 17 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:20-bookworm AS base
ARG USER_UID=1001
ARG USER_GID=1001
ARG USERNAME=node
ARG USERNAME=nectar
ENV PNPM_HOME=/pnpm
ENV DIST_DIR="dist"
ENV STANDALONE=1
Expand All @@ -22,26 +22,30 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update && apt-get --no-install-recommends install -y libc6;


RUN groupadd -g $USER_GID $USERNAME || true && \
useradd -u $USER_UID -g $USER_GID -m -s /bin/bash $USERNAME || true && \
usermod -u $USER_UID -g $USER_GID $USERNAME || true

WORKDIR /app

RUN groupmod --gid $USER_GID $USERNAME \
&& usermod --uid $USER_UID --gid $USER_GID $USERNAME \
&& chown -R $USER_UID:$USER_GID /app;
RUN chown -R $USER_UID:$USER_GID /app

FROM base as dev
COPY --link package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --ignore-scripts --no-optional
USER $USERNAME
COPY --link . ./

USER $USERNAME
ENTRYPOINT ["pnpm", "run", "dev"]

FROM base as unit
USER root
COPY --link package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install vitest
USER $USERNAME
COPY --link vitest-setup.ts vitest.config.js tsconfig.json ./
COPY --link src /app/src
USER $USERNAME
ENTRYPOINT ["vitest"]

FROM base AS build_prod
Expand All @@ -56,13 +60,13 @@ RUN --mount=type=cache,id=nextjs,target=./dist/cache pnpm run build
FROM base AS prod
ENV NODE_ENV=production

USER $USERNAME
COPY --link --from=build_prod /app/dist/standalone ./
COPY --link --from=build_prod /app/node_modules ./node_modules
COPY --link --from=build_prod /app/dist/static ./dist/static
COPY --link --from=build_prod /app/public ./public
COPY --link --from=build_prod --chown="$USERNAME":"$USERNAME" /app/dist/cache ./dist/cache
COPY --link --from=build_prod /app/dist/cache ./dist/cache

USER $USERNAME
EXPOSE 8000
ENTRYPOINT ["node", "server.js"]

Expand All @@ -73,11 +77,13 @@ RUN playwright install --with-deps
FROM e2e-browsers as e2e
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=0

USER $USERNAME
COPY --link src ./src
COPY --link e2e ./e2e
COPY --link playwright.config.ts ./
COPY --link tsconfig.json ./
COPY --link playwright.config.ts ./playwright.config.ts
COPY --link tsconfig.json ./tsconfig.json

RUN chown -R $USER_UID:$USER_GID /app;
USER $USERNAME

ENTRYPOINT ["playwright"]
CMD ["test"]
8 changes: 0 additions & 8 deletions docker-compose.overrides.yml

This file was deleted.

Loading

0 comments on commit ec7b426

Please sign in to comment.