Unit Tests #1687
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Unit Tests | |
on: | |
schedule: | |
- cron: "0 0 * * *" | |
push: | |
branches: | |
- "[0-9]+.0" | |
- "[0-9]+.0-*" | |
paths: | |
- "**/workflows/**" | |
- "**/resources/**" | |
- "Dockerfile" | |
env: | |
HUB_BASE: iterativodo | |
GIT_BASE: ghcr.io/iterativo-git | |
GCR_BASE: gcr.io/iterativo | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Inject slug/short variables | |
uses: rlespinasse/github-slug-action@v4 | |
# Automatic tag management and OCI Image Format Specification for labels | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v3 | |
with: | |
# list of Docker images to use as base name for tags | |
images: | | |
${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }} | |
- name: Set up QEMU | |
id: qemu | |
uses: docker/setup-qemu-action@v1 | |
with: | |
image: tonistiigi/binfmt:latest | |
platforms: all | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to Github Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to GCR | |
uses: docker/login-action@v1 | |
with: | |
registry: gcr.io | |
username: _json_key | |
password: ${{ secrets.GKE_SA_KEY }} | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
target: production | |
platforms: | | |
linux/amd64 | |
linux/arm64 | |
push: true | |
tags: ${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:sha-${{ env.GITHUB_SHA_SHORT }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=registry,ref=${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:buildcache | |
cache-to: type=registry,ref=${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:buildcache,mode=max | |
test: | |
name: Unit Tests | |
needs: ["build"] | |
runs-on: ubuntu-latest | |
services: | |
db: | |
image: postgres:14-alpine | |
env: | |
POSTGRES_DB: postgres | |
POSTGRES_USER: odoo | |
POSTGRES_PASSWORD: odoo | |
# needed because the postgres container does not provide a healthcheck | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Inject slug/short variables | |
uses: rlespinasse/github-slug-action@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
with: | |
driver-opts: network=host | |
- name: Login to Github Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run Odoo tests | |
continue-on-error: true | |
run: | | |
docker pull ${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:sha-${{ env.GITHUB_SHA_SHORT }} | |
docker run -e RUN_TESTS -e LOG_LEVEL -e EXTRA_MODULES -e PGHOST --network="host" --name odoo -t ${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:sha-${{ env.GITHUB_SHA_SHORT }} | |
env: | |
RUN_TESTS: "1" | |
LOG_LEVEL: test | |
EXTRA_MODULES: base | |
PGHOST: localhost | |
push: | |
name: Push to all registries | |
needs: ["build", "test"] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout local | |
uses: actions/checkout@v2 | |
- name: Inject slug/short variables | |
uses: rlespinasse/github-slug-action@v4 | |
# Automatic tag management and OCI Image Format Specification for labels | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v3 | |
with: | |
# list of Docker images to use as base name for tags | |
images: | | |
${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }} | |
${{ env.HUB_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }} | |
${{ env.GCR_BASE}}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }} | |
- name: Set up QEMU | |
id: qemu | |
uses: docker/setup-qemu-action@v1 | |
with: | |
image: tonistiigi/binfmt:latest | |
platforms: all | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to GitHub Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Login to GCR | |
uses: docker/login-action@v1 | |
with: | |
registry: gcr.io | |
username: _json_key | |
password: ${{ secrets.GKE_SA_KEY }} | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
target: production | |
platforms: | | |
linux/amd64 | |
linux/arm64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=registry,ref=${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:buildcache | |
cache-to: type=registry,ref=${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:buildcache,mode=max |