<commit_before># https://dev.azure.com/home-assistant

trigger:
  batch: true
  tags:
    include:
    - '*'
pr: none
variables:
  - name: versionBuilder
    value: '5.1'
  - group: docker
  - group: github
  - group: twine


stages:

- stage: 'Validate'
  jobs:
  - job: 'VersionValidate'
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - task: UsePythonVersion@0
      displayName: 'Use Python 3.7'
      inputs:
        versionSpec: '3.7'
    - script: |
        setup_version="$(python setup.py -V)"
        branch_version="$(Build.SourceBranchName)"

        if [ "${setup_version}" != "${branch_version}" ]; then
          echo "Version of tag ${branch_version} don't match with ${setup_version}!"
          exit 1
        fi
      displayName: 'Check version of branch/tag'
    - script: |
        sudo apt-get install -y --no-install-recommends \
          jq curl

        release="$(Build.SourceBranchName)"
        created_by="$(curl -s https://api.github.com/repos/home-assistant/home-assistant/releases/tags/${release} | jq --raw-output '.author.login')"

        if [[ "${created_by}" =~ ^(balloob|pvizeli|fabaff|robbiet480)$ ]]; then
          exit 0
        fi

        echo "${created_by} is not allowed to create an release!"
        exit 1
      displayName: 'Check rights'

