From 477bdfcc2e96d8cca7d42aaefb940306b8841f11 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Tue, 8 Oct 2024 18:30:15 +0300 Subject: [PATCH] ci: Add GitHub action for tessdata --- .github/workflows/ci.yml | 59 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3c4ef5..1d9d2d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,8 +66,32 @@ jobs: sudo apt-get install -y python3-poetry python3 ./install/common/build-image.py + download-tessdata: + name: Download and cache Tesseract data + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Cache Tessdata + id: cache-tessdata + uses: actions/cache@v4 + with: + path: share/tessdata/ + key: v1-tessdata-${{ hashFiles('./install/common/download-tessdata.py') }} + enableCrossOsArchive: true + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Download Tessdata + run: |- + if [ -f "share/tessdata" ]; then + echo "Already cached, skipping" + else + python3 ./install/common/download-tessdata.py + fi + windows: runs-on: windows-latest + needs: download-tessdata env: DUMMY_CONVERSION: 1 steps: @@ -77,6 +101,13 @@ jobs: python-version: "3.12" - run: pip install poetry - run: poetry install + - name: Restore cached tessdata + uses: actions/cache/restore@v4 + with: + path: share/tessdata/ + enableCrossOsArchive: true + fail-on-cache-miss: true + key: v1-tessdata-${{ hashFiles('./install/common/download-tessdata.py') }} - name: Run CLI tests run: poetry run make test # Taken from: https://github.com/orgs/community/discussions/27149#discussioncomment-3254829 @@ -90,6 +121,7 @@ jobs: macOS: name: "macOS (${{ matrix.arch }})" runs-on: ${{ matrix.runner }} + needs: download-tessdata strategy: matrix: include: @@ -104,6 +136,13 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.12" + - name: Restore cached tessdata + uses: actions/cache/restore@v4 + with: + path: share/tessdata/ + enableCrossOsArchive: true + fail-on-cache-miss: true + key: v1-tessdata-${{ hashFiles('./install/common/download-tessdata.py') }} - run: pip install poetry - run: poetry install - name: Run CLI tests @@ -301,7 +340,9 @@ jobs: run-tests: name: "run tests (${{ matrix.distro }} ${{ matrix.version }})" runs-on: ubuntu-latest - needs: build-container-image + needs: + - build-container-image + - download-tessdata strategy: matrix: include: @@ -360,6 +401,22 @@ jobs: share/image-id.txt fail-on-cache-miss: true + - name: Restore cached tessdata + uses: actions/cache/restore@v4 + with: + path: share/tessdata/ + enableCrossOsArchive: true + fail-on-cache-miss: true + key: v1-tessdata-${{ hashFiles('./install/common/download-tessdata.py') }} + + - name: Setup xvfb (Linux) + run: | + # Stuff copied wildly from several stackoverflow posts + sudo apt-get install -y xvfb libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0 libxcb-shape0 libglib2.0-0 libgl1-mesa-dev '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev + + # start xvfb in the background + sudo /usr/bin/Xvfb $DISPLAY -screen 0 1280x1024x24 & + - name: Run CI tests run: |- # Pass the -ac Xserver flag, to disable host-based access controls.