Skip to content

Update pre-commit hook biomejs/pre-commit to v2.3.0 #4682

Update pre-commit hook biomejs/pre-commit to v2.3.0

Update pre-commit hook biomejs/pre-commit to v2.3.0 #4682

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Test PR against HA-core
env:
CACHE_VERSION: 1
DEFAULT_PYTHON: "3.13"
PRE_COMMIT_HOME: ~/.cache/pre-commit
VENV: venv
# Do not run on 'push' (as the flow doesn't have access to the labels) - also disabled workflow_dispatch as such
# Workaround could be something like
# - name: Get PR labels
# run: |
# PR_LABELS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
# "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels")
# echo "PR Labels: $PR_LABELS"
on:
pull_request:
types:
- opened
- synchronize
- labeled
- unlabeled
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
# Determine cache key once
cache:
runs-on: ubuntu-latest
name: Cache identify
outputs:
cache-key: ${{ steps.set-key.outputs.cache-key }}
python-version: ${{ steps.python.outputs.python-version }}
steps:
- name: Check out committed code
uses: actions/checkout@v5
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v6
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Fetch HA pyproject
id: core-version
run: wget -O ha_pyproject.toml "https://raw.githubusercontent.com/home-assistant/core/refs/heads/dev/pyproject.toml"
- name: Compute cache key
id: set-key
run: echo "cache-key=${{ runner.os }}--${{ env.CACHE_VERSION }}-${{ hashFiles('pyproject.toml', 'requirements_test.txt', '.pre-commit-config.yaml', 'ha_pyproject.toml') }}" >> "$GITHUB_OUTPUT"
determine-mode:
name: Determine release or dev mode
runs-on: ubuntu-latest
outputs:
strict_dev: ${{ steps.set_mode.outputs.strict_dev }}
steps:
- name: Determine Branch Test Mode
id: set_mode
run: |
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'require-dev-pass') }}" == "true" ]]; then
echo "strict_dev=true" >> $GITHUB_OUTPUT
else
echo "strict_dev=false" >> $GITHUB_OUTPUT
fi
# Prepare default python version environment
prepare:
runs-on: ubuntu-latest
needs: cache
name: Prepare
steps:
- name: Prepare code checkout and python/pre-commit setup
id: cache-reuse
uses: plugwise/gh-actions/prepare-python-and-code@v1
with:
cache-key: ${{ needs.cache.outputs.cache-key }}
fail-on-miss: false # First time create cache (if not already exists)
python-version: ${{ needs.cache.outputs.python-version }}
venv-dir: ${{ env.VENV }}
precommit-home: ${{ env.PRE_COMMIT_HOME }}
clone-core: "true"
# Prepare default python version environment
ha-core-release-prepare:
runs-on: ubuntu-latest
name: Prepare and validate pre-commit
needs:
- cache
- prepare
steps:
- name: Check out committed code
uses: actions/checkout@v5
- name: Prepare code checkout and python/pre-commit setup
id: cache-reuse
uses: plugwise/gh-actions/prepare-python-and-code@v1
with:
cache-key: ${{ needs.cache.outputs.cache-key }}
fail-on-miss: false # First time create cache (if not already exists)
python-version: ${{ needs.cache.outputs.python-version }}
venv-dir: ${{ env.VENV }}
- name: Run all-files pre-commit excluding testing
run: |
# shellcheck disable=SC1091 # ingesting virtualenv
source venv-${{ needs.cache.outputs.python-version }}/bin/activate
pre-commit run --all-files --show-diff-on-failure
env: # While not problematic, save time on performing the local hooks as they are run from the complete script in the next job
SKIP: local-test-core-prep,local-test-pip-prep,local-testing,local-quality
# Prepare default python version environment
ha-core-testing:
runs-on: ubuntu-latest
name: Setup for HA-core (release/master)
continue-on-error: ${{ needs.determine-mode.outputs.strict_dev == 'true' }} # Allow master failures only if dev is strict
needs:
- cache
- prepare
- determine-mode
- ha-core-release-prepare
outputs:
release_failed: ${{ steps.ha_core_release_tests.outputs.release_failed }}
steps:
- name: Check out committed code
uses: actions/[email protected]
- name: Prepare code checkout and python/pre-commit setup
id: cache-reuse
uses: plugwise/gh-actions/prepare-python-and-code@v1
with:
cache-key: ${{ needs.cache.outputs.cache-key }}
fail-on-miss: false # First time create cache (if not already exists)
python-version: ${{ needs.cache.outputs.python-version }}
venv-dir: ${{ env.VENV }}
- name: Test through HA-core (master/release) - continue-on-error = ${{ needs.determine-mode.outputs.strict_dev == 'true' }}
id: ha_core_release_tests
continue-on-error: ${{ needs.determine-mode.outputs.strict_dev == 'true' }} # Allow master failures only if dev is strict
run: |
set +e
GITHUB_ACTIONS="" scripts/core-testing.sh
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "::warning::Release HA core incompatibility"
echo "release_failed=true" >> "$GITHUB_OUTPUT"
else
echo "Successfully tested against released HA-core"
echo "release_failed=false" >> "$GITHUB_OUTPUT"
fi
exit $EXIT_CODE
ha-core-dev-testing:
runs-on: ubuntu-latest
name: Setup for HA-core (dev)
continue-on-error: ${{ needs.determine-mode.outputs.strict_dev == 'false' }} # Allow dev failures unless strict
needs:
- cache
- prepare
- determine-mode
- ha-core-release-prepare
outputs:
dev_failed: ${{ steps.ha_core_dev_tests.outputs.dev_failed }}
steps:
- name: Check out committed code
uses: actions/[email protected]
- name: Prepare code checkout and python/pre-commit setup
id: cache-reuse
uses: plugwise/gh-actions/prepare-python-and-code@v1
with:
cache-key: ${{ needs.cache.outputs.cache-key }}
fail-on-miss: false # First time create cache (if not already exists)
python-version: ${{ needs.cache.outputs.python-version }}
venv-dir: ${{ env.VENV }}
- name: Test through HA-core (dev) - continue-on-error = ${{ needs.determine-mode.outputs.strict_dev == 'false' }}
id: ha_core_dev_tests
continue-on-error: ${{ needs.determine-mode.outputs.strict_dev == 'false' }} # Allow dev failures unless strict
run: |
set +e
GITHUB_ACTIONS="" BRANCH="dev" scripts/core-testing.sh
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "::warning::Development HA core incompatibility"
echo "dev_failed=true" >> "$GITHUB_OUTPUT"
else
echo "Successfully tested against dev HA-core"
echo "dev_failed=false" >> "$GITHUB_OUTPUT"
fi
exit $EXIT_CODE
final-comment:
runs-on: ubuntu-latest
needs:
- cache
- prepare
- determine-mode
- ha-core-release-prepare
- ha-core-testing
- ha-core-dev-testing
if: always()
steps:
- name: Create combined comment
run: |
# Get the results of the previous scripts
STRICT_DEV="${{ needs.determine-mode.outputs.strict_dev }}"
DEV_TESTS_FAILED="${{ needs.ha-core-dev-testing.outputs.dev_failed }}"
RELEASE_TESTS_FAILED="${{ needs.ha-core-release.outputs.release_failed }}"
FAIL_COUNT=0
# Get the action-bot's latest state
LAST_REVIEW_STATE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews" \
| jq -r '[.[] | select(.user.login=="github-actions[bot]")] | last | .state')
if [[ $DEV_TESTS_FAILED == "true" ]]; then
COMMENT_BODY=":x: **Error while testing for Development HA-core:**\n\n"
else
COMMENT_BODY=":warning: **Warning while testing for RELEASED HA-core:**\n\n"
fi
if [[ $DEV_TESTS_FAILED == "true" ]]; then
if [[ $STRICT_DEV == "true" ]]; then
COMMENT_BODY+=":x: **Error:** Incompatible while testing against dev HA-core and required to pass.\n"
FAIL_COUNT=2
else
COMMENT_BODY+=":warning: **Warning:** Incompatible while testing against dev HA-core.\n"
FAIL_COUNT=1
fi
else
COMMENT_BODY+=":heavy_check_mark: **Success:** No problem with testing against dev HA-core.\n"
fi
if [[ $RELEASE_TESTS_FAILED == "true" ]]; then
if [[ $STRICT_DEV == "false" ]]; then
COMMENT_BODY+=":x: **Error:** Incompatible while testing against released HA-core and required to pass.\n"
FAIL_COUNT=2
else
COMMENT_BODY+=":warning: **Warning:** Incompatible while testing against released HA-core.\n"
FAIL_COUNT=1
fi
else
COMMENT_BODY+=":heavy_check_mark: **Success:** No problem with testing against released HA-core.\n"
fi
# If everything is OK, don't approve - if requested changes before and everything is good now, approve
# to release the 'requested changes' bit
if [[ $FAIL_COUNT -eq 0 ]]; then
if [[ "$LAST_REVIEW_STATE" == "CHANGES_REQUESTED" ]]; then
echo "Lifting previous changes requested — submitting approval."
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
--data "{\"event\": \"APPROVE\", \"body\": \"$COMMENT_BODY\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
else
echo "No prior changes requested — skipping approval."
fi
fi
if [[ $FAIL_COUNT -eq 1 ]]; then
echo "Comment and approve the pull request"
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
--data "{\"event\": \"APPROVE\", \"body\": \"$COMMENT_BODY\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
fi
if [[ $FAIL_COUNT -eq 2 ]]; then
echo "Requesting changes on the pull request"
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
--data "{\"event\": \"REQUEST_CHANGES\", \"body\": \"$COMMENT_BODY\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
fi