Skip to content

Commit

Permalink
Add release CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtrKovalenko committed Aug 25, 2024
1 parent f068899 commit 2af7814
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 7 deletions.
37 changes: 30 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

36 changes: 36 additions & 0 deletions npm_package/post_install.js
Original file line number Diff line number Diff line change
@@ -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);
}
Empty file.
16 changes: 16 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2af7814

Please sign in to comment.