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: Migrate to github #25

Merged
merged 2 commits into from
Oct 18, 2023
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @famedly/workflows
100 changes: 100 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Python

on:
push:
branches: [ "main" ]
tags: [ "*" ]
pull_request:
branches: [ "*" ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Tests and coverage
runs-on: ubuntu-latest-16core
env:
HATCH_ENV: "ci"
# Workaround for read-only dependabot GITHUB_TOKEN in meow-coverage
permissions:
issues: write
pull-requests: write
contents: read
strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11" ]
steps:
- uses: actions/checkout@v4
with:
path: head
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install dependencies
working-directory: head
run: |
python -m pip install --upgrade pip
python -m pip install hatch

- name: Formatting
uses: famedly/black@stable
with:
src: head
options: "--check --verbose"

- name: Prepare lint
shell: bash
run: echo PYTHON_TARGET="py${{ matrix.python-version }}" | sed -r "s/\.//" >> $GITHUB_ENV

- name: Lint
uses: chartboost/ruff-action@2bc585f1253832f5a5220d7fbf86976822116147
with:
args: --target-version ${{ env.PYTHON_TARGET }}
src: head

- name: Tests and coverage
working-directory: head
run: hatch run head-cov

- name: Load base coverage results from cache
if: github.event_name == 'pull_request'
id: cache-coverage
uses: actions/cache@v3
with:
path: ./base.lcov
key: coverage-${{ github.event.pull_request.base.sha }}

- name: Pull base
uses: actions/checkout@v3
if: github.event_name == 'pull_request' && steps.cache-coverage.outputs.cache-hit != 'true'
with:
ref: ${{ github.event.pull_request.base.ref }}
repository: ${{ github.event.pull_request.base.full_name }}
path: base

- name: Generate base coverage
if: github.event_name == 'pull_request' && steps.cache-coverage.outputs.cache-hit != 'true'
working-directory: base
# Needed for initial run
continue-on-error: true
run: hatch run base-cov

- name: Meow Coverage
id: coverage-report
continue-on-error: true
uses: famedly/meow-coverage@main
if: github.event_name == 'pull_request'
with:
new-lcov-file: 'head.lcov'
old-lcov-file: ${{ github.event_name == 'pull_request' && 'base.lcov' || '' }}
source-prefix: 'synapse_invite_policies/'
pr-number: ${{ github.event_name == 'pull_request' && github.event.pull_request.number || '' }}
repo-name: ${{ github.repository }}
commit-id: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.event.after }}
github-token: ${{ secrets.GITHUB_TOKEN }}

31 changes: 0 additions & 31 deletions .gitlab-ci.yml

This file was deleted.

8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ dependencies = ["jwcrypto", "twisted"]
version = "0.3.2"

[project.urls]
Documentation = "https://gitlab.com/famedly/company/backend/services/synapse-token-authenticator#synapse-token-authenticator"
Issues = "https://gitlab.com/famedly/company/backend/services/synapse-token-authenticator/-/issues"
Source = "https://gitlab.com/famedly/company/backend/services/synapse-token-authenticator/"
Documentation = "https://github.com/famedly/synapse-token-authenticator"
Issues = "https://github.com/famedly/synapse-token-authenticator/issues"
Source = "https://github.com/famedly/synapse-token-authenticator"

[tool.hatch.envs.default]
dependencies = [
Expand All @@ -45,6 +45,8 @@ format = "black ."

[tool.hatch.envs.ci.scripts]
format = "black --check ."
head-cov = "pytest --cov-report=lcov:../head.lcov --cov-config=pyproject.toml --cov=synapse_token_authenticator --cov=tests"
base-cov = "pytest --cov-report=lcov:../base.lcov --cov-config=pyproject.toml --cov=synapse_token_authenticator --cov=tests"

[tool.coverage.run]
branch = true
Expand Down
4 changes: 3 additions & 1 deletion synapse_token_authenticator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from synapse_token_authenticator.token_authenticator import TokenAuthenticator
from synapse_token_authenticator.token_authenticator import (
TokenAuthenticator, # noqa: F401
)
4 changes: 2 additions & 2 deletions synapse_token_authenticator/token_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import synapse
from synapse.module_api import ModuleApi
from synapse.types import UserID, create_requester
from synapse.types import UserID

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -159,7 +159,7 @@ class _TokenAuthenticatorConfig(object):
raise Exception("Keyfile doesn't exist")

_config.algorithm = config.get("algorithm", "HS512")
if not _config.algorithm in [
if _config.algorithm not in [
"HS256",
"HS384",
"HS512",
Expand Down
4 changes: 1 addition & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

from synapse.server import HomeServer
from synapse.module_api import ModuleApi
from synapse.handlers.auth import AuthHandler
from synapse.handlers.register import RegistrationHandler

admins = {}

Expand Down Expand Up @@ -81,7 +79,7 @@ def get_token(
claims.update({"admin": admin})

if exp_in != -1:
if exp_in == None:
if exp_in is None:
claims["exp"] = int(time.time()) + 120
else:
claims["exp"] = int(time.time()) + exp_in
Expand Down
1 change: 0 additions & 1 deletion tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from twisted.trial import unittest
from twisted.internet import defer
from . import get_auth_provider, get_token


Expand Down
Loading