name: Publish Docker Image

on:
  release:
    types: [published]
jobs:
  buildUI:
    runs-on: osx
    name: Build UI Artifact
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: Restoring Node Packages
        run: |
          cd source
          yarn install --frozen-lockfile
      - name: Building Application
        run: |
          cd source
          yarn run build
      - name: Saving build artifact
        uses: actions/upload-artifact@v3
        with:
          name: troop20web
          path: source/dist/troop20web
  publishUI:
    runs-on: osx
    needs: [buildUI]
    name: Publish Docker Image
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: Getting Artifact
        uses: actions/download-artifact@v3
        with:
          name: troop20web
          path: source/dist/troop20web/
      - name: Log in to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .
          push: false
          tags: ${{ secrets.DOCKERHUB_USERNAME }}/troop20-web:${{ github.ref_name }}