name: Release

on:
  push:
    branches:
      - main
  release:
    types:
      - released

jobs:
  pre-commit:
    uses: ./.github/workflows/pre-commit.yaml
  build-backend:
    uses: ./.github/workflows/docker-build.yaml
    needs: pre-commit
    with:
      image-name: oasst-backend
      context: .
      dockerfile: docker/Dockerfile.backend
      build-args: ""
  build-web:
    uses: ./.github/workflows/docker-build.yaml
    needs: pre-commit
    with:
      image-name: oasst-web
      context: .
      dockerfile: docker/Dockerfile.website
      build-args: ""
  build-bot:
    uses: ./.github/workflows/docker-build.yaml
    needs: pre-commit
    with:
      image-name: oasst-discord-bot
      context: .
      dockerfile: docker/Dockerfile.discord-bot
      build-args: ""
  deploy-to-node:
    needs: [build-backend, build-web, build-bot]
    uses: ./.github/workflows/deploy-to-node.yaml
    secrets: inherit
    with:
      stack-name: ${{ github.event_name == 'release' && 'staging' || 'dev' }}
      image-tag:
        ${{ github.event_name == 'release' && github.event.release.tag_name ||
        'latest' }}
      backend-port: ${{ github.event_name == 'release' && '8180' || '8080' }}
      website-port: ${{ github.event_name == 'release' && '3100' || '3000' }}
