Skip to content

Showing logs from the run as a workflow step #4

Showing logs from the run as a workflow step

Showing logs from the run as a workflow step #4

name: Complexity level 4 -> Run Tests
on:
schedule:
- cron: "0 8 * * *" # run on schedule, examples: https://crontab.guru/examples.html
pull_request:
workflow_dispatch:
inputs:
environment:
type: choice
description: "Environment: localhost / dev"
required: true
options:
- localhost
- dev
default: "localhost"
browser:
type: choice
description: "Browser: chrome / firefox"
required: true
options:
- chrome
- firefox
default: "chrome"
jobs:
run-specs:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Node.js
if: ${{ inputs.environment == 'localhost' || github.event_name == 'pull_request' }}
uses: actions/setup-node@v3
with:
node-version: ">=16.0.0"
- name: Build packages
if: ${{ inputs.environment == 'localhost' || github.event_name == 'pull_request' }}
run: yarn
- name: Build application
if: ${{ inputs.environment == 'localhost' || github.event_name == 'pull_request' }}
run: yarn build-localhost
- name: Save build folder
if: ${{ inputs.environment == 'localhost' || github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: build
if-no-files-found: error
path: build
- name: Download the build folders
if: ${{ inputs.environment == 'localhost' || github.event_name == 'pull_request' }}
uses: actions/download-artifact@v3
with:
name: build
path: build
- name: Install Serve
if: ${{ inputs.environment == 'localhost' || github.event_name == 'pull_request' }}
run: yarn global add serve
- name: Run application on localhost
if: ${{ inputs.environment == 'localhost' || github.event_name == 'pull_request' }}
run: serve -s ${{ github.workspace }}/build &
- name: Run Tests on LOCALHOST
if: ${{ inputs.environment == 'localhost' || github.event_name == 'pull_request' }}
uses: cypress-io/github-action@v6
with:
install: true
wait-on: "http://localhost:3000"
wait-on-timeout: 120
browser: ${{ inputs.browser }}
config-file: /${{ github.workspace }}/cypress/configs/cypress.localhost.config.js
- name: Run Tests on DEV
if: ${{ github.event_name == 'schedule' || inputs.environment != 'localhost' && github.event_name != 'pull_request' }}
uses: cypress-io/github-action@v6
with:
install: true
browser: ${{ inputs.browser }}
config-file: /${{ github.workspace }}/cypress/configs/cypress.dev.config.js
- name: Cypress screenshots
uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-screenshots
path: ${{ github.workspace }}/cypress/screenshots
- name: Cypress videos
uses: actions/upload-artifact@v2
if: always()
with:
name: cypress-videos
path: ${{ github.workspace }}/cypress/videos
- name: Logs from the run
if: always()
run: |
echo "--<< BRANCH_NAME >>--"
export BRANCH_NAME=${GITHUB_REF#refs/heads/}
echo "--<< GITHUB ACTION RUN URL >>--"
export RUN_URL=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
echo "--<< WORKFLOW TRIGGER EVENT NAME >>--"
echo ${{ github.event_name }}
echo "--<< SELECTED ENVIRONMENT >>--"
echo ${{ inputs.environment }}
echo "--<< SELECTED BROWSER >>--"
echo ${{ inputs.browser }}
echo "--<< CYPRESS CONFIG LOCALHOST >>--"
cat ${{ github.workspace }}/cypress/configs/cypress.localhost.config.js
echo "--<< CYPRESS CONFIG DEV >>--"
cat ${{ github.workspace }}/cypress/configs/cypress.dev.config.js
echo "--<< LOCAL APP FRROM BUILD STEP >>--"
ls -lh ${{ github.workspace }}/build