name: Next Version Build

# Run the Weekly on Monday 8 AM UTC
on: 
  schedule:
    - cron: "0 12 * * 1"

jobs:
  publish-image:
    runs-on: ubuntu-latest
    steps:
      - name: Set Active Branch
        id: ver
        run: |
          echo "::warning Choosing Version 5.8"
          echo ::set-output name=activever::"5.8"

      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ steps.ver.outputs.activever }}

      - name: Get Current Date
        id: date
        run: echo "::set-output name=date::$(date +'%Y%m%d')"

      - name: Prepare Tags
        id: prep
        run: |
          DOCKER_BASE_IMAGE=noobaa/noobaa-base
          DOCKER_BUILDER_IMAGE=noobaa/noobaa-builder
          DOCKER_CORE_IMAGE=noobaa/noobaa-core
          VERSION="${{ steps.date.outputs.date }}"
          echo "::warning ${VERSION}"
          BASE_TAGS="${DOCKER_BASE_IMAGE}:${{ steps.ver.outputs.activever }}-${VERSION}"
          BUILDER_TAGS="${DOCKER_BUILDER_IMAGE}:${{ steps.ver.outputs.activever }}-${VERSION}"
          CORE_TAGS="${DOCKER_CORE_IMAGE}:${{ steps.ver.outputs.activever }}-${VERSION}"
          echo "::warning ${CORE_TAGS}"
          echo ::set-output name=basetags::${BASE_TAGS}
          echo ::set-output name=buildertags::${BUILDER_TAGS}
          echo ::set-output name=coretags::${CORE_TAGS}

      - name: Login to DockerHub Registry
        run: echo ${{ secrets.GHACTIONSDOCKERHUB }} | docker login -u ${{ secrets.GHACTIONSDOCKERHUBNAME }} --password-stdin

      - name: Build & Push Docker Images
        env:
          DOCKERHUB_OWNER: ${{ secrets.GHACTIONSDOCKERHUBNAME }}
        run: |
            make noobaa
            docker tag noobaa-base ${{ steps.prep.outputs.basetags }}
            docker push ${{ steps.prep.outputs.basetags }}
            docker tag noobaa-builder ${{ steps.prep.outputs.buildertags }}
            docker push ${{ steps.prep.outputs.buildertags }}
            docker tag noobaa ${{ steps.prep.outputs.coretags }}
            docker push ${{ steps.prep.outputs.coretags }}
            
