Skip to content

Commit

Permalink
Fix compat & tz/locale tests (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyNikiforov authored Jul 11, 2024
1 parent 7d74cbb commit 7df2311
Show file tree
Hide file tree
Showing 8 changed files with 919 additions and 189 deletions.
897 changes: 772 additions & 125 deletions .github/workflows/build-package.yml

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
FROM alpine:3.18 as runtime_amd64_none
FROM ubuntu:24.04 as runtime_amd64_none
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -y tzdata locales-all
WORKDIR /app
COPY dist/icloudpd-ex-*.*.*-linux-amd64 icloudpd_ex

FROM alpine:3.18 as runtime_386_none
# focal is the last ubuntu for 386
FROM i386/ubuntu:focal as runtime_386_none
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -y tzdata locales-all
WORKDIR /app
COPY dist/icloudpd-ex-*.*.*-linux-386 icloudpd_ex

FROM alpine:3.18 as runtime_arm64_none
FROM ubuntu:24.04 as runtime_arm64_none
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -y tzdata locales-all
WORKDIR /app
COPY dist/icloudpd-ex-*.*.*-linux-arm64 icloudpd_ex

FROM alpine:3.18 as runtime_arm_v7
FROM ubuntu:24.04 as runtime_arm_v7
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -y tzdata locales-all
WORKDIR /app
COPY dist/icloudpd-ex-*.*.*-linux-arm32v7 icloudpd_ex

FROM alpine:3.18 as runtime_arm_v6
ENV MUSL_LOCPATH="/usr/share/i18n/locales/musl"
RUN apk update && apk add --no-cache tzdata musl-locales musl-locales-lang
WORKDIR /app
COPY dist/icloudpd-ex-*.*.*-linux-arm32v6 icloudpd_ex

FROM runtime_${TARGETARCH}_${TARGETVARIANT:-none} as runtime
RUN apk add --no-cache tzdata
ENV TZ=UTC
EXPOSE 8080
WORKDIR /app
Expand Down
57 changes: 0 additions & 57 deletions scripts/compile_compatibility

This file was deleted.

21 changes: 21 additions & 0 deletions scripts/compile_compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
"""takes results of compatibility tests and compie into one file"""

import os
import sys

from compile_matrix import print_breakdowns


def content_checker(filepath):
return os.path.getsize(filepath) > 0


if __name__ == "__main__":
print("## Minimal Effort Compatibility")
print(
"Checks if `icloudpd` can be installed using minimal effort and ran bare minimum functionality of displaying a version information. Minimal effort may require installing default version of package manager using OS tools"
)
print("")
folder = sys.argv[1] if len(sys.argv) > 1 else "."
print_breakdowns(folder, content_checker, ("(src)", "Test pass using src (for pip)"))
68 changes: 68 additions & 0 deletions scripts/compile_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""takes results of compatibility tests and compile into one file"""

import itertools
import os


def _stats(files):
"""Print statistics"""
total = len([f for f in files if f[4] != "na"])
passed = len([f for f in files if f[4] == "pass"])
print(
f"Compatibility rate: {round(100*passed/total,1) if total > 0 else 0}% ({passed} passed out of {total})"
)
print("")


def _matrix(files, special):
"""Prints matrix"""
archs = [
k for k, _ in itertools.groupby(sorted(files, key=lambda ft: ft[3]), key=lambda ft: ft[3])
]
# sort by priority of archs
presort = ["amd64", "arm64", "arm32v7"]
archs_sorted = sorted(archs, key=lambda k: f"{presort.index(k) if k in presort else 9}{k}")
# caption
print("|".join(["OSes and distros"] + archs_sorted))
print("|".join(["-"] + ["-" for a in archs_sorted]))

oses = [
k for k, _ in itertools.groupby(sorted(files, key=lambda ft: ft[2]), key=lambda ft: ft[2])
]
for o in oses:
results_raw = [
list(filter(lambda ft: ft[2] == o and ft[3] == a, files)) for a in archs_sorted
]
results = [
"N/A"
if len(r) == 0 or r[0][4] == "na"
else (r[0][4] + ("" if r[0][4] != "pass" or r[0][0] is False else f" {special}"))
for r in results_raw
]
print("|".join([o] + results))


def print_breakdowns(folder, special_content_checker, special_pair):
"""param: folder"""
(abbr, description) = special_pair
files = [f for f in os.listdir(folder) if not os.path.isdir(f)]
fts = [
[special_content_checker(os.path.join(folder, f))] + f.split(".")
for f in files
if len(f.split(".")) == 4
]
_stats(fts)
print("Legend:")
print("- N/A - not applicable/available")
print("- pass - test pass")
print("- fail - test fail")
print(f"- pass {abbr} - {description}")
print("")
groups = [
(k, list(g))
for k, g in itertools.groupby(sorted(fts, key=lambda ft: ft[1]), key=lambda ft: ft[1])
]
for g, f in groups:
print(f"### {g}")
_stats(f)
_matrix(f, abbr)
35 changes: 35 additions & 0 deletions scripts/compile_tzlc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""takes results of tz and locale compatibility tests and compile into one file"""

import sys

from compile_matrix import print_breakdowns


def special_content_checker(expected_content):
# content is special when it exists, but is invalid
def _intern(filepath):
with open(filepath, encoding="UTF-8") as file:
content = file.read()
return content != expected_content

return _intern


if __name__ == "__main__":
if len(sys.argv) != 3:
print("Params: <folder> <expected content>")
sys.exit(1)
print("## Timezone and Locale Compatibility")
print(
"Checks if `icloudpd` can be installed using minimal effort and ran bare minimum functionality of displaying version and commit timestamp in local timezone and RU locale. Minimal effort may require installing default version of package manager, timezone data, and locales using OS tools"
)
print("")
folder = sys.argv[1]
expected_content = sys.argv[2]
# content is special when it exists, but is invalid
print_breakdowns(
folder,
special_content_checker(expected_content),
("(invalid)", "Incorrect values were generated"),
)
3 changes: 1 addition & 2 deletions scripts/npx_optional
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ set -euo pipefail

if [ `which npx` ]; then
echo "test icloudpd..." &&
npx ${@:3} &&
touch $1
npx ${@:3} 1>$1
else
echo "No npx available"
touch $2
Expand Down
11 changes: 11 additions & 0 deletions scripts/npx_optional_touch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail

if [ `which npx` ]; then
echo "test icloudpd..." &&
npx ${@:3} &&
touch $1
else
echo "No npx available"
touch $2
fi

0 comments on commit 7df2311

Please sign in to comment.