Skip to content

Commit

Permalink
Create github actions for build, e2e-tests and deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
kvestus committed Mar 9, 2024
1 parent f49f5fe commit 8572768
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 441 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build

on:
workflow_call:
secrets:
FIREBASE_CONFIG_BASE64:
required: true

jobs:
build:
timeout-minutes: 3
runs-on: ubuntu-latest
container:
image: cypress/browsers:node18.12.0-chrome106-ff106
options: --user 1001
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: ./node_modules
key: modules-${{ hashFiles('package-lock.json') }}

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

- name: Write Firebase config
run: |
echo ${{ secrets.FIREBASE_CONFIG_BASE64 }} | base64 -d > firebase.config.json
- run: node --version
- run: node -p 'os.cpus()'
- run: npm run build
- run: npm run lint
- run: npm run test:ci
- run: npm run build:test

- name: Save build folder
uses: actions/upload-artifact@v4
with:
name: dist
if-no-files-found: error
path: dist

- name: Save test build folder
uses: actions/upload-artifact@v4
with:
name: dist-test
if-no-files-found: error
path: dist-test
34 changes: 34 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build

on:
workflow_call:
inputs:
isPreview:
required: true
type: boolean
default: false
secrets:
TOKEN:
required: true
FIREBASE_SERVICE_ACCOUNT_LANGUAGES_LEARNER:
required: true

jobs:
deploy_preview_website:
timeout-minutes: 2
environment: ${{ inputs.isPreview && 'deploy_preview' || '' }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Download artifact
uses: actions/download-artifact@main
with:
name: dist
path: dist
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_LANGUAGES_LEARNER }}"
expires: ${{ inputs.isPreview && '7d' || '' }}
channelId: ${{ inputs.isPreview && '' || 'live' }}
97 changes: 97 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: E2E Chrome Tests

on:
workflow_call:
inputs:
isManual:
required: false
type: boolean
default: false
platform:
required: true
type: string
secrets:
TEST_USER_USERNAME:
required: true
TEST_USER_PASSWORD:
required: true

jobs:
e2e-chrome-tests:
environment: ${{ inputs.isManual && 'manual_e2e_tests' || '' }}
timeout-minutes: 5
runs-on: ubuntu-latest
container:
image: cypress/browsers:node18.12.0-chrome106-ff106
options: --user 1001
strategy:
fail-fast: false # https://github.com/cypress-io/github-action/issues/48
matrix:
# https://github.com/languages-learner/web/issues/32 - Disable cypress logs because limit reached
# containers: [ 1, 2 ]
containers: [ 1 ]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: ./node_modules
key: modules-${{ hashFiles('package-lock.json') }}

- name: Download the build folders
uses: actions/download-artifact@v4
with:
name: dist-test
path: dist-test

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

- name: "Cypress install"
run: yarn cypress install --force

- name: Node info
run: node -v

# - name: __e Dir
# run: ls /__e

- name: "E2E Tests - Chrome"
uses: cypress-io/github-action@v6
with:
install: false
start: npm run preview:test
browser: chrome
# https://github.com/languages-learner/web/issues/32 - Disable cypress logs because limit reached
# record: true
# parallel: true
# group: "E2E - Chrome"
spec: cypress/e2e/*
config-file: ${{ inputs.platform == 'desktop' && 'cypress/configs/preview.ts' || 'cypress/configs/mobile.preview.ts' }}
env:
TEST_USER_USERNAME: ${{ secrets.TEST_USER_USERNAME }}
TEST_USER_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}
# https://github.com/languages-learner/web/issues/32 - Disable cypress logs because limit reached
# CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
# CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
# COMMIT_INFO_SHA: ${{ github.event.pull_request.head.sha }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Save cypress snapshots
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.platform == 'desktop' && 'e2e-chrome-cypress-snapshots' || 'e2e-chrome-mobile-cypress-snapshots' }}
path: |
cypress/snapshots/actual
cypress/snapshots/diff
Loading

0 comments on commit 8572768

Please sign in to comment.