Add CI pipeline #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: Build Project | |
on: [push, pull_request] | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
component: | |
- { dir: 'backend', image: '$DOCKER_USERNAME/kuka-soittaa-backend' } | |
- { | |
dir: 'admin-panel', | |
image: '$DOCKER_USERNAME/kuka-soittaa-admin-panel', | |
} | |
- { dir: 'app' } | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
PUSH_DOCKER: github.event_name != 'pull_request' | |
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: 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 }}:${GITHUB_REF##*/} | |
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 |