|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +defaults: |
| 9 | + run: |
| 10 | + shell: bash |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: Build ${{ matrix.target }} |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + include: |
| 19 | + - target: x86_64-unknown-linux-gnu |
| 20 | + os: ubuntu-latest |
| 21 | + node-file: node-opencv-rs.linux-x64-gnu.node |
| 22 | + npm-dir: npm/linux-x64-gnu |
| 23 | + |
| 24 | + - target: aarch64-apple-darwin |
| 25 | + os: macos-latest |
| 26 | + node-file: node-opencv-rs.darwin-arm64.node |
| 27 | + npm-dir: npm/darwin-arm64 |
| 28 | + |
| 29 | + - target: x86_64-pc-windows-msvc |
| 30 | + os: windows-latest |
| 31 | + node-file: node-opencv-rs.win32-x64-msvc.node |
| 32 | + npm-dir: npm/win32-x64-msvc |
| 33 | + |
| 34 | + runs-on: ${{ matrix.os }} |
| 35 | + |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Setup Node.js |
| 40 | + uses: actions/setup-node@v4 |
| 41 | + with: |
| 42 | + node-version: '22' |
| 43 | + |
| 44 | + - name: Setup Rust |
| 45 | + uses: dtolnay/rust-toolchain@stable |
| 46 | + with: |
| 47 | + targets: ${{ matrix.target }} |
| 48 | + |
| 49 | + - name: Install Linux dependencies |
| 50 | + if: matrix.os == 'ubuntu-latest' |
| 51 | + run: | |
| 52 | + sudo apt-get update |
| 53 | + sudo apt-get install -y cmake libopencv-dev llvm clang libclang-dev |
| 54 | + echo "LIBCLANG_PATH=/usr/lib/x86_64-linux-gnu" >> $GITHUB_ENV |
| 55 | +
|
| 56 | + - name: Install macOS dependencies |
| 57 | + if: startsWith(matrix.os, 'macos') |
| 58 | + run: | |
| 59 | + brew install llvm opencv |
| 60 | + LLVM_DIR=$(brew --prefix llvm) |
| 61 | + OPENCV_INC=$(brew --prefix opencv)/include/opencv4 |
| 62 | + # Work around opencv-binding-generator 0.93.x panic on macOS ARM64 |
| 63 | + # surface_matching and gapi headers cause unreachable code in the generator. |
| 64 | + # These modules are not used by this package. |
| 65 | + for module in surface_matching gapi; do |
| 66 | + if [ -f "$OPENCV_INC/opencv2/${module}.hpp" ]; then |
| 67 | + echo "#pragma once // stubbed to avoid binding generator crash" > "$OPENCV_INC/opencv2/${module}.hpp" |
| 68 | + rm -rf "$OPENCV_INC/opencv2/${module}" |
| 69 | + fi |
| 70 | + done |
| 71 | + echo "LIBCLANG_PATH=${LLVM_DIR}/lib" >> $GITHUB_ENV |
| 72 | + echo "DYLD_FALLBACK_LIBRARY_PATH=${LLVM_DIR}/lib" >> $GITHUB_ENV |
| 73 | +
|
| 74 | + - name: Install Windows dependencies |
| 75 | + if: matrix.os == 'windows-latest' |
| 76 | + shell: pwsh |
| 77 | + run: | |
| 78 | + $opencvVersion = "4.10.0" |
| 79 | + $url = "https://github.com/opencv/opencv/releases/download/$opencvVersion/opencv-$opencvVersion-windows.exe" |
| 80 | + Invoke-WebRequest -Uri $url -OutFile "opencv.exe" -TimeoutSec 600 |
| 81 | + Start-Process -FilePath "opencv.exe" -ArgumentList "-y -o`"D:`"" -Wait |
| 82 | + echo "OPENCV_INCLUDE_PATHS=D:\opencv\build\include" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 83 | + echo "OPENCV_LINK_LIBS=opencv_world4100" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 84 | + echo "OPENCV_LINK_PATHS=D:\opencv\build\x64\vc16\lib" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 85 | + echo "D:\opencv\build\x64\vc16\bin" | Out-File -FilePath $env:GITHUB_PATH -Append |
| 86 | +
|
| 87 | + - name: Install npm dependencies |
| 88 | + run: npm install --ignore-scripts |
| 89 | + |
| 90 | + - name: Build |
| 91 | + run: npm run build |
| 92 | + |
| 93 | + - name: Smoke test |
| 94 | + run: | |
| 95 | + node -e 'const cv = require("./main.js"); const info = cv.getBuildInformation(); if (!info.includes("OpenCV")) process.exit(1); console.log("OK:", info.split("\n")[0]);' |
| 96 | +
|
| 97 | + - name: Rename artifact |
| 98 | + run: mv node-opencv-rs.node ${{ matrix.node-file }} |
| 99 | + |
| 100 | + - name: Upload artifact |
| 101 | + uses: actions/upload-artifact@v4 |
| 102 | + with: |
| 103 | + name: ${{ matrix.node-file }} |
| 104 | + path: ${{ matrix.node-file }} |
| 105 | + retention-days: 1 |
| 106 | + |
| 107 | + publish: |
| 108 | + name: Publish to npm and GitHub Releases |
| 109 | + needs: build |
| 110 | + runs-on: ubuntu-latest |
| 111 | + permissions: |
| 112 | + contents: write |
| 113 | + |
| 114 | + steps: |
| 115 | + - uses: actions/checkout@v4 |
| 116 | + |
| 117 | + - name: Setup Node.js |
| 118 | + uses: actions/setup-node@v4 |
| 119 | + with: |
| 120 | + node-version: '22' |
| 121 | + registry-url: 'https://registry.npmjs.org' |
| 122 | + |
| 123 | + - name: Download all artifacts |
| 124 | + uses: actions/download-artifact@v4 |
| 125 | + with: |
| 126 | + path: artifacts |
| 127 | + |
| 128 | + - name: Get version from tag |
| 129 | + run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV |
| 130 | + |
| 131 | + - name: Create GitHub Release |
| 132 | + uses: softprops/action-gh-release@v2 |
| 133 | + with: |
| 134 | + generate_release_notes: true |
| 135 | + files: artifacts/**/*.node |
| 136 | + |
| 137 | + - name: Set versions in all packages |
| 138 | + run: | |
| 139 | + npm version $VERSION --no-git-tag-version --allow-same-version |
| 140 | + for dir in npm/linux-x64-gnu npm/darwin-arm64 npm/win32-x64-msvc; do |
| 141 | + cd "$dir" |
| 142 | + npm version $VERSION --no-git-tag-version --allow-same-version |
| 143 | + cd ../.. |
| 144 | + done |
| 145 | +
|
| 146 | + - name: Publish linux-x64-gnu |
| 147 | + run: | |
| 148 | + cp artifacts/node-opencv-rs.linux-x64-gnu.node/node-opencv-rs.linux-x64-gnu.node npm/linux-x64-gnu/ |
| 149 | + cd npm/linux-x64-gnu |
| 150 | + npm publish --access public |
| 151 | + env: |
| 152 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 153 | + |
| 154 | + - name: Publish darwin-arm64 |
| 155 | + if: hashFiles('artifacts/node-opencv-rs.darwin-arm64.node/node-opencv-rs.darwin-arm64.node') != '' |
| 156 | + run: | |
| 157 | + cp artifacts/node-opencv-rs.darwin-arm64.node/node-opencv-rs.darwin-arm64.node npm/darwin-arm64/ |
| 158 | + cd npm/darwin-arm64 |
| 159 | + npm publish --access public |
| 160 | + env: |
| 161 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 162 | + |
| 163 | + - name: Publish win32-x64-msvc |
| 164 | + run: | |
| 165 | + cp artifacts/node-opencv-rs.win32-x64-msvc.node/node-opencv-rs.win32-x64-msvc.node npm/win32-x64-msvc/ |
| 166 | + cd npm/win32-x64-msvc |
| 167 | + npm publish --access public |
| 168 | + env: |
| 169 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 170 | + |
| 171 | + - name: Publish main package |
| 172 | + run: npm publish --access public |
| 173 | + env: |
| 174 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments