Skip to content

Commit 5aef439

Browse files
authored
OCR CI build artifact (#153)
* init for [IDWA-OCR-72] Install OCR into an executable * edit readme with the build command * add refs to form_filled to use this without args * lint * lint * lint * build/upload artifact * pip install pyinstaller * pip install pyinstaller * rm dev * put build in dependencies * add requirements.txt and use pyinstaller cli * rm working directory * point to main and not dir main * try dist/ and --onefile * try -windowed * dist/main * upgrade upload action * macos-latest * try using assets from tests * try using assets from tests * revert back to dup assets * CLI for better handling of arguments * lint * lint * rm args with pyinstaller because of new cli * use ^ woth version * install docopt with gh action job * rm unused assets in the ocr dir * docs * docs * upload bin for each os * matrix exp * matrix exp * matrix exp * zip * zip * check path * check path * check path * whoops * try gzexe * && * wip * try building release * fix the needs: * try building release * try building release * try building release * try building release * add checkout * change from action * add another checkout * add paths * try using workflow_call * try using workflow_call * wip * using download action * using download action * try that * token * try for loop * dont use matrix * token ref * try with workspace * try with workspace * try with workspace * whoops * working dir * working dir * add --repo * think i got it * try encoding with jq * try encoding with jq * github.repository * full url * matrix again * see what dir we're in * path to artifactas * put everything in first job with create * put everything in first job with create * upload all in dir * write all * try dif action * try dif action * try with content * upgrade action * new output * upgrade upload and download versions * just path for download * ls * ls * add to uplaod * try full workflow * forgot to switch needs job * again * fix file names * fix file names * change release title name * missed diffs * clean-up * try changing ref * try changing ref * try changing ref * try changing ref * try changing ref * try changing ref * try changing ref * create and see if upload asset chooses it * create and see if upload asset chooses it * create and see if upload asset chooses it * create and see if upload asset chooses it * create and see if upload asset chooses it * create and see if upload asset chooses it * create and see if upload asset chooses it * use ref at checkout * ls * use ref at checkout * try new upload action * fix script * create tag again * full workflow * full workflow * full workflow * cleaned up and made as workflow_dispatch --------- Co-authored-by: Derek Dombek <derek.a.dombek.com>
1 parent 8de679f commit 5aef439

File tree

7 files changed

+106
-27
lines changed

7 files changed

+106
-27
lines changed

.github/workflows/build-ocr.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build & Upload OCR Binaries
2+
on:
3+
workflow_call:
4+
outputs:
5+
output-file:
6+
description: "The first output string"
7+
value: ${{ jobs.build.outputs.output_artifacts }}
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
strategy:
13+
matrix:
14+
include:
15+
- os: macos-latest
16+
name: macos
17+
cmd: >
18+
pyinstaller -F -w -n main-macos ./OCR/ocr/main.py &&
19+
cd dist/ &&
20+
zip -r9 main-macos main-macos
21+
out_file: main-macos.zip
22+
- os: windows-latest
23+
name: windows
24+
cmd: pyinstaller -F -w -n main-windows ./OCR/ocr/main.py
25+
out_file: main-windows.exe
26+
- os: ubuntu-latest
27+
name: ubuntu
28+
cmd: >
29+
pyinstaller -F -w -n main-ubuntu ./OCR/ocr/main.py &&
30+
cd dist/ &&
31+
zip -r9 main-ubuntu main-ubuntu
32+
out_file: main-ubuntu.zip
33+
runs-on: ${{ matrix.os }}
34+
outputs:
35+
output_artifacts: ${{ steps.artifacts.outputs.matrix.out_file }}
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: actions/setup-python@v5
39+
with:
40+
python-version: "3.10"
41+
- name: Install dependencies
42+
run: |
43+
python -m pip install --upgrade pip
44+
pip install -r requirements.txt pyinstaller
45+
pip install docopt
46+
- name: Build binaries for all OS's
47+
run: ${{ matrix.cmd }}
48+
- name: Upload Artifacts To Workflow
49+
uses: actions/upload-artifact@v4
50+
id: artifacts
51+
with:
52+
name: main-${{ matrix.name }}
53+
path: ./dist/${{ matrix.out_file}}

.github/workflows/release-ocr.yml

+14-24
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,38 @@
11
name: Release MDE-OCR artifacts
2+
run-name: Release MDE-OCR artifacts - by @${{ github.actor }}
23
on:
3-
# workflow_dispatch:
4-
# inputs:
5-
# tag:
6-
# description: 'target environment'
7-
# required: true
8-
push:
9-
branches:
10-
- idwa-ocr-ci-for-executable
11-
paths:
12-
- .github/workflows/release-ocr.yml
13-
- .github/workflows/build-ocr.yml
14-
- OCR/**
15-
# tags:
16-
# - 'v*'
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Version tag for new release'
8+
required: true
179
jobs:
1810
create-release:
1911
name: Create Release
20-
2112
runs-on: [ubuntu-latest]
2213
permissions:
2314
contents: write
2415
steps:
2516
- uses: actions/checkout@v4
2617
- name: Create tag
27-
uses: actions/github-script@v5
18+
uses: actions/github-script@v7
2819
with:
2920
script: |
3021
github.rest.git.createRef({
3122
owner: context.repo.owner,
3223
repo: context.repo.repo,
33-
ref: 'refs/tags/1.0.0',
24+
ref: 'refs/tags/${{ github.event.inputs.tag }}',
3425
sha: context.sha
3526
})
3627
- name: Create release
3728
id: create_release
3829
env:
3930
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40-
tag: ${{ github.ref_name }}
31+
tag: ${{ github.event.inputs.tag }}
4132
run: |
4233
gh release create "$tag" \
4334
--repo="$GITHUB_REPOSITORY" \
44-
--title="MDE-OCR ${tag#v}" \
35+
--title="MDE-OCR ${tag}" \
4536
--generate-notes
4637
- name: Output Release URL File
4738
run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt
@@ -62,9 +53,8 @@ jobs:
6253
with:
6354
path: artifacts
6455
merge-multiple: true
65-
- name: Upload release binaries
66-
uses: alexellis/[email protected]
67-
env:
68-
GITHUB_TOKEN: ${{ github.token }}
56+
- name: Release Upload Assets
57+
uses: jaywcjlove/github-action-upload-assets@main
6958
with:
70-
asset_paths: '["./artifacts/*"]'
59+
tag: ${{ github.event.inputs.tag }}
60+
asset-path: '["./artifacts/*"]'

OCR/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Run main, hoping to convert this to a cli at some point
2929
poetry run main
3030
```
3131

32+
To build the OCR service into an executable artifact
33+
```shell
34+
poetry run build
35+
```
3236

3337
Adding new dependencies
3438
```shell

OCR/ocr/pyinstaller.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import PyInstaller.__main__
2+
from pathlib import Path
3+
4+
HERE = Path(__file__).parent.absolute()
5+
path_to_main = str(HERE / "main.py")
6+
7+
8+
# This function installs/packages the main OCR function as an executable.
9+
# You could also use the commandline. Using `pyinstaller ./OCR/ocr/main.py -F -w` works the same is the function below.
10+
# If you need to add asset paths, follow the example below.
11+
def install():
12+
PyInstaller.__main__.run(
13+
[
14+
path_to_main,
15+
"--onefile",
16+
"--windowed",
17+
# SOURCE:DESTINATION
18+
# "--add-data=ocr/assets/form_filled.png:assets/",
19+
# "--add-data=ocr/assets/form_segmention_template.png:assets/",
20+
# "--add-data=ocr/assets/labels.json:assets/",
21+
# other pyinstaller options...
22+
]
23+
)

OCR/poetry.lock

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OCR/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ build-backend = "poetry.core.masonry.api"
3434

3535
[tool.poetry.scripts]
3636
main = "ocr.main:main"
37+
build = "ocr.pyinstaller:install"
3738

3839
[tool.ruff]
3940
line-length = 118

requirements.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
numpy==1.26.4
2+
opencv-python==4.9.0.80
3+
python-dotenv==1.0.1
4+
Pillow>=10.3.0
5+
torch==1.13.1
6+
docopt==0.6.2
7+
git+https://github.com/huggingface/transformers.git

0 commit comments

Comments
 (0)