Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit ca01fe2

Browse files
committed
ci: add test and deploy jobs
1 parent 9682817 commit ca01fe2

File tree

5 files changed

+285
-6
lines changed

5 files changed

+285
-6
lines changed

.github/workflows/python.yaml

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
# Tests on Python 3.7+
2-
name: Python Test
1+
name: Python
32

43
on:
54
push:
65
branches: [ "*" ]
76
pull_request:
87
branches: [ master ]
8+
release:
9+
types:
10+
- created
911

1012
jobs:
11-
build:
12-
13+
lint:
14+
name: Run linters
1315
runs-on: ubuntu-latest
1416
strategy:
1517
matrix:
@@ -41,3 +43,71 @@ jobs:
4143
if: always()
4244
run: |
4345
poetry run mypy .
46+
47+
- name: Run custom style checks
48+
if: always()
49+
run: |
50+
poetry run cicd/custom_style_check.py
51+
52+
# test:
53+
# name: Run the tests
54+
# runs-on: ubuntu-latest
55+
# strategy:
56+
# matrix:
57+
# python-version: [ 3.7, 3.8, 3.9 ]
58+
59+
# steps:
60+
# - uses: actions/checkout@v2
61+
# - name: Set up Python ${{ matrix.python-version }}
62+
# uses: actions/setup-python@v2
63+
# with:
64+
# python-version: ${{ matrix.python-version }}
65+
# - name: Run image
66+
# uses: abatilo/[email protected]
67+
# - name: Run pytest
68+
# run: |
69+
# poetry run pytest -vv
70+
71+
build:
72+
name: Build linkedin_messaging
73+
runs-on: ubuntu-latest
74+
strategy:
75+
matrix:
76+
python-version: [ 3.7, 3.8, 3.9 ]
77+
78+
steps:
79+
- uses: actions/checkout@v2
80+
- name: Set up Python ${{ matrix.python-version }}
81+
uses: actions/setup-python@v2
82+
with:
83+
python-version: ${{ matrix.python-version }}
84+
- name: Run image
85+
uses: abatilo/[email protected]
86+
- name: Run build
87+
run: |
88+
poetry build
89+
90+
deploy:
91+
name: Deploy to pypi
92+
runs-on: ubuntu-latest
93+
needs: [lint, build]
94+
if: ${{ github.event_name == 'release' && github.event.action == 'created' }}
95+
96+
steps:
97+
- uses: actions/checkout@v2
98+
- name: Set up Python 3.8
99+
uses: actions/setup-python@v2
100+
with:
101+
python-version: 3.8
102+
- name: Run image
103+
uses: abatilo/[email protected]
104+
105+
- name: Dry run publish
106+
run: |
107+
poetry config pypi-token.pypi ${{ secrets.PYPI_DEPLOY_TOKEN }}
108+
poetry publish --build --dry-run
109+
110+
- name: Actual publish
111+
run: |
112+
poetry config pypi-token.pypi ${{ secrets.PYPI_DEPLOY_TOKEN }}
113+
poetry publish --build

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# v0.1.0
2+
3+
This is the initial release. Features include:
4+
5+
* Login helper and session manager. Works with 2FA.
6+
* Get a list of the user's conversations.
7+
* Retrieve the messages and media in a particular conversation.
8+
* Send messages to a particular conversation or set of recipients. Multimedia is
9+
supported.
10+
* An event listener structure for listening for new events.

cicd/custom_style_check.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#! /usr/bin/env python
2+
3+
"""
4+
Checks for TODO comments and makes sure they have an associated issue. Formats that are
5+
accepted are:
6+
7+
TODO (#1)
8+
TODO (#1)
9+
TODO (project#1)
10+
TODO (namespace/project#1)
11+
TODO (namespace/namespace/project#1)
12+
13+
Additionally, the TODO can be postfixed with ``:``.
14+
"""
15+
16+
import re
17+
import sys
18+
from pathlib import Path
19+
from typing import Pattern
20+
21+
from termcolor import cprint
22+
23+
todo_re = re.compile(r"\s*#\s*TODO:?\s*")
24+
accounted_for_todo = re.compile(r"\s*#\s*TODO:?\s*\(([\w-]+(/[\w-]+)*)?#\d+\)")
25+
26+
27+
def noqa_re(error_id: str = "") -> Pattern:
28+
return re.compile(rf"#\s*noqa(:\s*{error_id})?\s*\n$")
29+
30+
31+
def eprint(*strings):
32+
cprint(" ".join(strings), "red", end="", attrs=["bold"])
33+
34+
35+
def check_file(path: Path) -> bool:
36+
print(f"Checking {path.absolute()}...") # noqa: T001
37+
file = path.open()
38+
valid = True
39+
40+
for i, line in enumerate(file, start=1):
41+
if todo_re.match(line) and not accounted_for_todo.match(line):
42+
eprint(f"{i}: {line}")
43+
valid = False
44+
45+
file.close()
46+
return valid
47+
48+
49+
valid = True
50+
for path in Path("linkedin_messaging").glob("**/*.py"):
51+
valid &= check_file(path)
52+
53+
for path in Path("tests").glob("**/*.py"):
54+
valid &= check_file(path)
55+
56+
"""
57+
Checks that the version in the CHANGELOG is the same as the version in ``__init__.py``.
58+
"""
59+
with open(Path("linkedin_messaging/__init__.py")) as f:
60+
for line in f:
61+
if line.startswith("__version__"):
62+
version = eval(line.split()[-1])
63+
break
64+
else: # nobreak
65+
raise AssertionError("No version in linkedin_messaging/__init__.py")
66+
67+
with open(Path("pyproject.toml")) as f:
68+
for line in f:
69+
if line.startswith("version ="):
70+
assert eval(line.split()[-1]) == version, "Version mismatch: pyproject.toml"
71+
break
72+
else: # nobreak
73+
raise AssertionError("No version in pyproject.toml")
74+
75+
with open(Path("CHANGELOG.md")) as f:
76+
assert f.readline().strip() == f"# v{version}", "Version mismatch: CHANGELOG"
77+
78+
79+
sys.exit(0 if valid else 1)

poetry.lock

Lines changed: 119 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)