CI #22
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: CI | |
on: | |
schedule: | |
- cron: '19 6 * * *' | |
push: | |
branches: [ "main" ] | |
tags: [ 'v*.*.*' ] | |
pull_request: | |
branches: [ "main" ] | |
env: | |
REGISTRY: docker.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/[email protected] | |
- name: Log into Docker Hub | |
if: github.event_name != 'pull_request' | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/[email protected] | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build Docker image | |
id: build | |
uses: docker/[email protected] | |
with: | |
context: . | |
push: false | |
tags: jozpedro23/studentportal:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
file: Dockerfile.prod | |
load: true | |
- name: Up Containers | |
run: docker compose -f docker-compose.ci.yaml up -d | |
- name: generate envs | |
run: | | |
docker compose -f docker-compose.ci.yaml exec -u root -T app cp ./envs/.env.test.example ./envs/.env.test | |
docker compose -f docker-compose.ci.yaml exec -u root -T app cp ./envs/.env.e2e.example ./envs/.env.e2e | |
- name: Run tests in Docker container | |
run: | | |
docker compose -f docker-compose.ci.yaml exec -T app npm run test | |
docker compose -f docker-compose.ci.yaml exec -T app npm run test:e2e | |
- name: Push Docker image | |
if: github.event_name != 'pull_request' | |
uses: docker/[email protected] | |
with: | |
context: . | |
push: true | |
tags: jozpedro23/studentportal:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
file: Dockerfile.prod |