Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: implement ci workflows #96

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Publish

on:
workflow_dispatch:
release:
types:
- published

jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set_output.outputs.version }}
upload_url: ${{ steps.set_output.outputs.upload_url }}
env:
VERSION: ""
UPLOAD_URL: ""
steps:
- name: Get version and upload url from release
if: github.event_name == 'release'
run: |
echo "VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
echo "UPLOAD_URL=${{ github.event.release.upload_url }}" >> $GITHUB_ENV

- name: Get release from API
if: github.event_name == 'workflow_dispatch'
id: release_api
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/releases/latest
env:
GITHUB_TOKEN: ${{ secrets.PAT }}

- name: Parse API response
if: github.event_name == 'workflow_dispatch'
run: |
echo "VERSION=${{ fromJson(steps.release_api.outputs.data).tag_name }}" >> $GITHUB_ENV
echo "UPLOAD_URL=${{ fromJson(steps.release_api.outputs.data).upload_url }}" >> $GITHUB_ENV

- name: Log version and upload URL
run: |
echo "Version: $VERSION"
echo "Upload URL: $UPLOAD_URL"

- name: Fail if no version or no upload URL
run: |
if [[ -z "$VERSION" || -z "$UPLOAD_URL" ]]; then
echo "Missing version or upload URL"
exit 1
fi

- name: Set outputs
id: set_output
run: |
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "upload_url=$UPLOAD_URL" >> $GITHUB_OUTPUT

package:
needs: version
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached Poetry venv
id: cached-poetry-venv
uses: actions/cache@v3
with:
path: .venv
key: poetry-venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-venv.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Install package
run: poetry install --no-interaction

- name: Set package version
run: |
poetry version ${{ needs.version.outputs.version }}

- name: Build package
run: |
poetry build

- name: Upload package to pyPI
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish

- name: Upload package to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
upload_url: ${{ needs.version.outputs.upload_url }}
asset_path: ./dist/eq3btsmart-${{ needs.version.outputs.version }}.tar.gz
asset_name: eq3btsmart-${{ needs.version.outputs.version }}.tar.gz
asset_content_type: application/gzip

- name: Upload wheel to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
upload_url: ${{ needs.version.outputs.upload_url }}
asset_path: ./dist/eq3btsmart-${{ needs.version.outputs.version }}-py3-none-any.whl
asset_name: eq3btsmart-${{ needs.version.outputs.version }}-py3-none-any.whl
asset_content_type: application/zip
113 changes: 113 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Code Quality

on:
workflow_dispatch:
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
cache:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached Poetry venv
id: cached-poetry-venv
uses: actions/cache@v3
with:
path: .venv
key: poetry-venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-venv.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Install package
run: poetry install --no-interaction

ruff:
needs: cache
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Load cached Poetry installation
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Load cached Poetry venv
uses: actions/cache@v3
with:
path: ~/.venv
key: poetry-venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install package
run: |
poetry install --no-interaction

- name: Run ruff
run: |
poetry run ruff eq3btsmart custom_components/eq3btsmart

mypy:
needs: cache
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Load cached Poetry installation
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Load cached Poetry venv
uses: actions/cache@v3
with:
path: ~/.venv
key: poetry-venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install package
run: |
poetry install --no-interaction

- name: Run mypy
run: |
poetry run mypy eq3btsmart custom_components/eq3btsmart
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release

on:
workflow_dispatch:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest
concurrency: release
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
12 changes: 12 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"repository_url": "https://github.com/dbuezas/eq3btsmart.git",
"branches": [
"master"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github"
],
"tagFormat": "${version}"
}
2 changes: 1 addition & 1 deletion eq3btsmart/bleakconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def async_get_connection(self) -> BleakClient:

self._on_connection_event()

if self._conn.is_connected:
if self._conn is not None and self._conn.is_connected:
_LOGGER.debug("[%s] Connected", self._name)
else:
raise BackendException("Can't connect")
Expand Down
Loading