Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prv proton patch 1 #1

Open
wants to merge 2 commits into
base: feat/prashanth-cicd-testing-619
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 214 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
name: Testing pipeline

on:
push:
branches:
- '*'

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10.13'

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose

- name: Cache Poetry dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-

- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Cache Docker images
uses: actions/cache@v3
with:
path: /var/lib/docker
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-

- name: Install Poetry
run: pip install poetry==1.6.1

- name: Install backend dependencies
run: |
# Ensure that pip, setuptools, and wheel are up to date
pip install --upgrade pip setuptools wheel

# Install Poetry dependencies
cd backend
poetry config virtualenvs.create false
poetry install
pip install pytest-github-actions-annotate-failures

- name: Install frontend dependencies
run: |
cd frontend
npm ci

- name: Fix docker-compose.yml
run: |
sed -i 's/: true/: "true"/g; s/: false/: "false"/g' docker-compose.yml

- name: Build and start services
run: |
docker-compose build
docker-compose up -d

# - name: Run backend tests
# id: backend_tests
# continue-on-error: true
# run: |
# cd backend
# poetry run pytest --junitxml=pytest-results.xml
# env:
# LCFS_DB_HOST: localhost
# LCFS_DB_PORT: 5432
# LCFS_DB_USER: lcfs
# LCFS_DB_PASS: development_only
# LCFS_DB_BASE: lcfs
# LCFS_REDIS_HOST: localhost
# LCFS_REDIS_PORT: 6379
# LCFS_REDIS_PASSWORD: development_only
# APP_ENVIRONMENT: test

# - name: Upload pytest results
# if: always()
# uses: actions/upload-artifact@v3
# with:
# name: pytest-results
# path: backend/pytest-results.xml

# - name: Run frontend tests
# id: frontend_tests
# continue-on-error: true
# run: |
# cd frontend
# npm run test:run -- --reporter=junit --outputFile=vitest-results.xml
# env:
# CI: true

# - name: Upload Vitest results
# if: always()
# uses: actions/upload-artifact@v3
# with:
# name: vitest-results
# path: frontend/vitest-results.xml
- name: Run Cypress tests
id: cypress_tests
continue-on-error: true
uses: cypress-io/github-action@v6
with:
command: npm run cypress:run
wait-on: 'http://localhost:3000'
working-directory: frontend
env:
admin_idir_username: ${{ secrets.ADMIN_IDIR_USERNAME }}
admin_idir_password: ${{ secrets.ADMIN_IDIR_PASSWORD }}
org1_bceid_username: ${{ secrets.ORG1_BCEID_USERNAME }}
org1_bceid_password: ${{ secrets.ORG1_BCEID_PASSWORD }}
org1_bceid_id: ${{ secrets.ORG1_BCEID_ID }}
org1_bceid_userId: ${{ secrets.ORG1_BCEID_USERID }}
org2_bceid_username: ${{ secrets.ORG2_BCEID_USERNAME }}
org2_bceid_password: ${{ secrets.ORG2_BCEID_PASSWORD }}
org2_bceid_id: ${{ secrets.ORG2_BCEID_ID }}
org2_bceid_userId: ${{ secrets.ORG2_BCEID_USERID }}

- name: Upload Cypress results
if: always()
uses: actions/upload-artifact@v3
with:
name: cypress-results
path: |
frontend/cypress/reports/
frontend/cypress/screenshots/

- name: Stop services
if: always()
run: docker-compose down

- name: Publish Backend Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: backend/pytest-results.xml
github_token: ${{ secrets.GITHUB_TOKEN }}
comment_title: "Backend Test Results"
check_name: "Backend Test Results"
fail_on: "errors"
report_individual_runs: "true"
deduplicate_classes_by_file_name: "true"

- name: Publish Frontend Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: frontend/vitest-results.xml
github_token: ${{ secrets.GITHUB_TOKEN }}
comment_title: "Frontend Test Results"
check_name: "Frontend Test Results"
fail_on: "errors"
report_individual_runs: "true"
deduplicate_classes_by_file_name: "true"
# - name: Process and Publish End-to-end Test Results
# if: always()
# run: |
# # Process Cypress results
# echo "End-to-End Test Results:" >> test_summary.md
# jq -r '.stats | "Total: \(.tests), Passed: \(.passes), Failed: \(.failures)"' frontend/cypress/reports/results.json >> test_summary.md

# # Post comment to PR
# gh pr comment ${{ github.event.pull_request.number }} --body-file test_summary.md
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish End-to-End Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
frontend/cypress/reports/**/*
frontend/cypress/screenshots/**/*
github_token: ${{ secrets.GITHUB_TOKEN }}
comment_title: "End-to-End Test Results"
check_name: "End-to-End Test Results"
fail_on: "errors"
report_individual_runs: "true"
deduplicate_classes_by_file_name: "true"

- name: Check test results
if: always()
run: |
if [ "${{ steps.backend_tests.outcome }}" == "failure" ] || \
[ "${{ steps.frontend_tests.outcome }}" == "failure" ] || \
[ "${{ steps.cypress_tests.outcome }}" == "failure" ]; then
echo "One or more tests failed"
exit 0
else
echo "All tests passed"
fi
Loading
Loading