Skip to content

Commit

Permalink
Run tests with the same dependency version in production
Browse files Browse the repository at this point in the history
  • Loading branch information
vivodi committed Jan 25, 2025
1 parent 8451846 commit 28c4d95
Show file tree
Hide file tree
Showing 24 changed files with 142,619 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Update the Changelog
run: |
set -x
uv run update-changelog.py wiki/ChangeLog.md
uv run scripts/update_changelog.py wiki/ChangeLog.md
cd wiki
git add ChangeLog.md
if ! git diff --cached --exit-code; then
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5
with:
images: |
flexget/flexget
${{ secrets.DOCKERHUB_USERNAME }}/flexget
ghcr.io/${{ github.repository_owner }}/flexget
tags: |
type=semver,pattern={{version}}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ jobs:
env:
UV_PUBLISH_TOKEN: ${{ secrets.pypi_token }}
run: |
./release.sh
scripts/release.sh
- name: Build Changelog
id: changelog
if: env.release_tag
run: |
echo 'CHANGELOG_BODY<<EOF' >> $GITHUB_ENV
uv run dev_tools.py get-changelog ${{ env.release_tag }} >> $GITHUB_ENV
uv run scripts/dev_tools.py get-changelog ${{ env.release_tag }} >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Export config schema
if: env.release_tag
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/.Python
FlexGet.egg-info/
bin/
Scripts/
include/
lib/
local
Expand Down Expand Up @@ -49,4 +48,4 @@ flexget/ui/v1/app
.mypy_cache/
.tool-versions
.devcontainer/
.venv
.venv
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ COPY --from=ghcr.io/astral-sh/uv:0.5.22@sha256:db7daf75d8f12d1c982df42d9b01519fc
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
WORKDIR /flexget
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=bundle_webui.py,target=bundle_webui.py \
--mount=type=bind,source=scripts/bundle_webui.py,target=bundle_webui.py \
uv run bundle_webui.py
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Build settings
[project]
name = "FlexGet"
name = "flexgettest"
description = """\
FlexGet is a program aimed to automate downloading or processing content (torrents, podcasts, etc.) from \
different sources like RSS-feeds, html-pages, various sites and more.\
Expand Down Expand Up @@ -69,7 +69,7 @@ docs = [
"sphinx ~=8.1; python_version >= '3.10'"
]
plugin-test = [
# These are optional dependencies for plugins that have tests in the test suite
# These are optional dependencies for the plugins that have tests in the test suite
"boto3 ~=1.35",
"plexapi ~=4.16",
"pysftp ~=0.2.9",
Expand Down Expand Up @@ -120,7 +120,7 @@ exclude = ["/flexget/tests/cassettes"]
[tool.hatch.build.targets.wheel.hooks.custom]
# build with env variable HATCH_BUILD_HOOKS_ENABLE=true to bundle the webui when building
enable-by-default = false
path = "bundle_webui.py"
path = "scripts/bundle_webui.py"

[tool.hatch.build.targets.wheel]
include = [
Expand Down
7 changes: 7 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
"npm": {
"enabled": false
},
"pep723": {
"fileMatch": [
"scripts/bundle_webui.py",
"scripts/dev_tools.py",
"scripts/update_changelog.py"
]
},
"pip_requirements": {
"enabled": false
},
Expand Down
6 changes: 3 additions & 3 deletions bundle_webui.py → scripts/bundle_webui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "requests",
# "requests~=2.32",
# ]
# ///
import io
Expand All @@ -25,7 +25,7 @@ def dependencies(self) -> list[str]:
return ["requests"]

def clean(self, versions: list[str]) -> None:
p = Path(__file__).resolve().parent
p = Path(__file__).resolve().parent.parent
v1_path = p / "flexget" / "ui" / "v1" / "app"
v2_path = p / "flexget" / "ui" / "v2" / "dist"
if v1_path.exists():
Expand All @@ -45,7 +45,7 @@ def bundle_webui(ui_version: Optional[str] = None):
# once it is registered it can install the dep automatically during the build process.
import requests

ui_path = Path(__file__).resolve().parent / "flexget" / "ui"
ui_path = Path(__file__).resolve().parent.parent / "flexget" / "ui"

def download_extract(url, dest_path):
print(dest_path)
Expand Down
141,344 changes: 141,344 additions & 0 deletions scripts/cassettes/test_cli_bundle_webui.yaml

Large diffs are not rendered by default.

978 changes: 978 additions & 0 deletions scripts/cassettes/test_get_changelog.yaml

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions dev_tools.py → scripts/dev_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

import click
import requests

from bundle_webui import bundle_webui


def _get_version():
with open('flexget/_version.py') as f:
with open('./flexget/_version.py') as f:
g = globals()
loc = {}
exec(f.read(), g, loc)
Expand Down Expand Up @@ -66,7 +65,7 @@ def bump_version(bump_type):
if bump_type == 'dev':
ver_split.append('dev')
new_version = '.'.join(ver_split)
with fileinput.input('flexget/_version.py', inplace=True) as input:
with fileinput.input('./flexget/_version.py', inplace=True) as input:
for line in input:
if line.startswith('__version__ ='):
line = f"__version__ = '{new_version}'\n"
Expand Down
13 changes: 13 additions & 0 deletions scripts/dev_tools/dev_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Current FlexGet version.
This is contained in a separate file so that it can be easily read by setuptools, and easily edited and committed by
release scripts in continuous integration. Should only need to be set manually when doing a major/minor version bump.
The version should always be set to the <next release version>.dev
The github actions release job will automatically strip the .dev for release,
and update the version again for continued development.
NOTE: Should always have all three parts of the version, even on major and minor bumps. i.e. 4.0.0.dev, not 4.0.dev
"""

