|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: ["v*"] |
| 7 | + pull_request: |
| 8 | + branches: [main] |
| 9 | + |
| 10 | +env: |
| 11 | + CARGO_TERM_COLOR: always |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + name: Build — ${{ matrix.settings.target }} |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + settings: |
| 20 | + - target: aarch64-apple-darwin |
| 21 | + host: macos-14 |
| 22 | + platform: darwin-arm64 |
| 23 | + - target: x86_64-apple-darwin |
| 24 | + host: macos-13 |
| 25 | + platform: darwin-x64 |
| 26 | + - target: x86_64-unknown-linux-gnu |
| 27 | + host: ubuntu-latest |
| 28 | + platform: linux-x64-gnu |
| 29 | + - target: aarch64-unknown-linux-gnu |
| 30 | + host: ubuntu-latest |
| 31 | + platform: linux-arm64-gnu |
| 32 | + cross: true |
| 33 | + - target: x86_64-pc-windows-msvc |
| 34 | + host: windows-latest |
| 35 | + platform: win32-x64-msvc |
| 36 | + runs-on: ${{ matrix.settings.host }} |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + repository: faugustdev/aiyouvector |
| 43 | + token: ${{ secrets.AIYOUVECTOR_TOKEN }} |
| 44 | + path: ../aiyouvector |
| 45 | + |
| 46 | + - uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 47 | + with: |
| 48 | + target: ${{ matrix.settings.target }} |
| 49 | + |
| 50 | + - uses: actions/setup-node@v4 |
| 51 | + with: |
| 52 | + node-version: 20 |
| 53 | + cache: npm |
| 54 | + |
| 55 | + - run: npm install |
| 56 | + |
| 57 | + # Cross-compilation for Linux ARM64 |
| 58 | + - name: Install cross-compilation tools |
| 59 | + if: matrix.settings.cross |
| 60 | + run: | |
| 61 | + sudo apt-get update |
| 62 | + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu |
| 63 | + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV |
| 64 | +
|
| 65 | + - name: Build native module |
| 66 | + run: npx napi build --platform --release --target ${{ matrix.settings.target }} |
| 67 | + |
| 68 | + - uses: actions/upload-artifact@v4 |
| 69 | + with: |
| 70 | + name: bindings-${{ matrix.settings.platform }} |
| 71 | + path: "*.node" |
| 72 | + if-no-files-found: error |
| 73 | + |
| 74 | + test: |
| 75 | + name: Test |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: [] |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v4 |
| 80 | + |
| 81 | + - uses: actions/checkout@v4 |
| 82 | + with: |
| 83 | + repository: faugustdev/aiyouvector |
| 84 | + token: ${{ secrets.AIYOUVECTOR_TOKEN }} |
| 85 | + path: ../aiyouvector |
| 86 | + |
| 87 | + - uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 88 | + |
| 89 | + - uses: actions/setup-node@v4 |
| 90 | + with: |
| 91 | + node-version: 20 |
| 92 | + cache: npm |
| 93 | + |
| 94 | + - run: npm install |
| 95 | + - run: npm run build |
| 96 | + - run: npm test |
| 97 | + |
| 98 | + rust-test: |
| 99 | + name: Rust tests |
| 100 | + runs-on: ubuntu-latest |
| 101 | + steps: |
| 102 | + - uses: actions/checkout@v4 |
| 103 | + |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + with: |
| 106 | + repository: faugustdev/aiyouvector |
| 107 | + token: ${{ secrets.AIYOUVECTOR_TOKEN }} |
| 108 | + path: ../aiyouvector |
| 109 | + |
| 110 | + - uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 111 | + |
| 112 | + - run: cargo test --workspace |
| 113 | + |
| 114 | + publish: |
| 115 | + name: Publish to npm |
| 116 | + if: startsWith(github.ref, 'refs/tags/v') |
| 117 | + needs: [build, test, rust-test] |
| 118 | + runs-on: ubuntu-latest |
| 119 | + permissions: |
| 120 | + id-token: write |
| 121 | + steps: |
| 122 | + - uses: actions/checkout@v4 |
| 123 | + |
| 124 | + - uses: actions/setup-node@v4 |
| 125 | + with: |
| 126 | + node-version: 20 |
| 127 | + registry-url: https://registry.npmjs.org |
| 128 | + cache: npm |
| 129 | + |
| 130 | + - uses: actions/download-artifact@v4 |
| 131 | + with: |
| 132 | + path: artifacts/ |
| 133 | + |
| 134 | + - run: npm install |
| 135 | + - run: npm run build:ts |
| 136 | + - name: Prepare platform packages |
| 137 | + run: node scripts/prepare-publish.js |
| 138 | + |
| 139 | + - name: Publish platform packages |
| 140 | + run: | |
| 141 | + for dir in npm/*/; do |
| 142 | + if [ -f "$dir/package.json" ] && ls "$dir"/*.node 1>/dev/null 2>&1; then |
| 143 | + echo "Publishing $(basename $dir)..." |
| 144 | + cd "$dir" |
| 145 | + npm publish --provenance --access public |
| 146 | + cd ../.. |
| 147 | + fi |
| 148 | + done |
| 149 | + env: |
| 150 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 151 | + |
| 152 | + - name: Publish @aiyou-dev/cli |
| 153 | + run: npm publish --provenance --access public |
| 154 | + env: |
| 155 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 156 | + |
| 157 | + - name: Publish aiyoucli wrapper |
| 158 | + run: | |
| 159 | + cd packages/aiyoucli |
| 160 | + npm publish --provenance --access public |
| 161 | + env: |
| 162 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments