Skip to content

Commit

Permalink
CI: Common build step for E2E
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Nov 14, 2024
1 parent 722ccaf commit 2860788
Showing 1 changed file with 64 additions and 51 deletions.
115 changes: 64 additions & 51 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ env:
API_URL: http://localhost:3060
API_KEY: dvl-1510egmf4a23d80342403fb599qd
CI: true

E2E_TEST: 1
PGHOST: localhost
PGUSER: postgres
Expand All @@ -34,11 +33,43 @@ env:
AWS_SECRET: ${{ secrets.AWS_SECRET }}

jobs:
e2e:
build:
if: github.ref_name != 'i18n/crowdin'

runs-on: ubuntu-latest
steps:
- name: Checkout (frontend)
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
cache: 'npm'

- name: Restore node_modules (frontend)
uses: actions/cache@v4
id: node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}-${{ secrets.CACHE_VERSION }}

- name: Install dependencies (frontend)
if: steps.node-modules.outputs.cache-hit != 'true'
run: CYPRESS_INSTALL_BINARY=0 npm ci --prefer-offline --no-audit

- name: Build (frontend)
run: npm run build

- name: Upload frontend build
uses: actions/upload-artifact@v3
with:
name: next-build
path: ./dist

e2e:
needs: build
if: github.ref_name != 'i18n/crowdin'
runs-on: ubuntu-latest
timeout-minutes: 30

strategy:
Expand All @@ -60,7 +91,6 @@ jobs:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
Expand Down Expand Up @@ -91,8 +121,14 @@ jobs:
node-version-file: 'package.json'
cache: 'npm'

# Checkouts
# Download the frontend build from the previous job
- name: Download frontend build
uses: actions/download-artifact@v3
with:
name: next-build
path: ./dist

# Checkouts for other repos
- name: Set REF in env, removing the `refs/` part
run: |
echo "MATCHING_BRANCH_REF=${GITHUB_HEAD_REF-${GITHUB_REF##*/}}" >> $GITHUB_ENV
Expand Down Expand Up @@ -136,6 +172,29 @@ jobs:
repository: opencollective/opencollective-pdf
path: opencollective-pdf

# Setup dependencies
- name: Restore node_modules (frontend)
uses: actions/cache@v4
id: node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}-${{ secrets.CACHE_VERSION }}

- name: Install dependencies (frontend)
if: steps.node-modules.outputs.cache-hit != 'true'
run: CYPRESS_INSTALL_BINARY=0 npm ci --prefer-offline --no-audit

- name: Restore Cypress
uses: actions/cache@v4
id: cypress
with:
path: ~/.cache/Cypress
key: ${{ runner.os }}-cypress-${{ hashFiles('node_modules/cypress/package.json') }}

- name: Install Cypress
if: steps.cypress.outputs.cache-hit != 'true'
run: npx cypress install

# Prepare API

- name: Restore node_modules (api)
Expand Down Expand Up @@ -190,53 +249,7 @@ jobs:
working-directory: opencollective-pdf
run: npm run build

# Prepare Frontend

- name: Restore node_modules (frontend)
uses: actions/cache@v4
id: node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}-${{ secrets.CACHE_VERSION }}

- name: Install dependencies (frontend)
if: steps.node-modules.outputs.cache-hit != 'true'
run: CYPRESS_INSTALL_BINARY=0 npm ci --prefer-offline --no-audit

- name: Restore Cypress
uses: actions/cache@v4
id: cypress
with:
path: ~/.cache/Cypress
key: ${{ runner.os }}-cypress-${{ hashFiles('node_modules/cypress/package.json') }}

- name: Install Cypress
if: steps.cypress.outputs.cache-hit != 'true'
run: npx cypress install

- name: Restore .next build (frontend)
uses: actions/cache@v4
id: next-build
with:
path: .next
key: ${{ runner.os }}-next-build-${{ github.sha }}

- name: Restore .next cache (frontend)
if: steps.next-build.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: .next/cache
key: ${{ runner.os }}-next-cache-${{ github.sha }}
restore-keys: |
${{ runner.os }}-next-cache-${{ github.sha }}
${{ runner.os }}-next-cache-
- name: Build (frontend)
if: steps.next-build.outputs.cache-hit != 'true'
run: npm run build

# Seed DB

- name: Setup DB
run: ./scripts/setup_db.sh

Expand Down

0 comments on commit 2860788

Please sign in to comment.