name: Build and publish lint docker image

# Only run when docker paths change
on:
  push:
    branches: [dev]
    paths:
      - 'docker/Dockerfile.lint'
      - 'requirements.txt'
      - 'requirements_optional.txt'
      - 'requirements_test.txt'
      - 'platformio.ini'
      - '.github/workflows/docker-lint-build.yml'

jobs:
  deploy-docker:
    name: Build and publish docker containers
    if: github.repository == 'esphome/esphome'
    runs-on: ubuntu-latest
    strategy:
      matrix:
        arch: [amd64, armv7, aarch64]
        build_type: ["lint"]
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.9'
    - name: Set TAG
      run: |
        echo "TAG=1.1" >> $GITHUB_ENV

    - name: Run build
      run: |
        docker/build.py \
          --tag "${TAG}" \
          --arch "${{ matrix.arch }}" \
          --build-type "${{ matrix.build_type }}" \
          build

    - name: Log in to docker hub
      uses: docker/login-action@v1
      with:
        username: ${{ secrets.DOCKER_USER }}
        password: ${{ secrets.DOCKER_PASSWORD }}
    - name: Log in to the GitHub container registry
      uses: docker/login-action@v1
      with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

    - name: Run push
      run: |
        docker/build.py \
          --tag "${TAG}" \
          --arch "${{ matrix.arch }}" \
          --build-type "${{ matrix.build_type }}" \
          push

  deploy-docker-manifest:
    if: github.repository == 'esphome/esphome'
    runs-on: ubuntu-latest
    needs: [deploy-docker]
    strategy:
      matrix:
        build_type: ["lint"]
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.9'
    - name: Set TAG
      run: |
        echo "TAG=1.1" >> $GITHUB_ENV
    - name: Enable experimental manifest support
      run: |
        mkdir -p ~/.docker
        echo "{\"experimental\": \"enabled\"}" > ~/.docker/config.json

    - name: Log in to docker hub
      uses: docker/login-action@v1
      with:
        username: ${{ secrets.DOCKER_USER }}
        password: ${{ secrets.DOCKER_PASSWORD }}
    - name: Log in to the GitHub container registry
      uses: docker/login-action@v1
      with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

    - name: Run manifest
      run: |
        docker/build.py \
          --tag "${TAG}" \
          --build-type "${{ matrix.build_type }}" \
          manifest