name: build-dev

on:
  push:
    branches: [ dev ]
jobs:
  build:
    name: Create cross-platform dev build
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v1

      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.17
          
      - name: Test
        run: go test -v ./...

      - name: Build
        env:
          RELEASE: v1.0.${{ github.run_number }} 
          ArmoBEServer: api.armo.cloud
          ArmoERServer: report.euprod1.cyberarmorsoft.com
          ArmoWebsite: portal.armo.cloud
          CGO_ENABLED: 0
        run: python3 --version && python3 build.py
      
      - name: Upload build artifacts 
        uses: actions/upload-artifact@v2
        with:
          name: kubescape-${{ matrix.os }}
          path: build/${{ matrix.os }}/kubescape 


  build-docker:
    name: Build docker container, tag and upload to registry
    needs: build
    if: ${{ github.repository == 'armosec/kubescape' }}
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set name
        run: echo quay.io/armosec/kubescape:dev-v1.0.${{ github.run_number }} > build_tag.txt

      - name: Build the Docker image
        run: docker build . --file build/Dockerfile --tag $(cat build_tag.txt)
      
      - name: Login to Quay.io
        env: # Or as an environment variable
          QUAY_PASSWORD: ${{ secrets.QUAYIO_REGISTRY_PASSWORD }}
          QUAY_USERNAME: ${{ secrets.QUAYIO_REGISTRY_USERNAME }}
        run: docker login -u="${QUAY_USERNAME}" -p="${QUAY_PASSWORD}" quay.io
        
      - name: Push Docker image
        run: |
          docker push $(cat build_tag.txt)
    
        
