name: Publish Backend

on:
  workflow_dispatch:

jobs:
  publish_backend:
    name: Generate docker image and publish
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - name: Check out code
        uses: actions/checkout@v4
      - name: Set up JDK 21
        uses: actions/setup-java@v4
        with:
          distribution: adopt
          java-version: '21'
      - name: Release build
        run: ./gradlew :backend:gateway:buildFatJar
      - name: Log in to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: docker/build-push-action@v5
        with:
          context: ./backend/gateway
          push: true
          tags: ghcr.io/writeopia/writeopia-backend:latest
