diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 38cea82e..6e0b14cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,12 +77,9 @@ jobs: - run: opam exec -- opam install . --deps-only --with-test - run: opam exec -- dune build --verbose - - if: always() - uses: actions/upload-artifact@v4 - with: - name: odiff-${{ matrix.artifact }}.exe - path: _build/default/bin/ODiffBin.exe - retention-days: 14 + + - name: Give binary system-specific name + run: cp "_build/default/bin/ODiffBin.exe" "odiff-${{ matrix.artifact }}.exe" - run: opam exec -- dune exec ODiffBin -- --version - run: opam exec -- dune runtest @@ -102,6 +99,32 @@ jobs: - name: Install node deps run: npm ci - - name: e2e test run: npm test + + - if: always() + uses: actions/upload-artifact@v4 + with: + if-no-files-found: ignore + name: odiff-${{ matrix.artifact }}.exe + path: odiff-${{ matrix.artifact }}.exe + retention-days: 14 + + publish: + name: Publish release + needs: [build] + # if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Download built binaries + uses: actions/download-artifact@v4 + with: + pattern: odiff-*.exe + merge-multiple: true + destination-path: npm_package/raw_binaries + + - run: tree npm_package + diff --git a/npm_package/post_install.js b/npm_package/post_install.js new file mode 100644 index 00000000..aff708ff --- /dev/null +++ b/npm_package/post_install.js @@ -0,0 +1,36 @@ +const fs = require('fs'); +const path = require('path'); +const os = require('os'); + +const binaries = { + 'linux-x64': 'odiff-linux-x64.exe', + 'darwin-arm64': 'odiff-macos-arm64.exe', + 'darwin-x64': 'odiff-macos-x64.exe', + 'win32-x64': 'odiff-windows-x64.exe', +}; + +const platform = os.platform(); +const arch = os.arch(); + +let binaryKey = `${platform}-${arch}`; +if (platform === 'win32' && arch === 'x64') { + binaryKey = 'win32-x64'; +} + +const binaryFile = binaries[binaryKey]; + +if (!binaryFile) { + console.error(`odiff: Sorry your platform or architecture is not supported. Here is a list of supported binaries: ${Object.keys(binaries).join(', ')}`); + process.exit(1); +} + +const sourcePath = path.join(__dirname, 'raw_binaries', binaryFile); +const destPath = path.join(__dirname, 'bin', 'odiff'); + +try { + fs.copyFileSync(sourcePath, destPath); + fs.chmodSync(destPath, 0o755); +} catch (err) { + console.error(`odiff: failed to copy and link the binary file: ${err}`); + process.exit(1); +} diff --git a/npm_package/raw_binaries/.gitkeep b/npm_package/raw_binaries/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/release.sh b/release.sh new file mode 100644 index 00000000..6f53d021 --- /dev/null +++ b/release.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -eou pipefail + +VERSION="$1" +if ! git diff --quiet; then + echo "Error: There are unstaged changes in the repository." + exit 1 +fi + +sed -i '' "s/(version [^)]*)/(version $VERSION)/g" dune-project +dune build + +sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"$VERSION\"/g" package.json +npm install +