diff --git a/.github/workflows/docker-build-check.yml b/.github/workflows/docker-build-check.yml index 0cc3036c4b..52c90a2353 100644 --- a/.github/workflows/docker-build-check.yml +++ b/.github/workflows/docker-build-check.yml @@ -45,6 +45,52 @@ jobs: tags: airbyte/source-declarative-manifest:pr-${{ github.event.pull_request.number }} outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=SDM Docker image for PR ${{ github.event.pull_request.number }} + - name: Build Docker image for bytecode check (linux/amd64) + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64 + load: true + tags: airbyte/source-declarative-manifest:bytecode-check + + - name: Verify every site-packages module has precompiled bytecode + run: | + docker run --rm -i --entrypoint python airbyte/source-declarative-manifest:bytecode-check - <<'EOF' + import importlib.util + import pathlib + import re + import struct + import sys + import sysconfig + + SKIP = re.compile(r"/tests?/") # keep in sync with compileall -x in the Dockerfile + + root = pathlib.Path(sysconfig.get_paths()["purelib"]) + missing, stale = [], [] + total = 0 + for src in root.rglob("*.py"): + if SKIP.search(str(src)): + continue + total += 1 + pyc = pathlib.Path(importlib.util.cache_from_source(str(src))) + if not pyc.is_file(): + missing.append(src) + continue + header = pyc.read_bytes()[:16] + flags = int.from_bytes(header[4:8], "little") + if len(header) < 16 or header[:4] != importlib.util.MAGIC_NUMBER or flags != 0: + stale.append(src) + else: + mtime, size = struct.unpack(" main.py \