Skip to content

Commit 97cf9c8

Browse files
committed
chore: implement ci workflows
1 parent 4465e65 commit 97cf9c8

File tree

4 files changed

+277
-0
lines changed

4 files changed

+277
-0
lines changed

.github/workflows/publish.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Publish
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types:
7+
- published
8+
9+
jobs:
10+
version:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
version: ${{ steps.set_output.outputs.version }}
14+
upload_url: ${{ steps.set_output.outputs.upload_url }}
15+
env:
16+
VERSION: ""
17+
UPLOAD_URL: ""
18+
steps:
19+
- name: Get version and upload url from release
20+
if: github.event_name == 'release'
21+
run: |
22+
echo "VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
23+
echo "UPLOAD_URL=${{ github.event.release.upload_url }}" >> $GITHUB_ENV
24+
25+
- name: Get release from API
26+
if: github.event_name == 'workflow_dispatch'
27+
id: release_api
28+
uses: octokit/[email protected]
29+
with:
30+
route: GET /repos/${{ github.repository }}/releases/latest
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.PAT }}
33+
34+
- name: Parse API response
35+
if: github.event_name == 'workflow_dispatch'
36+
run: |
37+
echo "VERSION=${{ fromJson(steps.release_api.outputs.data).tag_name }}" >> $GITHUB_ENV
38+
echo "UPLOAD_URL=${{ fromJson(steps.release_api.outputs.data).upload_url }}" >> $GITHUB_ENV
39+
40+
- name: Log version and upload URL
41+
run: |
42+
echo "Version: $VERSION"
43+
echo "Upload URL: $UPLOAD_URL"
44+
45+
- name: Fail if no version or no upload URL
46+
run: |
47+
if [[ -z "$VERSION" || -z "$UPLOAD_URL" ]]; then
48+
echo "Missing version or upload URL"
49+
exit 1
50+
fi
51+
52+
- name: Set outputs
53+
id: set_output
54+
run: |
55+
echo "version=$VERSION" >> $GITHUB_OUTPUT
56+
echo "upload_url=$UPLOAD_URL" >> $GITHUB_OUTPUT
57+
58+
package:
59+
needs: version
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Checkout code
63+
uses: actions/checkout@v4
64+
65+
- name: Set up Python
66+
uses: actions/setup-python@v4
67+
with:
68+
python-version: "3.11"
69+
70+
- name: Load cached Poetry installation
71+
id: cached-poetry
72+
uses: actions/cache@v3
73+
with:
74+
path: ~/.local
75+
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
76+
77+
- name: Install Poetry
78+
if: steps.cached-poetry.outputs.cache-hit != 'true'
79+
uses: snok/install-poetry@v1
80+
with:
81+
virtualenvs-create: true
82+
virtualenvs-in-project: true
83+
84+
- name: Load cached Poetry venv
85+
id: cached-poetry-venv
86+
uses: actions/cache@v3
87+
with:
88+
path: .venv
89+
key: poetry-venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
90+
91+
- name: Install dependencies
92+
if: steps.cached-poetry-venv.outputs.cache-hit != 'true'
93+
run: poetry install --no-interaction --no-root
94+
95+
- name: Install package
96+
run: poetry install --no-interaction
97+
98+
- name: Set package version
99+
run: |
100+
poetry version ${{ needs.version.outputs.version }}
101+
102+
- name: Build package
103+
run: |
104+
poetry build
105+
106+
- name: Upload package to pyPI
107+
run: |
108+
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
109+
poetry publish
110+
111+
- name: Upload package to release
112+
uses: actions/upload-release-asset@v1
113+
env:
114+
GITHUB_TOKEN: ${{ secrets.PAT }}
115+
with:
116+
upload_url: ${{ needs.version.outputs.upload_url }}
117+
asset_path: ./dist/eq3btsmart-${{ needs.version.outputs.version }}.tar.gz
118+
asset_name: eq3btsmart-${{ needs.version.outputs.version }}.tar.gz
119+
asset_content_type: application/gzip
120+
121+
- name: Upload wheel to release
122+
uses: actions/upload-release-asset@v1
123+
env:
124+
GITHUB_TOKEN: ${{ secrets.PAT }}
125+
with:
126+
upload_url: ${{ needs.version.outputs.upload_url }}
127+
asset_path: ./dist/eq3btsmart-${{ needs.version.outputs.version }}-py3-none-any.whl
128+
asset_name: eq3btsmart-${{ needs.version.outputs.version }}-py3-none-any.whl
129+
asset_content_type: application/zip

.github/workflows/quality.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Code Quality
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types:
7+
- opened
8+
- synchronize
9+
- reopened
10+
11+
jobs:
12+
cache:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Install Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: "3.11"
22+
23+
- name: Load cached Poetry installation
24+
id: cached-poetry
25+
uses: actions/cache@v3
26+
with:
27+
path: ~/.local
28+
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
29+
30+
- name: Install Poetry
31+
if: steps.cached-poetry.outputs.cache-hit != 'true'
32+
uses: snok/install-poetry@v1
33+
with:
34+
virtualenvs-create: true
35+
virtualenvs-in-project: true
36+
37+
- name: Load cached Poetry venv
38+
id: cached-poetry-venv
39+
uses: actions/cache@v3
40+
with:
41+
path: .venv
42+
key: poetry-venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
43+
44+
- name: Install dependencies
45+
if: steps.cached-poetry-venv.outputs.cache-hit != 'true'
46+
run: poetry install --no-interaction --no-root
47+
48+
- name: Install package
49+
run: poetry install --no-interaction
50+
51+
ruff:
52+
needs: cache
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
58+
- name: Install Python
59+
uses: actions/setup-python@v4
60+
with:
61+
python-version: "3.11"
62+
63+
- name: Load cached Poetry installation
64+
uses: actions/cache@v3
65+
with:
66+
path: ~/.local
67+
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
68+
69+
- name: Load cached Poetry venv
70+
uses: actions/cache@v3
71+
with:
72+
path: ~/.venv
73+
key: poetry-venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
74+
75+
- name: Install package
76+
run: |
77+
poetry install --no-interaction
78+
79+
- name: Run ruff
80+
run: |
81+
poetry run ruff . --check
82+
83+
mypy:
84+
needs: cache
85+
runs-on: ubuntu-latest
86+
steps:
87+
- name: Checkout
88+
uses: actions/checkout@v4
89+
90+
- name: Install Python
91+
uses: actions/setup-python@v4
92+
with:
93+
python-version: "3.11"
94+
95+
- name: Load cached Poetry installation
96+
uses: actions/cache@v3
97+
with:
98+
path: ~/.local
99+
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
100+
101+
- name: Load cached Poetry venv
102+
uses: actions/cache@v3
103+
with:
104+
path: ~/.venv
105+
key: poetry-venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
106+
107+
- name: Install package
108+
run: |
109+
poetry install --no-interaction
110+
111+
- name: Run mypy
112+
run: |
113+
poetry run mypy eq3btsmart custom_components/eq3btsmart

.github/workflows/release.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
concurrency: release
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
persist-credentials: false
19+
20+
- name: Semantic Release
21+
uses: cycjimmy/semantic-release-action@v4
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.PAT }}

.releaserc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"repository_url": "https://github.com/dbuezas/eq3btsmart.git",
3+
"branches": [
4+
"master"
5+
],
6+
"plugins": [
7+
"@semantic-release/commit-analyzer",
8+
"@semantic-release/release-notes-generator",
9+
"@semantic-release/github"
10+
],
11+
"tagFormat": "${version}"
12+
}

0 commit comments

Comments
 (0)