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 4126005
Showing 1 changed file with 65 additions and 51 deletions.
116 changes: 65 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,45 @@ 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
./next
e2e:
needs: build
if: github.ref_name != 'i18n/crowdin'
runs-on: ubuntu-latest
timeout-minutes: 30

strategy:
Expand All @@ -60,7 +93,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 +123,13 @@ 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

# 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 +173,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 +250,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 4126005

Please sign in to comment.