__version__ = '3.13.19.dev'
13 changes: 13 additions & 0 deletions scripts/dev_tools/release_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Current FlexGet version.
This is contained in a separate file so that it can be easily read by setuptools, and easily edited and committed by
release scripts in continuous integration. Should only need to be set manually when doing a major/minor version bump.
The version should always be set to the <next release version>.dev
The github actions release job will automatically strip the .dev for release,
and update the version again for continued development.
NOTE: Should always have all three parts of the version, even on major and minor bumps. i.e. 4.0.0.dev, not 4.0.dev
"""

__version__ = '3.13.19'
8 changes: 4 additions & 4 deletions release.sh → scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ fi
if git log --skip 1 origin/master..origin/develop|grep '^commit '; then

# Bump to new release version
uv run dev_tools.py bump-version release
VERSION=$(uv run dev_tools.py version)
uv run scripts/dev_tools.py bump-version release
VERSION=$(uv run scripts/dev_tools.py version)
export VERSION
uv lock --upgrade-package flexget

Expand All @@ -39,11 +39,11 @@ if git log --skip 1 origin/master..origin/develop|grep '^commit '; then
echo "release_tag=v${VERSION}" >> $GITHUB_ENV

# Bump to new dev version, then commit again
uv run dev_tools.py bump-version dev
uv run scripts/dev_tools.py bump-version dev
uv lock --upgrade-package flexget
git add flexget/_version.py
git add uv.lock
git commit -m "Prepare v$(uv run dev_tools.py version)"
git commit -m "Prepare v$(uv run scripts/dev_tools.py version)"

# master branch should be at the release we tagged
git branch -f master v${VERSION}
Expand Down
82 changes: 82 additions & 0 deletions scripts/test_dev_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import os
import shutil
from pathlib import Path

import pytest
import vcr
from click.testing import CliRunner

from flexget.ui import v1, v2
from scripts.dev_tools import bump_version, cli_bundle_webui, get_changelog, version


def test_version(tmp_path):
os.makedirs(tmp_path / 'flexget', exist_ok=True)
shutil.copy('dev_tools/dev_version.py', tmp_path / 'flexget' / '_version.py')
os.chdir(tmp_path / 'flexget')
runner = CliRunner()
result = runner.invoke(version)
assert result.exit_code == 0
assert result.output == '3.13.19.dev\n'


@pytest.mark.parametrize(
('bump_from', 'bump_to', 'version'),
[
(
'dev',
'release',
'3.13.19',
),
(
'release',
'dev',
'3.13.20.dev',
),
],
)
def test_bump_version(tmp_path, bump_from, bump_to, version):
os.makedirs(tmp_path / 'flexget', exist_ok=True)
shutil.copy(
Path(__file__).parent / f'dev_tools/{bump_from}_version.py',
tmp_path / 'flexget' / '_version.py',
)
os.chdir(tmp_path / 'flexget')
runner = CliRunner()
result = runner.invoke(bump_version, [bump_to])
assert result.exit_code == 0
with open(tmp_path.joinpath('flexget/_version.py')) as f:
assert f"__version__ = '{version}'\n" in f


@vcr.use_cassette('cassettes/test_cli_bundle_webui.yaml')
@pytest.mark.parametrize('args', [[], ['--version', 'v2'], ['--version', 'v1'], ['--version', '']])
@pytest.mark.xdist_group(name="bundle webui")
def test_cli_bundle_webui(args):
v1_path = Path(v1.__file__).parent / 'app'
v2_path = Path(v2.__file__).parent / 'dist'
shutil.rmtree(v1_path, ignore_errors=True)
shutil.rmtree(v2_path, ignore_errors=True)
runner = CliRunner()
result = runner.invoke(cli_bundle_webui, args)
assert result.exit_code == 0
if 'v1' in args:
assert v1_path.is_dir()
elif 'v2' in args:
assert v2_path.is_dir()
else:
assert v1_path.is_dir()
assert v2_path.is_dir()


@vcr.use_cassette('cassettes/test_get_changelog.yaml')
def test_get_changelog():
runner = CliRunner()
result = runner.invoke(get_changelog, ['v3.13.6'])
assert result.exit_code == 0
assert result.output == (
'[all commits](https://github.com/Flexget/Flexget/compare/v3.13.5...v3.13.6)\n'
'### Changed\n'
'- Strictly ignore 19xx-20xx from episode parsing\n'
'- Strictly ignore 19xx-20xx from episode parsing\n'
)
27 changes: 27 additions & 0 deletions scripts/test_update_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import filecmp
import os
import shutil
from pathlib import Path
from zipfile import ZipFile

import pytest

from scripts.update_changelog import update_changelog


@pytest.mark.parametrize(
'n',
[
1,
2,
],
)
def test_update_changelog(tmp_path, n):
shutil.copy(Path(__file__).parent / f'update_changelog/test_{n}/ChangeLog.md', tmp_path)
ZipFile(Path(__file__).parent / f'update_changelog/test_{n}/repo.zip').extractall(tmp_path)
os.chdir(tmp_path)
update_changelog('ChangeLog.md')
assert filecmp.cmp(
'ChangeLog.md',
Path(__file__).parent / 'update_changelog' / f'test_{n}' / 'new_ChangeLog.md',
)
26 changes: 14 additions & 12 deletions update-changelog.py → scripts/update_changelog.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "gitpython ~=3.1",
# "gitpython~=3.1",
# ]
# ///

import collections
import contextlib
import re
import sys
from collections.abc import Generator, Iterable
Expand Down Expand Up @@ -100,12 +99,7 @@ def isplit(
return head, None, iterator


if __name__ == '__main__':
try:
filename = sys.argv[1]
except IndexError:
print('No filename specified, using changelog.md')
filename = 'changelog.md'
def update_changelog(filename: str) -> None:
with open(filename, encoding='utf-8') as logfile:
pre_lines, start_comment, tail = isplit('<!---', logfile)
active_lines, end_comment, tail = isplit('<!---', tail)
Expand Down Expand Up @@ -145,10 +139,9 @@ def isplit(
oldestref = commit.hexsha

verfile = repo.tree('HEAD')['flexget/_version.py'].data_stream.read()
__version__: Optional[str] = None
with contextlib.suppress(Exception):
exec(verfile)
new_version_header = f'## {__version__} (unreleased)\n'
local = {}
exec(verfile, globals(), local)
new_version_header = f'## {local.get("__version__")} (unreleased)\n'
if new_version_header != cur_ver.version_header:
cur_ver.version_header = new_version_header
modified = True
Expand All @@ -165,3 +158,12 @@ def isplit(
logfile.writelines(post_lines)
else:
print('No updates to write.')


if __name__ == '__main__':
try:
filename = sys.argv[1]
except IndexError:
print('No filename specified, using changelog.md')
filename = './ChangeLog.md'
update_changelog(filename)
23 changes: 23 additions & 0 deletions scripts/update_changelog/test_1/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: ChangeLog
description:
published: true
date: 2024-03-15T00:33:34.805Z
tags:
editor: markdown
dateCreated: 2022-09-18T04:48:39.193Z
---

# Changelog
This changelog is in progress. It can be manually updated via the wiki, but is also updated automatically via select commit messages and new releases. The two comment lines with git hashes (`<!---a1234--->`) must not be changed or removed.

<!---85bfdefbd3d2cd4ab258f1111dbc1ad074a0fcd3--->

## 3.13.19.dev (unreleased)
<!---659bf21e5852415df1463c124ef67b30189b4a37--->

## 3.13.18 (2025-01-20)
[all commits](https://github.com/Flexget/Flexget/compare/v3.13.17...v3.13.18)

## 3.13.17 (2025-01-19)
[all commits](https://github.com/Flexget/Flexget/compare/v3.13.16...v3.13.17)
Loading

0 comments on commit 28c4d95

Please sign in to comment.