Skip to content

Commit

Permalink
Multiple Updates: (#114)
Browse files Browse the repository at this point in the history
- Create module/index.js that will be used for running the package
- Make the node addon file have the OS name tagged on the end
- Update README.md
- Update bindings for newer version of nodejs
- Create release CI to create release and upload tarball file to github
  - Also publishes to the npm regsitry
  • Loading branch information
shanedell authored Dec 29, 2021
1 parent 72e5a4c commit 9bb23c8
Show file tree
Hide file tree
Showing 15 changed files with 535 additions and 713 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
name: Automatic Release
on:
push:
tags:
- 'v*.*.*'
env:
export_cmd: |
GIT_TAG=$(echo ${GITHUB_REF#refs/*/} | cut -d 'v' -f 2)
PKG_VERSION=$(echo $(node -p "JSON.stringify(require('./package.json').version)") | sed 's|"||g')
echo "GIT_TAG=$GIT_TAG" >> $GITHUB_ENV
echo "PKG_VERSION=$PKG_VERSION" >> $GITHUB_ENV
jobs:
build:
strategy:
matrix:
os: [macos-11, ubuntu-20.04]
name: Build ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2.3.5
- name: Setup Node
uses: actions/setup-node@v1.4.6
with:
node-version: 12

- name: Export git tag and package.json version
run: ${{ env.export_cmd }}

- name: Check if git tag matches package version
run: if [[ ${{env.GIT_TAG}} != ${{env.PKG_VERSION}} ]]; then exit 1; else exit 0; fi
shell: bash

- name: Create addon file
run: npm ci

- name: Export addon file name
run: |
NODE_FILE=""
if [[ ${{ matrix.os }} == *"macos"* ]]; then
NODE_FILE="omega_edit_darwin.node"
mv module/omega_edit_mac.node module/$NODE_FILE
else
NODE_FILE="omega_edit_linux.node"
fi
echo "NODE_FILE=$(echo $NODE_FILE)" >> $GITHUB_ENV
- name: Upload ${{ env.NODE_FILE }}
uses: actions/upload-artifact@v2.3.1
with:
name: ${{ env.NODE_FILE }}
path: module/${{ env.NODE_FILE }}
release:
name: Release package
runs-on: ubuntu-20.04
needs: build
steps:
- uses: actions/checkout@v2.3.5
- name: Setup Node
uses: actions/setup-node@v1.4.6
with:
registry-url: 'https://registry.npmjs.org'
node-version: 12

- name: Export git tag and package.json version
run: ${{ env.export_cmd }}

- name: Download node files
uses: actions/download-artifact@v2.1.0
with:
path: module/

- name: Move out node files
run: |
cd module
mv omega_edit_linux.node omega_edit_linux.node_dir
mv omega_edit_darwin.node omega_edit_darwin.node_dir
mv omega_edit_linux.node_dir/omega_edit_linux.node .
mv omega_edit_darwin.node_dir/omega_edit_darwin.node .
rm -rf omega_edit_linux.node_dir omega_edit_darwin.node_dir
- name: Check if pre-release
run: |
if [[ ${{env.GIT_TAG}} == *"pre-"* || ${{env.GIT_TAG}} == *"-pre"* ]]; then
echo "PRE_RELEASE=true" >> $GITHUB_ENV
else
echo "PRE_RELEASE=false" >> $GITHUB_ENV
fi
shell: bash

- name: Create release
uses: actions/create-release@v1.1.4
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: "${{ env.PRE_RELEASE }}"

- name: Create release tarball
run: yarn pack --filename omega-edit-v${{ env.PKG_VERSION }}.tar.gz

- name: Upload release tarball
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./omega-edit-v${{ env.PKG_VERSION }}.tar.gz
asset_name: omega-edit-v${{ env.PKG_VERSION }}.tar.gz
asset_content_type: application/tar+gzip

- name: Publish package to npm registry
run: yarn publish omega-edit-v${{ env.PKG_VERSION }}.tar.gz
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
18 changes: 10 additions & 8 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ jobs:
- name: Run Tests
working-directory: cmake-build-debug/src/tests/
run: ./omega_test -d yes --order lex
- name: Create Node v10 Virtual Environment
run: nodeenv --node=10.24.1 venv
- name: Prepare To Build Node v10 Bindings
- name: Create Node v12 Virtual Environment
run: nodeenv --node=12.22.8 venv
- name: Prepare To Build Node v12 Bindings
run: |
source ./venv/bin/activate
npm ci
- name: Test Node v10 Bindings
mv module/omega_edit* module/omega_edit.node
- name: Test Node v12 Bindings
run: |
source ./venv/bin/activate
node ./src/examples/omega_simple.js
Expand Down Expand Up @@ -57,13 +58,14 @@ jobs:
- name: Run Tests Under Valgrind
working-directory: cmake-build-debug/src/tests/
run: valgrind --leak-check=full --show-leak-kinds=all --leak-resolution=med --track-origins=yes --vgdb=no --error-exitcode=1 ./omega_test -d yes --order lex
- name: Create Node v10 Virtual Environment
run: nodeenv --node=10.24.1 venv
- name: Prepare To Build Node v10 Bindings
- name: Create Node v12 Virtual Environment
run: nodeenv --node=12.22.8 venv
- name: Prepare To Build Node v12 Bindings
run: |
source ./venv/bin/activate
npm ci
- name: Test Node v10 Bindings
mv module/omega_edit* module/omega_edit.node
- name: Test Node v12 Bindings
run: |
source ./venv/bin/activate
node ./src/examples/omega_simple.js
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ venv/

# IDE files
.idea/

# Ignore addon files
**/*.node

# Ignore packaged files
**/*.tar.gz
**/*.tgz
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
!LICENSE.txt
!package.json
!README.md
!build/Release/omega_edit.node
!module/*
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Studio Code also works well.
- CMake (https://cmake.org/download/)
- make or ninja
- nvm or nodeenv
- node-gyp (to run `package.json` scripts)
- `npm install -g node-gyp`
- swig (http://www.swig.org/svn.html)

If developing the Ωedit API, you'll need SWIG installed as well.

Expand Down Expand Up @@ -54,21 +57,20 @@ cd ../../../

## Build Node bindings

The SWIG bindings are generated for Node v10, so we need to setup the environment accordingly. There are several
reasonable ways to do this, here are two of those options:
The SWIG bindings are generated for Node v12, so we need to setup the environment accordingly. There are several reasonable ways to do this. Here are two options:

#### **OPTION 1:** Use nvm ([Node Version Manager](https://github.com/nvm-sh/nvm))

Using Node v10 in nvm looks like this:
Using Node v12 in nvm looks like this:

```bash
nvm use 10
nvm use 12
```

#### **OPTION 2:** Setup a Node v10 virtual environment using [nodeenv](https://pypi.org/project/nodeenv/)
#### **OPTION 2:** Setup a Node v12 virtual environment using [nodeenv](https://pypi.org/project/nodeenv/)

```bash
nodeenv --node=10.24.1 venv
nodeenv --node=12.22.8 venv
```

Activate the Node virtual environment:
Expand All @@ -79,7 +81,7 @@ source ./venv/bin/activate

#### Building and testing

Using Node v10 (by whatever method), build the bindings, and run an example:
Using Node v12 (by whatever method), build the bindings, and run an example:

```bash
node ci
Expand Down
15 changes: 13 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"targets": [
{
"target_name": "omega_edit",
"target_name": "omega_edit_<(OS)",
"sources": [
"src/lib/change.cpp",
"src/lib/check.cpp",
Expand All @@ -16,7 +16,18 @@
"src/lib/impl_/find.cpp",
"src/lib/impl_/internal_fun.cpp",
"src/bindings/omega_edit_wrap.cxx"
],
},
{
"target_name": "copy_binary",
"type":"none",
"dependencies" : [ "omega_edit_<(OS)" ],
"copies": [
{
'destination': '<(module_root_dir)/module/',
'files': ['<(module_root_dir)/build/Release/omega_edit_<(OS).node']
}
]
}
},
]
}
17 changes: 17 additions & 0 deletions module/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**********************************************************************************************************************
* Copyright (c) 2021 Concurrent Technologies Corporation. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software is distributed under the License is *
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
* implied. See the License for the specific language governing permissions and limitations under the License. *
* *
**********************************************************************************************************************/

// Export module for operating system
omega_edit = require("./omega_edit_" + process.platform)
module.exports = omega_edit
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "omega-edit",
"description": "OmegaEdit open source library for building editors that can handle massive files",
"version": "0.6.1",
"main": "build/Release/omega_edit",
"version": "0.6.2",
"main": "module/index.js",
"repository": {
"url": "https://github.com/scholarsmate/omega-edit",
"type": "git"
Expand All @@ -12,7 +12,16 @@
},
"author": "Shane Dell, Davin Shearer, John Wass",
"license": "Apache-2.0",
"dependencies": {
"node-gyp": "^8.4.1"
"scripts": {
"gyp-build": "node-gyp build",
"gyp-clean": "node-gyp clean",
"gyp-configure": "node-gyp configure",
"gyp-rebuild": "node-gyp rebuild",
"gyp-install": "node-gyp install",
"gyp-list": "node-gyp list",
"gyp-remove": "node-gyp remove",
"swig-compile": "swig -javascript -node -v -c++ src/bindings/omega_edit.i",
"pre-package": "yarn swig-compile && yarn gyp-configure && yarn gyp-build",
"package": "yarn pre-package && yarn publish"
}
}
Loading

0 comments on commit 9bb23c8

Please sign in to comment.