refactor(ocr): improve PDF splitting and OCR caching, update tool naming #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Release | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| paths-ignore: | |
| - '**.md' | |
| - 'docs/**' | |
| - 'LICENSE' | |
| - '.gitignore' | |
| - '*.txt' | |
| tags: [ 'v*' ] | |
| pull_request: | |
| branches: [ main, master ] | |
| paths-ignore: | |
| - '**.md' | |
| - 'docs/**' | |
| - 'LICENSE' | |
| - '.gitignore' | |
| - '*.txt' | |
| env: | |
| GO_VERSION: '1.23' | |
| BINARY_NAME: 'doc-to-text' | |
| CGO_ENABLED: '0' | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go-${{ env.GO_VERSION }}- | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Run tests | |
| run: go test -v ./... | |
| - name: Run go vet | |
| run: go vet ./... | |
| - name: Check formatting | |
| run: | | |
| if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then | |
| echo "Code is not formatted. Run: gofmt -s -w ." | |
| gofmt -s -l . | |
| exit 1 | |
| fi | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| needs: test | |
| strategy: | |
| matrix: | |
| goos: [linux, windows, darwin] | |
| goarch: [amd64, arm64] | |
| include: | |
| - goos: linux | |
| goarch: arm | |
| goarm: 7 | |
| exclude: | |
| - goos: windows | |
| goarch: arm64 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Get version info | |
| id: version | |
| run: | | |
| if git describe --tags --exact-match >/dev/null 2>&1; then | |
| VERSION=$(git describe --tags --exact-match) | |
| else | |
| COMMIT_SHORT=$(git rev-parse --short HEAD) | |
| VERSION="v1.0.0-dev+${COMMIT_SHORT}" | |
| fi | |
| GIT_COMMIT=$(git rev-parse HEAD) | |
| BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "git_commit=$GIT_COMMIT" >> $GITHUB_OUTPUT | |
| echo "build_time=$BUILD_TIME" >> $GITHUB_OUTPUT | |
| - name: Build binary | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| GOARM: ${{ matrix.goarch == 'arm' && matrix.goarm || '' }} | |
| run: | | |
| mkdir -p dist | |
| # Set binary name with proper extension | |
| if [ "${{ matrix.goos }}" = "windows" ]; then | |
| BINARY_NAME="${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}.exe" | |
| else | |
| if [ "${{ matrix.goarch }}" = "arm" ] && [ -n "${{ matrix.goarm }}" ]; then | |
| BINARY_NAME="${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}v${{ matrix.goarm }}" | |
| else | |
| BINARY_NAME="${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}" | |
| fi | |
| fi | |
| # Build with version info | |
| go build \ | |
| -ldflags "-s -w \ | |
| -X 'main.Version=${{ steps.version.outputs.version }}' \ | |
| -X 'main.GitCommit=${{ steps.version.outputs.git_commit }}' \ | |
| -X 'main.BuildTime=${{ steps.version.outputs.build_time }}'" \ | |
| -o "dist/${BINARY_NAME}" . | |
| # Create checksum | |
| cd dist | |
| sha256sum "${BINARY_NAME}" > "${BINARY_NAME}.sha256" | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.goarm && format('v{0}', matrix.goarm) || '' }} | |
| path: dist/* | |
| retention-days: 7 | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: startsWith(github.ref, 'refs/tags/') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Generate release notes | |
| id: release_notes | |
| run: | | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| GIT_COMMIT=$(git rev-parse HEAD) | |
| BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ') | |
| cat > release_notes.md << EOF | |
| ## Release $VERSION | |
| ### Build Information | |
| - **Version**: $VERSION | |
| - **Commit**: $GIT_COMMIT | |
| - **Build Time**: $BUILD_TIME | |
| ### Downloads | |
| Choose the appropriate binary for your platform: | |
| **Linux:** | |
| - Linux AMD64: \`${{ env.BINARY_NAME }}_linux_amd64\` | |
| - Linux ARM64: \`${{ env.BINARY_NAME }}_linux_arm64\` | |
| - Linux ARMv7: \`${{ env.BINARY_NAME }}_linux_armv7\` | |
| **macOS:** | |
| - macOS Intel: \`${{ env.BINARY_NAME }}_darwin_amd64\` | |
| - macOS Apple Silicon: \`${{ env.BINARY_NAME }}_darwin_arm64\` | |
| **Windows:** | |
| - Windows AMD64: \`${{ env.BINARY_NAME }}_windows_amd64.exe\` | |
| ### Installation | |
| 1. Download the binary for your platform | |
| 2. Verify checksum (optional): \`sha256sum -c filename.sha256\` | |
| 3. Make executable (Unix): \`chmod +x filename\` | |
| 4. Run: \`./filename --help\` | |
| EOF | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: artifacts/**/* | |
| body_path: release_notes.md | |
| draft: false | |
| prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }} | |
| make_latest: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |