Merge remote-tracking branch 'paperless/dev' into feature-consume-eml

This commit is contained in:
phail
2022-11-03 21:00:01 +01:00
45 changed files with 1426 additions and 971 deletions

View File

@@ -249,10 +249,12 @@ class MainImageTagsCleaner(RegistryTagsCleaner):
will be removed, if the corresponding branch no longer exists.
"""
# Default to everything gets kept still
super().decide_what_tags_to_keep()
# Locate the feature branches
feature_branches = {}
for branch in self.branch_api.get_branches(
owner=self.repo_owner,
repo=self.repo_name,
):
if branch.name.startswith("feature-"):
@@ -261,6 +263,10 @@ class MainImageTagsCleaner(RegistryTagsCleaner):
logger.info(f"Located {len(feature_branches)} feature branches")
if not len(feature_branches):
# Our work here is done, delete nothing
return
# Filter to packages which are tagged with feature-*
packages_tagged_feature: List[ContainerPackage] = []
for package in self.all_package_versions:

View File

@@ -15,7 +15,7 @@ from typing import Dict
from typing import List
from typing import Optional
import requests
import httpx
logger = logging.getLogger("github-api")
@@ -28,15 +28,15 @@ class _GithubApiBase:
def __init__(self, token: str) -> None:
self._token = token
self._session: Optional[requests.Session] = None
self._client: Optional[httpx.Client] = None
def __enter__(self) -> "_GithubApiBase":
"""
Sets up the required headers for auth and response
type from the API
"""
self._session = requests.Session()
self._session.headers.update(
self._client = httpx.Client()
self._client.headers.update(
{
"Accept": "application/vnd.github.v3+json",
"Authorization": f"token {self._token}",
@@ -49,14 +49,14 @@ class _GithubApiBase:
Ensures the authorization token is cleaned up no matter
the reason for the exit
"""
if "Accept" in self._session.headers:
del self._session.headers["Accept"]
if "Authorization" in self._session.headers:
del self._session.headers["Authorization"]
if "Accept" in self._client.headers:
del self._client.headers["Accept"]
if "Authorization" in self._client.headers:
del self._client.headers["Authorization"]
# Close the session as well
self._session.close()
self._session = None
self._client.close()
self._client = None
def _read_all_pages(self, endpoint):
"""
@@ -66,7 +66,7 @@ class _GithubApiBase:
internal_data = []
while True:
resp = self._session.get(endpoint)
resp = self._client.get(endpoint)
if resp.status_code == 200:
internal_data += resp.json()
if "next" in resp.links:
@@ -76,7 +76,7 @@ class _GithubApiBase:
break
else:
logger.warning(f"Request to {endpoint} return HTTP {resp.status_code}")
break
resp.raise_for_status()
return internal_data
@@ -113,14 +113,15 @@ class GithubBranchApi(_GithubApiBase):
def __init__(self, token: str) -> None:
super().__init__(token)
self._ENDPOINT = "https://api.github.com/repos/{OWNER}/{REPO}/branches"
self._ENDPOINT = "https://api.github.com/repos/{REPO}/branches"
def get_branches(self, owner: str, repo: str) -> List[GithubBranch]:
def get_branches(self, repo: str) -> List[GithubBranch]:
"""
Returns all current branches of the given repository owned by the given
owner or organization.
"""
endpoint = self._ENDPOINT.format(OWNER=owner, REPO=repo)
# The environment GITHUB_REPOSITORY already contains the owner in the correct location
endpoint = self._ENDPOINT.format(REPO=repo)
internal_data = self._read_all_pages(endpoint)
return [GithubBranch(branch) for branch in internal_data]
@@ -247,7 +248,7 @@ class GithubContainerRegistryApi(_GithubApiBase):
"""
Deletes the given package version from the GHCR
"""
resp = self._session.delete(package_data.url)
resp = self._client.delete(package_data.url)
if resp.status_code != 204:
logger.warning(
f"Request to delete {package_data.url} returned HTTP {resp.status_code}",
@@ -266,7 +267,7 @@ class GithubContainerRegistryApi(_GithubApiBase):
PACKAGE_VERSION_ID=package_data.id,
)
resp = self._session.post(endpoint)
resp = self._client.post(endpoint)
if resp.status_code != 204:
logger.warning(
f"Request to delete {endpoint} returned HTTP {resp.status_code}",

View File

@@ -139,7 +139,7 @@ jobs:
-
name: Get changed files
id: changed-files-specific
uses: tj-actions/changed-files@v32
uses: tj-actions/changed-files@v34
with:
files: |
src/**

View File

@@ -64,9 +64,9 @@ jobs:
with:
python-version: "3.10"
-
name: Install requests
name: Install httpx
run: |
python -m pip install requests
python -m pip install httpx
#
# Clean up primary package
#

View File

@@ -50,6 +50,11 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: "3.9"
-
name: Install jq
run: |
sudo apt-get update
sudo apt-get install jq
-
name: Setup qpdf image
id: qpdf-setup
@@ -86,6 +91,18 @@ jobs:
echo ${build_json}
echo "jbig2enc-json=${build_json}" >> $GITHUB_OUTPUT
-
name: Setup other versions
id: cache-bust-setup
run: |
pillow_version=$(jq ".default.pillow.version" Pipfile.lock | sed 's/=//g' | sed 's/"//g')
lxml_version=$(jq ".default.lxml.version" Pipfile.lock | sed 's/=//g' | sed 's/"//g')
echo "Pillow is ${pillow_version}"
echo "lxml is ${lxml_version}"
echo "pillow-version=${pillow_version}" >> $GITHUB_OUTPUT
echo "lxml-version=${lxml_version}" >> $GITHUB_OUTPUT
outputs:
@@ -97,7 +114,11 @@ jobs:
psycopg2-json: ${{ steps.psycopg2-setup.outputs.psycopg2-json }}
jbig2enc-json: ${{ steps.jbig2enc-setup.outputs.jbig2enc-json}}
jbig2enc-json: ${{ steps.jbig2enc-setup.outputs.jbig2enc-json }}
pillow-version: ${{ steps.cache-bust-setup.outputs.pillow-version }}
lxml-version: ${{ steps.cache-bust-setup.outputs.lxml-version }}
build-qpdf-debs:
name: qpdf
@@ -145,3 +166,5 @@ jobs:
REPO=${{ needs.prepare-docker-build.outputs.ghcr-repository }}
QPDF_VERSION=${{ fromJSON(needs.prepare-docker-build.outputs.qpdf-json).version }}
PIKEPDF_VERSION=${{ fromJSON(needs.prepare-docker-build.outputs.pikepdf-json).version }}
PILLOW_VERSION=${{ needs.prepare-docker-build.outputs.pillow-version }}
LXML_VERSION=${{ needs.prepare-docker-build.outputs.lxml-version }}