View the full GitHub Actions workflow file here.

Triggers

The on section has the events that trigger the workflow automation. In this case, it will trigger when code is pushed or whenever a pull request is opened on any branch.

on:
  push:
    branches: [ "**" ]
  pull_request:
    branches: [ "**" ]
 

Jobs

The jobs section has tasks, which will run simultaneously on different servers.

Each task runs on a temporary Linux server. uses actions/checkout@v4 will clone the code on the server.

runs-on: ubuntu-latest
 
steps:
- uses: actions/checkout@v4

The -name: field is for labels for each step that will happen next.

Backend

These echo commands save the API keys and URLs into a local .env inside the server.

	- name: Create .env file
	  working-directory: ./backend
	  run: |
		echo "GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}" > .env
		echo "SUPABASE_URL=${{ secrets.SUPABASE_URL }}" >> .env
		echo "SUPABASE_SERVICE_KEY=${{ secrets.SUPABASE_SERVICE_KEY }}" >> .env

This part installs Python dependencies. The run: | treats the part after it as a terminal command.

	- name: Set up Python
	  uses: actions/setup-python@v4
	  with:
		python-version: '3.9'
		
	- name: Install dependencies
	  working-directory: ./backend
	  run: |
		pip install -r requirements.txt

Next, it runs the unit tests using PyTest. The pytest command runs the test functions in any files that are named test_*.py or *_test.py. It uses the -v (verbose) flag to print out the test names and whether they passed or failed.

    - name: Run tests
      working-directory: ./backend
      run: |
        pytest automated_tests/ -v

Frontend

Similar to the backend job, the frontend job clones the code, sets up dependencies, and builds the frontend.

Notes:

  • The backend doesn’t have to be built. It can just run because Python doesn’t need to be compiled.
  • The frontend has to be built so that a web browser can display it.
  test-frontend:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Set up Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '20'
    - name: Install dependencies
      working-directory: ./frontend
      run: npm install
    - name: Build frontend
      working-directory: ./frontend
      run: npm run build

Docker

This part installs Docker Compose.

  • sudo curl -L downloads Docker Compose from the given URL. The -L flag ensures that if the URL has a redirect, it follows it to the final link
  • sudo chmod +x changes the file permissions to executable (+x). This allows you to run docker-compose commands
  • Run docker-compose version to make sure Docker Compose was set up properly
 name: Install Docker Compose
      run: |
        sudo curl -L "https://github.com/docker/compose/releases/download/v2.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
        sudo chmod +x /usr/local/bin/docker-compose
        docker-compose version

Test the containers.

  • docker-compose up -d starts the application. The -d flag starts the containers in the background, which is useful for web servers
  • Use sleep 30 to pause the script for 30 seconds. This gives the app time to boot
  • curl -f http://localhost:3000 || exit 1 tries to open the app. If it doesn’t work, exit 1 makes the pipeline fail
  • Shut down the container using docker-compose down
- name: Build Docker images
      run: |
        docker-compose build
    - name: Test Docker containers
      run: |
        docker-compose up -d
        sleep 30
        curl -f http://localhost:3000 || exit 1
        docker-compose down