Add CI pipeline #15
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: | |
branches: ['main'] | |
pull_request: | |
branches: ['main'] | |
jobs: | |
generate-tag: | |
runs-on: ubuntu-latest | |
outputs: | |
tag: ${{ steps.generate-tag.outputs.tag }} | |
steps: | |
- name: Generate tag | |
id: generate-tag | |
run: echo "tag=$(date +"%Y%m%d-%H%M%S")" >> "$GITHUB_OUTPUT" | |
build-and-push: | |
runs-on: ubuntu-latest | |
needs: generate-tag | |
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 }} | |
IMAGE_TAG: ${{ needs.generate-tag.outputs.tag }} | |
steps: | |
- name: Print component | |
run: echo ${{ matrix.component.dir }} ${{ matrix.component.image }} | |
- 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 | |
- name: Generate tag | |
id: generate-tag | |
run: echo "IMAGE_NAME=${{ matrix.component.image }}:$IMAGE_TAG" >> $GITHUB_ENV | |
if: matrix.component.image | |
- name: Build Docker image | |
run: | | |
cd ${{ matrix.component.dir }} | |
docker build . --tag $IMAGE_NAME | |
if: matrix.component.image | |
- name: Print Docker image | |
run: echo $IMAGE_NAME | |
if: matrix.component.image | |
- name: Push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: '$(echo $IMAGE_NAME)' | |
if: matrix.component.image |