|
| 1 | +name: Package ocrweb |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - v* |
| 7 | + |
| 8 | + |
| 9 | +env: |
| 10 | + package_name: RapidOCRWeb |
| 11 | + rapidocr_web_dir: ocrweb/rapidocr_web/ |
| 12 | + |
| 13 | +jobs: |
| 14 | + create_release: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 18 | + steps: |
| 19 | + - name: get_cur_time |
| 20 | + uses: srfrnk/current-time@master |
| 21 | + id: get_cur_time |
| 22 | + with: |
| 23 | + format: YYYY-MM-DD-HH-mm-ss |
| 24 | + - name: create_release |
| 25 | + id: create_release |
| 26 | + uses: marvinpinto/action-automatic-releases@latest |
| 27 | + with: |
| 28 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + automatic_release_tag: Draft-${{ steps.get_cur_time.outputs.formattedTime }} |
| 30 | + prerelease: false |
| 31 | + draft: true |
| 32 | + |
| 33 | + build_windows: |
| 34 | + name: build_windows |
| 35 | + runs-on: ${{ matrix.os }} |
| 36 | + needs: create_release |
| 37 | + strategy: |
| 38 | + matrix: |
| 39 | + os: ['windows-2022', 'windows-2019'] |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Pull latest code |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Set up Python 3.10 |
| 46 | + uses: actions/setup-python@v4 |
| 47 | + with: |
| 48 | + python-version: '3.10' |
| 49 | + architecture: 'x64' |
| 50 | + |
| 51 | + - name: Display Python version |
| 52 | + run: python -c "import sys; print(sys.version)" |
| 53 | + |
| 54 | + - name: Install environments |
| 55 | + run: | |
| 56 | + pip3 install Pillow pyinstaller Flask>=2.1.0 rapidocr_onnxruntime>=1.2.8 get_pypi_latest_version |
| 57 | +
|
| 58 | + - name: Run pyinstaller |
| 59 | + id: run_pyinstaller |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + cd ${{ env.rapidocr_web_dir }} |
| 63 | + pyinstaller ocrweb.spec |
| 64 | + cp -r static templates dist/${{ env.package_name }} |
| 65 | + rm dist/${{ env.package_name }}/cv2/opencv_videoio_ffmpe*.dll || echo "未找到opencv_videoio_ffmpeg" |
| 66 | + echo "VERSION=$(get_pypi_latest_version rapid_videocr)" >> $GITHUB_OUTPUT |
| 67 | +
|
| 68 | + - name: Concat file path |
| 69 | + id: concat_file_path |
| 70 | + shell: bash |
| 71 | + env: |
| 72 | + ZIP_WIN_NAME: ${{ env.package_name }}-${{ steps.run_pyinstaller.outputs.VERSION }}-${{ matrix.os }}-${{ runner.arch }}-no-installer.zip |
| 73 | + Win_DIST_DIR: ${{ github.workspace }}\ocrweb\rapidocr_web\dist |
| 74 | + run: | |
| 75 | + echo "ZIP_NAME=$ZIP_WIN_NAME" >> $GITHUB_OUTPUT |
| 76 | + echo "Win_PACKAGE_DIR=$Win_DIST_DIR\${{ env.package_name }}" >> $GITHUB_OUTPUT |
| 77 | + echo "Win_ZIP_FULL_PATH=$Win_DIST_DIR\\$ZIP_WIN_NAME" >> $GITHUB_OUTPUT |
| 78 | +
|
| 79 | + - name: Zip package |
| 80 | + run: | |
| 81 | + powershell Compress-Archive ${{ steps.concat_file_path.outputs.Win_PACKAGE_DIR }} ${{ steps.concat_file_path.outputs.Win_ZIP_FULL_PATH }} |
| 82 | +
|
| 83 | + - name: Upload release asset |
| 84 | + id: upload-release-asset-windows |
| 85 | + uses: actions/upload-release-asset@v1 |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + with: |
| 89 | + upload_url: ${{ needs.create_release.outputs.upload_url }} |
| 90 | + asset_path: ${{ steps.concat_file_path.outputs.Win_ZIP_FULL_PATH }} |
| 91 | + asset_name: ${{ steps.concat_file_path.outputs.ZIP_NAME }} |
| 92 | + asset_content_type: application/zip |
| 93 | + |
| 94 | + build_linux: |
| 95 | + name: build_linux |
| 96 | + runs-on: ${{ matrix.os }} |
| 97 | + needs: create_release |
| 98 | + strategy: |
| 99 | + matrix: |
| 100 | + os: ['ubuntu-20.04', 'ubuntu-22.04', 'macos-13', 'macos-12', 'macos-11'] |
| 101 | + |
| 102 | + steps: |
| 103 | + - name: Pull latest code |
| 104 | + uses: actions/checkout@v4 |
| 105 | + |
| 106 | + - name: Set up Python 3.10 |
| 107 | + uses: actions/setup-python@v4 |
| 108 | + with: |
| 109 | + python-version: '3.10' |
| 110 | + architecture: 'x64' |
| 111 | + |
| 112 | + - name: Display Python version |
| 113 | + run: python -c "import sys; print(sys.version)" |
| 114 | + |
| 115 | + - name: Install environments |
| 116 | + run: | |
| 117 | + pip3 install Pillow pyinstaller Flask>=2.1.0 rapidocr_onnxruntime>=1.2.8 get_pypi_latest_version |
| 118 | +
|
| 119 | + - name: Run pyinstaller |
| 120 | + id: run_pyinstaller |
| 121 | + shell: bash |
| 122 | + run: | |
| 123 | + cd ocrweb/rapidocr_web/ |
| 124 | + pyinstaller ocrweb.spec |
| 125 | + cp -r static templates dist/${{ env.package_name }} |
| 126 | + rm dist/${{ env.package_name }}/cv2/opencv_videoio_ffmpe*.dll || echo "未找到opencv_videoio_ffmpeg" |
| 127 | + echo "VERSION=$(get_pypi_latest_version rapid_videocr)" >> $GITHUB_OUTPUT |
| 128 | +
|
| 129 | + - name: Concat file path |
| 130 | + id: concat_file_path |
| 131 | + env: |
| 132 | + ZIP_NAME: ${{ env.package_name }}-${{ steps.run_pyinstaller.outputs.VERSION }}-${{ matrix.os }}-${{ runner.arch }}-no-installer.zip |
| 133 | + Linux_DIST_DIR: ${{ github.workspace }}/ocrweb/rapidocr_web/dist |
| 134 | + run: | |
| 135 | + echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_OUTPUT |
| 136 | + echo "Linux_PACKAGE_DIR=$Linux_DIST_DIR/${{ env.package_name }}" >> $GITHUB_OUTPUT |
| 137 | + echo "Linux_ZIP_FULL_PATH=$Linux_DIST_DIR/$ZIP_NAME" >> $GITHUB_OUTPUT |
| 138 | + echo "Linux_DIST_DIR=$Linux_DIST_DIR" >> $GITHUB_OUTPUT |
| 139 | +
|
| 140 | + - name: Zip package |
| 141 | + run: | |
| 142 | + cd ${{ steps.concat_file_path.outputs.Linux_DIST_DIR }} |
| 143 | + zip -r ${{ steps.concat_file_path.outputs.ZIP_NAME }} ${{ env.package_name }} |
| 144 | +
|
| 145 | + - name: Upload release asset |
| 146 | + id: upload-release-asset-linux-macOS |
| 147 | + uses: actions/upload-release-asset@v1 |
| 148 | + env: |
| 149 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 150 | + with: |
| 151 | + upload_url: ${{ needs.create_release.outputs.upload_url }} |
| 152 | + asset_path: ${{ steps.concat_file_path.outputs.Linux_ZIP_FULL_PATH }} |
| 153 | + asset_name: ${{ steps.concat_file_path.outputs.ZIP_NAME }} |
| 154 | + asset_content_type: application/zip |
0 commit comments