diff --git a/.github/actions/action_1/action.yml b/.github/actions/action_1/action.yml new file mode 100644 index 0000000000000..baf3d6f163d58 --- /dev/null +++ b/.github/actions/action_1/action.yml @@ -0,0 +1,25 @@ +name: 'setup_and_restore_python' +description: 'Setup and restore Python environment' +runs: + using: "composite" + steps: + - name: Set up Python ${{ env.DEFAULT_PYTHON }} + uses: actions/setup-python@v2.1.1 + id: python + with: + python-version: ${{ env.DEFAULT_PYTHON }} + - name: Restore base Python virtual environment + id: cache-venv + uses: actions/cache@v2 + with: + path: venv + key: >- + ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version + }}-${{ hashFiles('requirements.txt') }}-${{ + hashFiles('requirements_test.txt') }}-${{ + hashFiles('homeassistant/package_constraints.txt') }} + - name: Fail job if Python cache restore failed + if: steps.cache-venv.outputs.cache-hit != 'true' + run: | + echo "Failed to restore Python virtual environment from cache" + exit 1 diff --git a/.github/actions/action_2/action.yml b/.github/actions/action_2/action.yml new file mode 100644 index 0000000000000..1b04c4f33f598 --- /dev/null +++ b/.github/actions/action_2/action.yml @@ -0,0 +1,17 @@ +name: 'setup_restore_python_and_pre_commit' +description: 'Setup and restore Python environment with pre-commit cache' +runs: + using: "composite" + steps: + - name: Restore pre-commit environment from cache + id: cache-precommit + uses: actions/cache@v2 + with: + path: ${{ env.PRE_COMMIT_HOME }} + key: | + ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} + - name: Fail job if cache restore failed + if: steps.cache-venv.outputs.cache-hit != 'true' + run: | + echo "Failed to restore Python virtual environment from cache" + exit 1 diff --git a/.github/actions/action_3/action.yml b/.github/actions/action_3/action.yml new file mode 100644 index 0000000000000..e77c322705e50 --- /dev/null +++ b/.github/actions/action_3/action.yml @@ -0,0 +1,75 @@ +name: 'setup_and_restore_python_2' +description: 'Setup and restore Python environment (2)' +runs: + using: "composite" + steps: + - name: + Restore full Python ${{ matrix.python-version }} virtual environment + id: cache-venv + uses: actions/cache@v2 + with: + path: venv + key: >- + ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ + hashFiles('requirements_test.txt') }}-${{ + hashFiles('requirements_all.txt') }}-${{ + hashFiles('homeassistant/package_constraints.txt') }} + - name: Fail job if Python cache restore failed + if: steps.cache-venv.outputs.cache-hit != 'true' + run: | + echo "Failed to restore Python virtual environment from cache" + exit 1 + - name: Check out code from GitHub + uses: actions/checkout@v2 + - name: + Restore full Python ${{ matrix.python-version }} virtual environment + id: cache-venv + uses: actions/cache@v2 + with: + path: venv + key: >- + ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ + hashFiles('requirements_test.txt') }}-${{ + hashFiles('requirements_all.txt') }}-${{ + hashFiles('homeassistant/package_constraints.txt') }} + - name: Fail job if Python cache restore failed + if: steps.cache-venv.outputs.cache-hit != 'true' + run: | + echo "Failed to restore Python virtual environment from cache" + exit 1 + - name: Check out code from GitHub + uses: actions/checkout@v2 + - name: + Restore full Python ${{ matrix.python-version }} virtual environment + id: cache-venv + uses: actions/cache@v2 + with: + path: venv + key: >- + ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ + hashFiles('requirements_test.txt') }}-${{ + hashFiles('requirements_all.txt') }}-${{ + hashFiles('homeassistant/package_constraints.txt') }} + - name: Fail job if Python cache restore failed + if: steps.cache-venv.outputs.cache-hit != 'true' + run: | + echo "Failed to restore Python virtual environment from cache" + exit 1 + - name: Check out code from GitHub + uses: actions/checkout@v2 + - name: + Restore full Python ${{ matrix.python-version }} virtual environment + id: cache-venv + uses: actions/cache@v2 + with: + path: venv + key: >- + ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ + hashFiles('requirements_test.txt') }}-${{ + hashFiles('requirements_all.txt') }}-${{ + hashFiles('homeassistant/package_constraints.txt') }} + - name: Fail job if Python cache restore failed + if: steps.cache-venv.outputs.cache-hit != 'true' + run: | + echo "Failed to restore Python virtual environment from cache" + exit 1 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6389a5428257f..51adcebae07ef 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -74,38 +74,8 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: | - ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - - name: Fail job if cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 + - uses: ./.github/actions/action_2 - name: Run bandit run: | . venv/bin/activate @@ -118,38 +88,8 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: | - ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - - name: Fail job if cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 + - uses: ./.github/actions/action_2 - name: Run black run: | . venv/bin/activate @@ -162,38 +102,8 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: | - ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - - name: Fail job if cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 + - uses: ./.github/actions/action_2 - name: Register codespell problem matcher run: | echo "::add-matcher::.github/workflows/matchers/codespell.json" @@ -228,38 +138,8 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: | - ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - - name: Fail job if cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 + - uses: ./.github/actions/action_2 - name: Register check executables problem matcher run: | echo "::add-matcher::.github/workflows/matchers/check-executables-have-shebangs.json" @@ -275,38 +155,8 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: | - ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - - name: Fail job if cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 + - uses: ./.github/actions/action_2 - name: Register flake8 problem matcher run: | echo "::add-matcher::.github/workflows/matchers/flake8.json" @@ -322,38 +172,8 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: | - ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - - name: Fail job if cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 + - uses: ./.github/actions/action_2 - name: Run isort run: | . venv/bin/activate @@ -366,38 +186,8 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: | - ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - - name: Fail job if cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 + - uses: ./.github/actions/action_2 - name: Register check-json problem matcher run: | echo "::add-matcher::.github/workflows/matchers/check-json.json" @@ -413,38 +203,8 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: | - ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - - name: Fail job if cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 + - uses: ./.github/actions/action_2 - name: Run pyupgrade run: | . venv/bin/activate @@ -468,38 +228,8 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache@v2 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: | - ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - - name: Fail job if cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 + - uses: ./.github/actions/action_2 - name: Register yamllint problem matcher run: | echo "::add-matcher::.github/workflows/matchers/yamllint.json" @@ -515,26 +245,7 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 - name: Run hassfest run: | . venv/bin/activate @@ -547,26 +258,7 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v2.1.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version - }}-${{ hashFiles('requirements.txt') }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_1 - name: Run gen_requirements_all.py run: | . venv/bin/activate @@ -623,22 +315,7 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: - Restore full Python ${{ matrix.python-version }} virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('requirements_all.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_3 - name: Register pylint problem matcher run: | echo "::add-matcher::.github/workflows/matchers/pylint.json" @@ -658,22 +335,7 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: - Restore full Python ${{ matrix.python-version }} virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('requirements_all.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_3 - name: Register mypy problem matcher run: | echo "::add-matcher::.github/workflows/matchers/mypy.json" @@ -695,22 +357,7 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: - Restore full Python ${{ matrix.python-version }} virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('requirements_all.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_3 - name: Register Python problem matcher run: | echo "::add-matcher::.github/workflows/matchers/python.json" @@ -756,22 +403,7 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v2 - - name: - Restore full Python ${{ matrix.python-version }} virtual environment - id: cache-venv - uses: actions/cache@v2 - with: - path: venv - key: >- - ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ - hashFiles('requirements_test.txt') }}-${{ - hashFiles('requirements_all.txt') }}-${{ - hashFiles('homeassistant/package_constraints.txt') }} - - name: Fail job if Python cache restore failed - if: steps.cache-venv.outputs.cache-hit != 'true' - run: | - echo "Failed to restore Python virtual environment from cache" - exit 1 + - uses: ./.github/actions/action_3 - name: Download all coverage artifacts uses: actions/download-artifact@v2 - name: Combine coverage results