Skip to content

Commit

Permalink
From Biophonia project
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicdmt committed Jan 20, 2025
1 parent b76d160 commit ad25e29
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 0 deletions.
157 changes: 157 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: Run basic checks

on:
pull_request:
branches: [main, dev]

env:
TELESCOOP_DEV: true
IS_TESTING: true

jobs:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Install python dependencies
run: pip install -r back/requirements.txt
- name: Install front js dependencies
run: npm install
working-directory: ./front
- name: Create back/local_settings.conf
run: echo "${{ secrets.LOCAL_SETTINGS_CONF }}" > local_settings.conf
working-directory: ./back
- name: Cache Python dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('back/requirements.txt') }}
- name: Cache Node.js dependencies
uses: actions/cache@v3
with:
path: ./front/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('front/package-lock.json') }}

pre-commit:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Restore Python cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('back/requirements.txt') }}
- name: Install python dependencies if not cached
if: steps.cache-python.outputs.cache-hit != 'true'
run: pip install -r back/requirements.txt
- name: Restore Node.js cache
uses: actions/cache@v3
with:
path: ./front/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('front/package-lock.json') }}
- name: Install js dependencies if not cached
if: steps.cache-node.outputs.cache-hit != 'true'
run: npm install
working-directory: ./front
- name: Enforce pre-commit hook server side
uses: pre-commit/[email protected]

node-setup:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version-file: ./front/.nvmrc
cache: "npm"
- name: Restore Node.js cache
uses: actions/cache@v3
with:
path: ./front/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('front/package-lock.json') }}
- name: Install js dependencies if not cached
if: steps.cache-node.outputs.cache-hit != 'true'
run: npm install
working-directory: ./front

frontend-tests:
runs-on: ubuntu-latest
needs: [setup, node-setup]
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: ./front/.nvmrc
cache: "npm"
- name: Restore Node.js cache
uses: actions/cache@v3
with:
path: ./front/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('front/package-lock.json') }}
- name: Install front js dependencies if not cached
if: steps.cache-node.outputs.cache-hit != 'true'
run: npm install
working-directory: ./front
- name: Run vitest
run: npm run test
working-directory: ./front
- name: Run cypress component tests
uses: cypress-io/github-action@v6
with:
component: true
working-directory: ./front

e2e-tests:
runs-on: ubuntu-latest
needs: [setup]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Restore Python cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('back/requirements.txt') }}
- name: Install python dependencies if not cached
if: steps.cache-python.outputs.cache-hit != 'true'
run: pip install -r back/requirements.txt
- name: Migrate database
run: python back/manage.py migrate
- name: Load test database
run: python back/manage.py backup_db restore_db test_db
- name: Run back-end server in background
run: python manage.py runserver localhost:8000 &
working-directory: ./back
- name: Run e2e tests
uses: cypress-io/github-action@v6
with:
start: npm run dev
browser: chrome
config-file: cypress.config.js
working-directory: ./front
- name: Upload cypress screenshots
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshot
path: |
front/cypress/screenshots
retention-days: 10
38 changes: 38 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Run deploy prod

on:
pull_request:
branches: [main, dev]

jobs:
deploy-prod:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy frontend in prod
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: frontend.yml
directory: deploy
vault_password: ${{secrets.ANSIBLE_VAULT_KEY}}
options: |
-l prod
key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Deploy backend in prod
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: backend.yml
directory: deploy
vault_password: ${{secrets.ANSIBLE_VAULT_KEY}}
options: |
-l prod
key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Deploy static in prod
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: showcase.yml
directory: deploy
vault_password: ${{secrets.ANSIBLE_VAULT_KEY}}
options: |
-l prod
key: ${{ secrets.SSH_PRIVATE_KEY }}
7 changes: 7 additions & 0 deletions deploy/roles/backend/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@
become_user: "{{ main_user }}"
when: clonecode.changed or force_update is defined

- name: Load database and media
command:
cmd: "{{ project_slug }}-ctl backup_db recover_db_and_media"
become: true
become_user: "{{ main_user }}"
when: clonecode.changed or force_update is defined

- name: Collect backend static files
command:
cmd: "{{ project_slug }}-ctl collectstatic --no-input"
Expand Down

0 comments on commit ad25e29

Please sign in to comment.