Skip to content

Add CI pipeline

Add CI pipeline #29

Workflow file for this run

name: Build Project
on:
push:
pull_request:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
PUSH_DOCKER: github.event_name == 'push'
strategy:
matrix:
component:
- { dir: 'backend', image: '${DOCKER_USERNAME}/kuka-soittaa-backend' }
- {
dir: 'admin-panel',
image: '${DOCKER_USERNAME}/kuka-soittaa-admin-panel',
}
- { dir: 'app' }
steps:
- uses: actions/checkout@v3
- name: Install dependencies for ${{ matrix.component.dir }}
run: |
cd ${{ matrix.component.dir }}
yarn install --frozen-lockfile --non-interactive
- name: Lint ${{ matrix.component.dir }}
run: |
cd ${{ matrix.component.dir }}
yarn lint
- name: Build ${{ matrix.component.dir }}
run: |
cd ${{ matrix.component.dir }}
yarn build
- name: Extract branch name
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF##*/})" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
if: matrix.component.image && env.PUSH_DOCKER
- name: Push Docker image
uses: docker/build-push-action@v5
with:
push: true
context: ${{ matrix.component.dir }}
tags: ${{ matrix.component.image }}:${{ env.BRANCH_NAME }}
if: matrix.component.image && env.PUSH_DOCKER
- name: Push Docker image with latest tag
uses: docker/build-push-action@v5
with:
push: true
context: ${{ matrix.component.dir }}
tags: ${{ matrix.component.image }}:latest
if: github.ref == 'refs/heads/main' && matrix.component.image && env.PUSH_DOCKER