|
| 1 | +name: Build and Publish npm |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + publish-to-npm: |
| 10 | + description: 'Publish to npm (true/false)' |
| 11 | + required: false |
| 12 | + default: 'false' |
| 13 | + type: choice |
| 14 | + options: |
| 15 | + - 'true' |
| 16 | + - 'false' |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + name: Build (${{ matrix.target }}) |
| 24 | + runs-on: ${{ matrix.os }} |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + include: |
| 29 | + - target: x86_64-unknown-linux-gnu |
| 30 | + os: ubuntu-latest |
| 31 | + - target: aarch64-unknown-linux-gnu |
| 32 | + os: ubuntu-latest |
| 33 | + - target: x86_64-apple-darwin |
| 34 | + os: macos-latest |
| 35 | + - target: aarch64-apple-darwin |
| 36 | + os: macos-latest |
| 37 | + - target: x86_64-pc-windows-msvc |
| 38 | + os: windows-latest |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - uses: actions/setup-node@v4 |
| 43 | + with: |
| 44 | + node-version: 20 |
| 45 | + |
| 46 | + - uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 47 | + with: |
| 48 | + target: ${{ matrix.target }} |
| 49 | + |
| 50 | + - name: Install dependencies |
| 51 | + working-directory: crates/ofd-validator-js |
| 52 | + run: npm install |
| 53 | + |
| 54 | + - name: Install cross-compilation tools |
| 55 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 56 | + run: | |
| 57 | + sudo apt-get update |
| 58 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 59 | +
|
| 60 | + - name: Build native addon |
| 61 | + working-directory: crates/ofd-validator-js |
| 62 | + run: npx napi build --release --platform --target ${{ matrix.target }} |
| 63 | + |
| 64 | + - name: Upload artifact |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: binding-${{ matrix.target }} |
| 68 | + path: crates/ofd-validator-js/*.node |
| 69 | + retention-days: 7 |
| 70 | + |
| 71 | + test: |
| 72 | + name: Test (${{ matrix.os }}) |
| 73 | + needs: build |
| 74 | + runs-on: ${{ matrix.os }} |
| 75 | + strategy: |
| 76 | + fail-fast: false |
| 77 | + matrix: |
| 78 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - uses: actions/setup-node@v4 |
| 83 | + with: |
| 84 | + node-version: 20 |
| 85 | + |
| 86 | + - name: Download all artifacts |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + pattern: binding-* |
| 90 | + merge-multiple: true |
| 91 | + path: crates/ofd-validator-js |
| 92 | + |
| 93 | + - name: Install dependencies |
| 94 | + working-directory: crates/ofd-validator-js |
| 95 | + run: npm install |
| 96 | + |
| 97 | + - name: Smoke test |
| 98 | + working-directory: crates/ofd-validator-js |
| 99 | + shell: bash |
| 100 | + run: | |
| 101 | + node -e " |
| 102 | + const v = require('./index'); |
| 103 | + console.log('Available exports:', Object.keys(v)); |
| 104 | +
|
| 105 | + // Test that all path-mode functions exist |
| 106 | + console.assert(typeof v.validateAll === 'function', 'validateAll missing'); |
| 107 | + console.assert(typeof v.validateJsonFiles === 'function', 'validateJsonFiles missing'); |
| 108 | + console.assert(typeof v.validateLogoFiles === 'function', 'validateLogoFiles missing'); |
| 109 | + console.assert(typeof v.validateFolderNames === 'function', 'validateFolderNames missing'); |
| 110 | + console.assert(typeof v.validateStoreIds === 'function', 'validateStoreIds missing'); |
| 111 | + console.assert(typeof v.validateGtinEan === 'function', 'validateGtinEan missing'); |
| 112 | + console.assert(typeof v.validateRequiredFiles === 'function', 'validateRequiredFiles missing'); |
| 113 | + console.assert(typeof v.validateLogoFile === 'function', 'validateLogoFile missing'); |
| 114 | + console.assert(typeof v.validateFolderName === 'function', 'validateFolderName missing'); |
| 115 | +
|
| 116 | + // Test that all content-mode functions exist |
| 117 | + console.assert(typeof v.validateJsonContent === 'function', 'validateJsonContent missing'); |
| 118 | + console.assert(typeof v.validateLogoContent === 'function', 'validateLogoContent missing'); |
| 119 | + console.assert(typeof v.validateFolderNameContent === 'function', 'validateFolderNameContent missing'); |
| 120 | + console.assert(typeof v.validateGtinEanContent === 'function', 'validateGtinEanContent missing'); |
| 121 | + console.assert(typeof v.validateStoreIdsContent === 'function', 'validateStoreIdsContent missing'); |
| 122 | + console.assert(typeof v.validateAllContent === 'function', 'validateAllContent missing'); |
| 123 | +
|
| 124 | + console.log('All smoke tests passed'); |
| 125 | + " |
| 126 | +
|
| 127 | + publish: |
| 128 | + name: Publish to npm |
| 129 | + needs: test |
| 130 | + runs-on: ubuntu-latest |
| 131 | + if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish-to-npm == 'true') |
| 132 | + steps: |
| 133 | + - uses: actions/checkout@v4 |
| 134 | + |
| 135 | + - uses: actions/setup-node@v4 |
| 136 | + with: |
| 137 | + node-version: 20 |
| 138 | + registry-url: https://registry.npmjs.org |
| 139 | + |
| 140 | + - name: Download all artifacts |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + pattern: binding-* |
| 144 | + merge-multiple: true |
| 145 | + path: crates/ofd-validator-js |
| 146 | + |
| 147 | + - name: Install dependencies |
| 148 | + working-directory: crates/ofd-validator-js |
| 149 | + run: npm install |
| 150 | + |
| 151 | + - name: Prepare platform packages |
| 152 | + working-directory: crates/ofd-validator-js |
| 153 | + run: npx napi prepublish --skip-gh-release |
| 154 | + |
| 155 | + - name: List packages |
| 156 | + working-directory: crates/ofd-validator-js |
| 157 | + run: ls -lhR npm/ *.node 2>/dev/null || true |
| 158 | + |
| 159 | + - name: Publish |
| 160 | + working-directory: crates/ofd-validator-js |
| 161 | + run: | |
| 162 | + npm publish --access public |
| 163 | + env: |
| 164 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments