๐งฉ Workflow Components in GitHub Actions
What Is a Workflow?
๐น A workflow is a set of Actions that run automatically in response to specific events in the repository.
๐น Workflows are defined in YAML files and stored in the folder:
.github/workflows
โจ Core Components of a Workflow
1๏ธโฃ name: a descriptive name for the workflow.
2๏ธโฃ on: the events (triggers) that start the workflow, such as:
-
push -
pull_request -
schedule(Cron Jobs)
3๏ธโฃ jobs: a set of jobs. Each job contains steps that run in a specific runner environment.
โ๏ธ Components of a Job
โถ๏ธ name: the name of the job.
โถ๏ธ runs-on: the execution environment (for example: ubuntu-latest, windows-latest, macos-latest).
โถ๏ธ steps: the list of steps the job runs (running commands or using ready-made Actions).
๐ Example workflow.yml File
name: Testing Python Code Workflow
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
name: Construir y Testear
runs-on: ubuntu-24.04
steps:
- name: Checkout del cรณdigo
uses: actions/checkout@v4
- name: Configurar Python 3.11
uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Instalar dependencias
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r ./requirements.txt
- name: Ejecutar pruebas
run: |
python -m unittest discover -s tests
๐ Explaining the Example
-
Trigger: starts when a
pushorpull_requesthappens on themainbranch. -
Job: named build, and it runs on an Ubuntu 24.04 environment.
-
Steps:
-
โ Checkout code โ fetches the code from the repository.
-
โ Setup Python โ installs Python 3.11.
-
โ Install dependencies โ installs the required libraries.
-
โ Run tests โ runs the unit tests.
-
โก๏ธ This scenario lets you automate building and testing your projects (such as Odoo add-ons) on every change to the main branch.
๐ก Where Does the Workflow Run?
-
All workflows run on a Runner (a temporary server provided by GitHub).
-
The runner can be a virtual server or even a Docker container.
-
As soon as the workflow finishes, this server is destroyed.
๐ What Can We Do Next?
Using this runner, you can connect to your Odoo server (VPS or Cloud) to run automated tasks such as:
-
๐ Updating the code (repositories).
-
๐พ Creating backups.
-
๐๏ธ Upgrading the database.