# SPDX-License-Identifier: Apache-2.0
# Copyright 2023 Authors of Nimbus

name: Latest release

on:
  push:
    branches:
      - main
      - "v*"
  create:
    branches:
      - "v*"

permissions: read-all

jobs:
  release-nimbus-image:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source code
        uses: actions/checkout@v3

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Get tag
        id: tag
        run: |
          if [ ${{ github.ref }} == "refs/heads/main" ]; then
            echo "tag=latest" >> $GITHUB_OUTPUT
          else
            echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
          fi

      - name: Build and push nimbus image
        run: make docker-buildx TAG=${{ steps.tag.outputs.tag }}