- stage: 'Build'
  jobs:
  - job: 'ReleasePython'
    condition: and(startsWith(variables['Build.SourceBranch'], 'refs/tags'), succeeded())
    dependsOn:
    - 'VersionValidate'
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - task: UsePythonVersion@0
      displayName: 'Use Python 3.7'
      inputs:
        versionSpec: '3.7'
    - script: pip install twine wheel
      displayName: 'Install tools'
    - script: python setup.py sdist bdist_wheel
      displayName: 'Build package'
    - script: |
        export TWINE_USERNAME="$(twineUser)"
        export TWINE_PASSWORD="$(<PASSWORD>)"
        
        twine upload dist/* --skip-existing
      displayName: 'Upload pypi'
  - job: 'ReleaseDocker'
    condition: and(startsWith(variables['Build.SourceBranch'], 'refs/tags'), succeeded())
    dependsOn:
    - 'VersionValidate'
    timeoutInMinutes: 240
    pool:
      vmImage: 'ubuntu-latest'
    strategy:
      maxParallel: 5
      matrix:
        amd64:
          buildArch: 'amd64'
          buildMachine: 'qemux86-64,intel-nuc'
        i386:
          buildArch: 'i386'
          buildMachine: 'qemux86'
        armhf:
          buildArch: 'armhf'
          buildMachine: 'qemuarm,raspberrypi'
        armv7:
          buildArch: 'armv7'
          buildMachine: 'raspberrypi2,raspberrypi3,odroid-xu,tinker'
        aarch64:
          buildArch: 'aarch64'
          buildMachine: 'qemuarm-64,raspberrypi3-64,odroid-c2,orangepi-prime'
    steps:
    - script: sudo docker login -u $(dockerUser) -p $(dockerPassword)
      displayName: 'Docker hub login'
    - script: sudo docker pull homeassistant/amd64-builder:$(versionBuilder)
      displayName: 'Install Builder'
    - script: |
        set -e

        sudo docker run --rm --privileged \
          -v ~/.docker:/root/.docker \
          -v /run/docker.sock:/run/docker.sock:rw \
          homeassistant/amd64-builder:$(versionBuilder) \
          --homeassistant $(Build.SourceBranchName) "--$(buildArch)" \
          -r https://github.com/home-assistant/hassio-homeassistant \
          -t generic --docker-hub homeassistant

        sudo docker run --rm --privileged \
          -v ~/.docker:/root/.docker \
          -v /run/docker.sock:/run/docker.sock:rw \
          homeassistant/amd64-builder:$(versionBuilder) \
          --homeassistant-machine "$(Build.SourceBranchName)=$(buildMachine)" \
          -r https://github.com/home-assistant/hassio-homeassistant \
          -t machine --docker-hub homeassistant
      displayName: 'Build Release'

- stage: 'Publish'
  jobs:
  - job: 'ReleaseHassio'
    condition: and(startsWith(variables['Build.SourceBranch'], 'refs/tags'), succeeded())
    dependsOn:
      - 'ReleaseDocker'
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - script: |
        sudo apt-get install -y --no-install-recommends \
          git jq curl

        git config --global user.name "<NAME>"
        git config --global user.email "<EMAIL>"
        git config --global credential.helper store

        echo "https://$(githubToken):x-oauth-basic@github.com" > $HOME/.git-credentials
      displayName: 'Install requirements'
    - script: |
        set -e

        version="$(Build.SourceBranchName)"

        git clone https://github.com/home-assistant/hassio-version
        cd hassio-version
<commit_msg>Update azure-pipelines-release.yml for Azure Pipelines<commit_after># https://dev.azure.com/home-assistant

trigger:
  batch: true
  tags:
    include:
    - '*'
pr: none
variables:
  - name: versionBuilder
    value: '5.1'
  - group: docker
  - group: github
  - group: twine


stages:

- stage: 'Validate'
  jobs:
  - job: 'VersionValidate'
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - task: UsePythonVersion@0
      displayName: 'Use Python 3.7'
      inputs:
        versionSpec: '3.7'
    - script: |
        setup_version="$(python setup.py -V)"
        branch_version="$(Build.SourceBranchName)"

        if [ "${setup_version}" != "${branch_version}" ]; then
          echo "Version of tag ${branch_version} don't match with ${setup_version}!"
          exit 1
        fi
      displayName: 'Check version of branch/tag'
    - script: |
        sudo apt-get install -y --no-install-recommends \
          jq curl

        release="$(Build.SourceBranchName)"
        created_by="$(curl -s https://api.github.com/repos/home-assistant/home-assistant/releases/tags/${release} | jq --raw-output '.author.login')"

        if [[ "${created_by}" =~ ^(balloob|pvizeli|fabaff|robbiet480)$ ]]; then
          exit 0
        fi

        echo "${created_by} is not allowed to create an release!"
        exit 1
      displayName: 'Check rights'

- stage: 'Build'
  jobs:
  - job: 'ReleasePython'
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - task: UsePythonVersion@0
      displayName: 'Use Python 3.7'
      inputs:
        versionSpec: '3.7'
    - script: pip install twine wheel
      displayName: 'Install tools'
    - script: python setup.py sdist bdist_wheel
      displayName: 'Build package'
    - script: |
        export TWINE_USERNAME="$(twineUser)"
        export TWINE_PASSWORD="$(<PASSWORD>)"
        
        twine upload dist/* --skip-existing
      displayName: 'Upload pypi'
  - job: 'ReleaseDocker'
    timeoutInMinutes: 240
    pool:
      vmImage: 'ubuntu-latest'
    strategy:
      maxParallel: 5
      matrix:
        amd64:
          buildArch: 'amd64'
          buildMachine: 'qemux86-64,intel-nuc'
        i386:
          buildArch: 'i386'
          buildMachine: 'qemux86'
        armhf:
          buildArch: 'armhf'
          buildMachine: 'qemuarm,raspberrypi'
        armv7:
          buildArch: 'armv7'
          buildMachine: 'raspberrypi2,raspberrypi3,odroid-xu,tinker'
        aarch64:
          buildArch: 'aarch64'
          buildMachine: 'qemuarm-64,raspberrypi3-64,odroid-c2,orangepi-prime'
    steps:
    - script: sudo docker login -u $(dockerUser) -p $(dockerPassword)
      displayName: 'Docker hub login'
    - script: sudo docker pull homeassistant/amd64-builder:$(versionBuilder)
      displayName: 'Install Builder'
    - script: |
        set -e

        sudo docker run --rm --privileged \
          -v ~/.docker:/root/.docker \
          -v /run/docker.sock:/run/docker.sock:rw \
          homeassistant/amd64-builder:$(versionBuilder) \
          --homeassistant $(Build.SourceBranchName) "--$(buildArch)" \
          -r https://github.com/home-assistant/hassio-homeassistant \
          -t generic --docker-hub homeassistant

        sudo docker run --rm --privileged \
          -v ~/.docker:/root/.docker \
          -v /run/docker.sock:/run/docker.sock:rw \
          homeassistant/amd64-builder:$(versionBuilder) \
          --homeassistant-machine "$(Build.SourceBranchName)=$(buildMachine)" \
          -r https://github.com/home-assistant/hassio-homeassistant \
          -t machine --docker-hub homeassistant
      displayName: 'Build Release'

- stage: 'Publish'
  jobs:
  - job: 'ReleaseHassio'
    condition: and(startsWith(variables['Build.SourceBranch'], 'refs/tags')
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - script: |
        sudo apt-get install -y --no-install-recommends \
          git jq curl

        git config --global user.name "<NAME>"
        git config --global user.email "<EMAIL>"
        git config --global credential.helper store

        echo "https://$(githubToken):x-oauth-basic@github.com" > $HOME/.git-credentials
      displayName: 'Install requirements'
    - script: |
        set -e

        version="$(Build.SourceBranchName)"

        git clone https://github.com/home-assistant/hassio-version
        cd hassio-version

{'fraction_non_alphanumeric': 0.12981947849342546, 'fraction_numerical': 0.012926231334967684, 'mean_word_length': 2.22262118491921, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7528106', 'n_tokens_mistral': 2968, 'n_tokens_neox': 2788, 'n_words': 615}