Skip to content

Commit bd150f5

Browse files
feat: add GitHub Actions CI and semantic-release (#4)
* Add GitHub Actions CI and semantic-release (#3) * chore(release): 1.0.0 [skip ci] # 1.0.0 (2024-03-16) ### Features * add initial code ([#2](https://github.com/siuhui/async-postgres-watcher/issues/2)) ([6c868e1](https://github.com/siuhui/async-postgres-watcher/commit/6c868e108e8b68e6aacde833a4afe96f75345fe8)), closes [#1](https://github.com/siuhui/async-postgres-watcher/issues/1) --------- Co-authored-by: semantic-release-bot <[email protected]>
1 parent 6c868e1 commit bd150f5

9 files changed

+218
-1
lines changed

.github/semantic.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Always validate the PR title AND all the commits
2+
titleAndCommits: true

.github/workflows/release.yml

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: tests
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
jobs:
8+
tests:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
python-version: ["3.9", "3.10", "3.11", "3.12"]
14+
os: [ubuntu-latest, macOS-latest, windows-latest]
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Set up PostgreSQL on Linux
26+
if: startsWith(runner.os, 'linux')
27+
run: |
28+
sudo systemctl start postgresql.service
29+
pg_isready
30+
sudo -u postgres psql --command="ALTER USER postgres WITH PASSWORD '123456'" --command="\du"
31+
32+
- name: Setup PostgreSQL on macOS
33+
if: startsWith(runner.os, 'macos')
34+
run: |
35+
brew services start postgresql
36+
echo "Check PostgreSQL service is running"
37+
i=10
38+
COMMAND='pg_isready'
39+
while [ $i -gt 0 ]; do
40+
echo "Check PostgreSQL service status"
41+
eval $COMMAND && break
42+
((i--))
43+
if [ $i == 0 ]; then
44+
echo "PostgreSQL service not ready, all attempts exhausted"
45+
exit 1
46+
fi
47+
echo "PostgreSQL service not ready, wait 10 more sec, attempts left: $i"
48+
sleep 10
49+
done
50+
psql --command="CREATE USER postgres PASSWORD '123456'" --command="\du" postgres
51+
52+
- name: Start PostgreSQL on Windows
53+
if: startsWith(runner.os, 'windows')
54+
run: |
55+
$pgService = Get-Service -Name postgresql*
56+
Set-Service -InputObject $pgService -Status running -StartupType automatic
57+
Start-Process -FilePath "$env:PGBIN\pg_isready" -Wait -PassThru
58+
& $env:PGBIN\psql --command="ALTER USER postgres WITH PASSWORD '123456'" --command="\du"
59+
60+
- name: Upgrade install tools
61+
run: python -m pip install --upgrade setuptools wheel
62+
63+
- name: Install dependencies
64+
run: |
65+
pip install -r requirements.txt
66+
67+
- name: Run tests
68+
run: |
69+
python -m unittest discover -s tests -t tests
70+
71+
coveralls:
72+
runs-on: ubuntu-latest
73+
steps:
74+
- name: Checkout
75+
uses: actions/checkout@v2
76+
77+
- name: Set up Python
78+
uses: actions/setup-python@v2
79+
with:
80+
python-version: 3.9
81+
82+
- name: Install dependencies
83+
run: |
84+
pip install -r requirements.txt
85+
pip install coveralls
86+
pip install coverage
87+
88+
- name: Set up PostgreSQL on Linux
89+
if: startsWith(runner.os, 'linux')
90+
run: |
91+
sudo systemctl start postgresql.service
92+
pg_isready
93+
sudo -u postgres psql --command="ALTER USER postgres WITH PASSWORD '123456'" --command="\du"
94+
95+
- name: Run tests
96+
run: coverage run -m unittest discover -s tests -t tests
97+
98+
- name: Upload coverage data to coveralls.io
99+
run: coveralls --service=github
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
103+
release:
104+
name: Release
105+
runs-on: ubuntu-latest
106+
needs: [ tests, coveralls ]
107+
steps:
108+
- name: Checkout
109+
uses: actions/checkout@v2
110+
with:
111+
fetch-depth: 0
112+
113+
- name: Setup Node.js
114+
uses: actions/setup-node@v1
115+
with:
116+
node-version: '20'
117+
118+
- name: Setup
119+
run: npm install -g semantic-release @semantic-release/github @semantic-release/changelog @semantic-release/commit-analyzer @semantic-release/git @semantic-release/release-notes-generator semantic-release-pypi
120+
121+
- name: Set up python
122+
uses: actions/setup-python@v2
123+
with:
124+
python-version: 3.9
125+
126+
- name: Install setuptools
127+
run: python -m pip install --upgrade setuptools wheel twine
128+
129+
- name: Release
130+
env:
131+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
133+
run: npx semantic-release

.releaserc.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"branches": "master",
3+
"plugins": [
4+
"@semantic-release/commit-analyzer",
5+
"@semantic-release/release-notes-generator",
6+
"semantic-release-pypi",
7+
"@semantic-release/github",
8+
[
9+
"@semantic-release/changelog",
10+
{
11+
"changelogFile": "CHANGELOG.md",
12+
"changelogTitle": "# Semantic Versioning Changelog"
13+
}
14+
],
15+
[
16+
"@semantic-release/git",
17+
{
18+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
19+
"assets": ["CHANGELOG.md", "pyproject.toml"]
20+
}
21+
]
22+
]
23+
}

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Semantic Versioning Changelog
2+
3+
# 1.0.0 (2024-03-16)
4+
5+
6+
### Features
7+
8+
* add initial code ([#2](https://github.com/siuhui/async-postgres-watcher/issues/2)) ([6c868e1](https://github.com/siuhui/async-postgres-watcher/commit/6c868e108e8b68e6aacde833a4afe96f75345fe8)), closes [#1](https://github.com/siuhui/async-postgres-watcher/issues/1)

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
# async-postgres-watcher
22

3+
[![tests](https://github.com/pycasbin/async-postgres-watcher/actions/workflows/release.yml/badge.svg)](https://github.com/pycasbin/async-postgres-watcher/actions)
4+
[![PyPI - Version](https://img.shields.io/pypi/v/casbin-async-postgres-watcher)](https://pypi.org/project/casbin-async-postgres-watcher/)
5+
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casbin-async-postgres-watcher.svg)](https://pypi.org/project/casbin-async-postgres-watcher/)
6+
[![PyPI - Downloads](https://img.shields.io/pypi/dm/casbin-async-postgres-watcher)](https://pypi.org/project/casbin-async-postgres-watcher/)
7+
[![PyPI - License](https://img.shields.io/pypi/l/casbin-async-postgres-watcher)](https://pypi.org/project/casbin-async-postgres-watcher/)
38
[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)
49

510
Async casbin role watcher to be used for monitoring updates to casbin policies
611

12+
## Installation
13+
14+
```bash
15+
pip install casbin-async-postgres-watcher
16+
```
17+
718
## Basic Usage Example
819

920
### With Flask-authz
@@ -39,8 +50,8 @@ casbin_enforcer = CasbinEnforcer(app, adapter)
3950
# If check_hostname is True, the SSL context is created with sslmode=verify-full.
4051
# If check_hostname is False, the SSL context is created with sslmode=verify-ca.
4152
watcher = AsyncPostgresWatcher(host=HOST, port=PORT, user=USER, password=PASSWORD, dbname=DBNAME, sslrootcert=SSLROOTCERT, check_hostname = True, sslcert=SSLCERT, sslkey=SSLKEY)
42-
4353
watcher.set_update_callback(casbin_enforcer.e.load_policy)
54+
4455
casbin_enforcer.set_watcher(watcher)
4556
```
4657

package.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"devDependencies": {
3+
"@semantic-release/changelog": "^6.0.3",
4+
"@semantic-release/git": "^10.0.1",
5+
"semantic-release": "^22.0.5",
6+
"semantic-release-pypi": "^3.0.0"
7+
}
8+
}

pyproject.toml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[project]
2+
name = "casbin-async-postgres-watcher"
3+
version = "1.0.0"
4+
authors = [
5+
{name = "hsluoyz", email = "[email protected]"},
6+
]
7+
description = "Async casbin role watcher to be used for monitoring updates to policies for PyCasbin"
8+
readme = "README.md"
9+
dynamic = ["dependencies"]
10+
requires-python = ">=3.5"
11+
license = {text = "Apache 2.0"}
12+
classifiers = [
13+
"Programming Language :: Python :: 3.9",
14+
"Programming Language :: Python :: 3.10",
15+
"Programming Language :: Python :: 3.11",
16+
"Programming Language :: Python :: 3.12",
17+
"License :: OSI Approved :: Apache Software License",
18+
"Operating System :: OS Independent",
19+
]
20+
21+
[project.urls]
22+
"Home-page" = "https://github.com/pycasbin/async-postgres-watcher"
23+
24+
[build-system]
25+
requires = ["setuptools"]
26+
build-backend = "setuptools.build_meta"
27+
28+
[tool.setuptools.packages.find]
29+
exclude = ["tests", "tests.*"]
30+
31+
[tool.setuptools.dynamic]
32+
dependencies = {file = ["requirements.txt"]}

requirements.txt

-81 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)