name: Build Images

on:
  workflow_dispatch:
    inputs:
      choice:
        type: choice
        description: Build targets
        options:
        - beta
        - stable
        - rc
      runner:
        type: choice
        description: Build runners for CLI
        options:
        - small
        - ubuntu-latest
      sourcerepo:
        description: Source repository
        required: true
        default: 'nightly'
jobs:

  fake:
    runs-on: ubuntu-latest
    name: Source changes
    if: ${{ github.repository_owner == 'Armbian' }}
    steps:
      - run: |
          echo "not empty" > changes
      - uses: actions/upload-artifact@v2
        with:
          path: changes
          name: changes
          if-no-files-found: ignore
      
  merge:
    needs: [ fake ]
    uses: armbian/scripts/.github/workflows/merge-from-branch.yml@master    

    with:
      branch: 'nightly'
      runner: small

    secrets:  
      GPG_KEY2: ${{ secrets.GPG_KEY2 }}
      GPG_PASSPHRASE2: ${{ secrets.GPG_PASSPHRASE2 }}

  x86:
    needs: [ merge ]
    uses: armbian/scripts/.github/workflows/build-with-docker.yml@master

    with:
 
      variant: 'cli:${{ github.event.inputs.choice }}'
      sourcerepo: '${{ github.event.inputs.sourcerepo }}'
      runner: '${{ github.event.inputs.runner }}'
      part: 1
      of: 1
      include: 'grep uefi-x86 | '
      exclude: ''
      uploading: false

    secrets:
      GPG_KEY1: ${{ secrets.GPG_KEY1 }}
      GPG_PASSPHRASE1: ${{ secrets.GPG_PASSPHRASE1 }}
      GPG_KEY2: ${{ secrets.GPG_KEY2 }}
      GPG_PASSPHRASE2: ${{ secrets.GPG_PASSPHRASE2 }}
      SCRIPTS_ACCESS_TOKEN: ${{ secrets.SCRIPTS_ACCESS_TOKEN }}
      SSH_KEY_TORRENTS: ${{ secrets.KEY_TORRENTS }}
      KNOWN_HOSTS_UPLOAD: ${{ secrets.KNOWN_HOSTS_UPLOAD }}

  x86-desktop:
    needs: [ merge ]
    uses: armbian/scripts/.github/workflows/build-with-docker.yml@master

    with:

      variant: 'desktop:${{ github.event.inputs.choice }}'
      sourcerepo: '${{ github.event.inputs.sourcerepo }}'
      runner: "big"
      part: 1
      of: 1
      include: 'grep uefi-x86 | '
      exclude: ''
      uploading: false

    secrets:
      GPG_KEY1: ${{ secrets.GPG_KEY1 }}
      GPG_PASSPHRASE1: ${{ secrets.GPG_PASSPHRASE1 }}
      GPG_KEY2: ${{ secrets.GPG_KEY2 }}
      GPG_PASSPHRASE2: ${{ secrets.GPG_PASSPHRASE2 }}
      SCRIPTS_ACCESS_TOKEN: ${{ secrets.SCRIPTS_ACCESS_TOKEN }}
      SSH_KEY_TORRENTS: ${{ secrets.KEY_TORRENTS }}
      KNOWN_HOSTS_UPLOAD: ${{ secrets.KNOWN_HOSTS_UPLOAD }}

  cli:
    needs: [ merge ]
    uses: armbian/scripts/.github/workflows/build-with-docker.yml@master

    with:
 
      variant: 'cli:${{ github.event.inputs.choice }}'
      sourcerepo: '${{ github.event.inputs.sourcerepo }}'
      runner: '${{ github.event.inputs.runner }}'
      part: 1
      of: 1
      include: ''
      exclude: 'grep -v uefi-x86 | '
      uploading: false

    secrets:
      GPG_KEY1: ${{ secrets.GPG_KEY1 }}
      GPG_PASSPHRASE1: ${{ secrets.GPG_PASSPHRASE1 }}
      GPG_KEY2: ${{ secrets.GPG_KEY2 }}
      GPG_PASSPHRASE2: ${{ secrets.GPG_PASSPHRASE2 }}
      SCRIPTS_ACCESS_TOKEN: ${{ secrets.SCRIPTS_ACCESS_TOKEN }}
      SSH_KEY_TORRENTS: ${{ secrets.KEY_TORRENTS }}
      KNOWN_HOSTS_UPLOAD: ${{ secrets.KNOWN_HOSTS_UPLOAD }}


  desktop:
    needs: [ merge ]
    uses: armbian/scripts/.github/workflows/build-with-docker.yml@master

    with:
      variant: 'desktop:${{ github.event.inputs.choice }}'
      sourcerepo: '${{ github.event.inputs.sourcerepo }}'
      runner: "big"
      part: 1
      of: 1      
      include: ''
      exclude: 'grep -v uefi-x86 | '
      uploading: false

    secrets:
      GPG_KEY1: ${{ secrets.GPG_KEY1 }}
      GPG_PASSPHRASE1: ${{ secrets.GPG_PASSPHRASE1 }}
      GPG_KEY2: ${{ secrets.GPG_KEY2 }}
      GPG_PASSPHRASE2: ${{ secrets.GPG_PASSPHRASE2 }}
      SCRIPTS_ACCESS_TOKEN: ${{ secrets.SCRIPTS_ACCESS_TOKEN }}
      SSH_KEY_TORRENTS: ${{ secrets.KEY_TORRENTS }}
      KNOWN_HOSTS_UPLOAD: ${{ secrets.KNOWN_HOSTS_UPLOAD }}

  jobsend:
    name: finish
    needs: [x86,x86-desktop,cli,desktop]
    runs-on: [ubuntu-latest]
    if: ${{ github.repository_owner == 'Armbian' }}
    steps:
      - run: |
          echo "End"
