maingockien01 is running CI on commit d80a3f3bf7c324182884c2457e41a9a4d4d71b07 #473
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 | |
run-name: ${{ github.actor }} is running ${{ github.workflow }} on commit ${{ github.sha }} | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} | |
DOCKER_TAG: ${{ secrets.DOCKER_USERNAME }}/team8:latest | |
IS_PUSH_TO_MAIN: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
jobs: | |
security-scan: | |
permissions: | |
contents: read | |
security-events: write | |
actions: read | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Snyk CLI | |
uses: snyk/actions/setup@master | |
env: | |
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
- name: Snyk run code analysis | |
run: snyk code test -d --sarif > snyk-code.sarif || true | |
env: | |
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
- name: Snyk IaC test and report | |
run: snyk iac test -d --report || true | |
env: | |
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
- name: Upload result to GitHub Code Scanning | |
uses: github/codeql-action/upload-sarif@v2 | |
with: | |
sarif_file: snyk-code.sarif | |
build: | |
name: Build the docker image | |
runs-on: ubuntu-latest | |
concurrency: | |
group: build-${{ github.sha }} | |
cancel-in-progress: true | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and export | |
id: build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
tags: ${{ env.DOCKER_TAG }} | |
outputs: type=docker,dest=/tmp/image.tar | |
# Upload Docker image as artifact | |
- name: Upload image | |
id: upload | |
uses: actions/upload-artifact@v3 | |
with: | |
name: image | |
path: /tmp/image.tar | |
lint: | |
name: Lint and Test code | |
runs-on: ubuntu-latest | |
needs: build | |
concurrency: | |
group: lint-${{ github.sha }} | |
cancel-in-progress: true | |
steps: | |
# Downloading docker image | |
- name: Dowload Docker image | |
id: download | |
uses: actions/download-artifact@v3 | |
with: | |
name: image | |
path: /tmp | |
# Loading image | |
- name: Load image | |
run: docker load --input /tmp/image.tar | |
# Linting the code | |
- name: Run linter on workspace backend | |
id: backend | |
run: docker run ${{ env.DOCKER_TAG }} yarn workspace @team8/backend lint | |
- name: Run linter on workspace frontend | |
id: frontend | |
run: docker run ${{ env.DOCKER_TAG }} yarn workspace @team8/frontend lint | |
- name: Run linter on workspace types | |
id: types | |
run: docker run ${{ env.DOCKER_TAG }} yarn workspace @team8/types lint | |
- name: Run linter on workspace constants | |
id: constants | |
run: docker run ${{ env.DOCKER_TAG }} yarn workspace @team8/constants lint | |
- name: Run linter on workspace utils | |
id: utils | |
run: docker run ${{ env.DOCKER_TAG }} yarn workspace @team8/utils lint | |
tests-unit-backend: | |
name: BE unit tests | |
runs-on: ubuntu-latest | |
needs: build | |
concurrency: | |
group: tests-unit-backend-${{ github.sha }} | |
cancel-in-progress: true | |
steps: | |
# Downloading docker image | |
- name: Dowload Docker image | |
id: download | |
uses: actions/download-artifact@v3 | |
with: | |
name: image | |
path: /tmp | |
# Loading image | |
- name: Load image | |
run: docker load --input /tmp/image.tar | |
# Running tests | |
- name: Run unit tests on workspace backend | |
id: backend-unit | |
run: docker run ${{ env.DOCKER_TAG }} yarn workspace @team8/backend test:unit | |
tests-unit-frontend: | |
name: FE Unit tests | |
runs-on: ubuntu-latest | |
needs: build | |
concurrency: | |
group: tests-unit-frontend-${{ github.sha }} | |
cancel-in-progress: true | |
steps: | |
# Downloading docker image | |
- name: Dowload Docker image | |
id: download | |
uses: actions/download-artifact@v3 | |
with: | |
name: image | |
path: /tmp | |
# Loading image | |
- name: Load image | |
run: docker load --input /tmp/image.tar | |
# Run test | |
- name: Run unit tests on workspace frontend | |
id: frontend-unit | |
run: docker run ${{ env.DOCKER_TAG }} yarn workspace @team8/frontend test:unit | |
tests-backend-e2e: | |
name: BE e2e tests | |
runs-on: ubuntu-latest | |
needs: build | |
concurrency: | |
group: tests-backend-e2e-${{ github.sha }} | |
cancel-in-progress: true | |
services: | |
database: | |
image: mysql:5.7 | |
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 --name=database | |
ports: | |
- 3306:3306 | |
env: | |
MYSQL_ROOT_PASSWORD: root | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
# Downloading docker image | |
- name: Dowload Docker image | |
id: download | |
uses: actions/download-artifact@v3 | |
with: | |
name: image | |
path: /tmp | |
# Loading image | |
- name: Load image | |
run: docker load --input /tmp/image.tar | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v3 | |
- name: Init mysql | |
run: | | |
docker exec -i database mysql -uroot -proot < ./docker/mysql/provision/init.sql | |
- name: Run e2e tests on workspace backend | |
id: backend-e2e | |
run: docker run --network ${{ job.container.network }} --name apps ${{ env.DOCKER_TAG }} yarn workspace @team8/backend test:e2e | |
push-image: | |
name: Push to Dockerhub | |
runs-on: ubuntu-latest | |
needs: [lint, tests-unit-backend, tests-unit-frontend, tests-backend-e2e] | |
if: ${{github.event_name != 'pull_request'}} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Docker Hub | |
if: ${{ env.IS_PUSH_TO_MAIN }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ env.DOCKER_USERNAME }} | |
password: ${{ env.DOCKER_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: ${{github.event_name != 'pull_request'}} # Don't push on PRs | |
tags: ${{ env.DOCKER_TAG }} | |
cache-from: type=registry,ref=${{ env.DOCKER_TAG }} | |
cache-to: type=inline |