Skip to content

Commit

Permalink
Add cross-compile action.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstegeman committed Oct 2, 2020
1 parent 6ddb980 commit f171843
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 15 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Create Release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- run: echo ::set-env name=UPLOAD_URL::'${{ steps.create_release.outputs.upload_url }}' > upload_url
- name: Upload upload_url
uses: actions/upload-artifact@v1
with:
name: upload_url
path: upload_url

build:
needs: create-release
strategy:
matrix:
platform: [
'linux-arm',
'linux-arm64',
'linux-x64',
'darwin-x64',
]
pair: [
'node:8',
'node:10',
'node:12',
'node:14',
]
include:
- platform: 'linux-arm'
host-os: 'ubuntu-latest'
- platform: 'linux-arm64'
host-os: 'ubuntu-latest'
- platform: 'linux-x64'
host-os: 'ubuntu-latest'
- platform: 'darwin-x64'
host-os: 'macos-latest'
- pair: 'node:8'
language: 'node'
version: '8'
- pair: 'node:10'
language: 'node'
version: '10'
- pair: 'node:12'
language: 'node'
version: '12'
- pair: 'node:14'
language: 'node'
version: '14'

runs-on: ${{ matrix.host-os }}

steps:
- name: Download upload_url
uses: actions/download-artifact@v1
with:
name: upload_url
- name: Set upload_url env var
run: cat upload_url/upload_url
- name: Set env
run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:11})
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.version }}
- name: Build adapter
run: |
./build.sh "${{ matrix.platform }}" "${{ matrix.language }}" "${{ matrix.version }}"
- name: Upload Release Asset
id: upload-release-asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: homekit-adapter-${{ env.RELEASE_VERSION }}-${{ matrix.platform }}-v${{ matrix.version }}.tgz
asset_name: homekit-adapter-${{ env.RELEASE_VERSION }}-${{ matrix.platform }}-v${{ matrix.version }}.tgz
asset_content_type: application/zip
- name: Upload Release Asset Checksum
id: upload-release-asset-checksum
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: homekit-adapter-${{ env.RELEASE_VERSION }}-${{ matrix.platform }}-v${{ matrix.version }}.tgz.sha256sum
asset_name: homekit-adapter-${{ env.RELEASE_VERSION }}-${{ matrix.platform }}-v${{ matrix.version }}.tgz.sha256sum
asset_content_type: text/plain
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# homekit-adapter

HomeKit device adapter for Mozilla WebThings Gateway
HomeKit device adapter for WebThings Gateway

## Supported Devices

Expand Down
81 changes: 81 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash -e

ADDON_ARCH="$1"
LANGUAGE_NAME="$2"
LANGUAGE_VERSION="$3"

function map_posix_tools() {
tar() {
gtar "$@"
return $!
}
export -f tar

readlink() {
greadlink "$@"
return $!
}
export -f readlink

find() {
gfind "$@"
return $!
}
export -f find
}

function install_osx_compiler() {
brew install \
boost \
cmake \
coreutils \
eigen \
findutils \
gnu-tar \
pkg-config
map_posix_tools
}

function install_linux_cross_compiler() {
sudo apt -qq update
sudo apt install --no-install-recommends -y \
binfmt-support \
qemu \
qemu-user-static
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
}

function build_native() {
ADDON_ARCH=${ADDON_ARCH} ./package.sh
}

function build_cross_compiled() {
docker run --rm -t -v $PWD:/build webthingsio/toolchain-${ADDON_ARCH}-${LANGUAGE_NAME}-${LANGUAGE_VERSION} bash -c "cd /build; ADDON_ARCH=${ADDON_ARCH} ./package.sh"
}

case "${ADDON_ARCH}" in
darwin-x64)
install_osx_compiler
build_native
;;

linux-arm)
install_linux_cross_compiler
build_cross_compiled
;;

linux-arm64)
install_linux_cross_compiler
build_cross_compiled
;;

linux-x64)
install_linux_cross_compiler
build_cross_compiled
;;

*)
echo "Unsupported architecture"
exit 1
;;
esac
4 changes: 2 additions & 2 deletions lib/homekit-adapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* HomeKit adapter for Mozilla WebThings Gateway.
* HomeKit adapter for WebThings Gateway.
*/
'use strict';

Expand Down Expand Up @@ -28,7 +28,7 @@ class HomeKitAdapter extends Adapter {
this.knownDevices = new Set();

this.db = new HomeKitDatabase(this.packageName);
this.db.open().then(() => {
this.db.open(this.userProfile.dataDir).then(() => {
return this.db.loadConfig();
}).then((config) => {
this.config = config;
Expand Down
12 changes: 9 additions & 3 deletions lib/homekit-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ const os = require('os');
const path = require('path');
const storage = require('node-persist');

function getDataPath() {
function getDataPath(dataDir) {
if (dataDir) {
return path.join(dataDir, 'homekit-adapter');
}

let profileDir;
if (process.env.hasOwnProperty('MOZIOT_HOME')) {
profileDir = process.env.MOZIOT_HOME;
Expand All @@ -28,10 +32,12 @@ class HomeKitDatabase extends Database {
/**
* Open the database.
*
* @param {string} dataDir - Configured data directory
* @returns Promise which resolves when the database has been opened.
*/
open() {
const dataDir = getDataPath();
open(dataDir) {
dataDir = getDataPath(dataDir);

if (!fs.existsSync(dataDir)) {
mkdirp.sync(dataDir, {mode: 0o755});
}
Expand Down
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"author": "Mozilla IoT",
"author": "WebThingsIO",
"description": "HomeKit device adapter.",
"gateway_specific_settings": {
"webthings": {
Expand All @@ -9,7 +9,7 @@
"strict_min_version": "0.10.0"
}
},
"homepage_url": "https://github.com/mozilla-iot/homekit-adapter",
"homepage_url": "https://github.com/WebThingsIO/homekit-adapter",
"id": "homekit-adapter",
"license": "MPL-2.0",
"manifest_version": 1,
Expand All @@ -32,5 +32,5 @@
}
},
"short_name": "HomeKit",
"version": "0.9.2"
"version": "0.9.3"
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "homekit-adapter",
"version": "0.9.2",
"version": "0.9.3",
"description": "HomeKit device adapter.",
"author": "Mozilla IoT",
"author": "WebThingsIO",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"lint": "eslint ."
},
"homepage": "https://github.com/mozilla-iot/homekit-adapter",
"homepage": "https://github.com/WebThingsIO/homekit-adapter",
"license": "MPL-2.0",
"repository": {
"type": "git",
"url": "https://github.com/mozilla-iot/homekit-adapter.git"
"url": "https://github.com/WebThingsIO/homekit-adapter.git"
},
"bugs": {
"url": "https://github.com/mozilla-iot/homekit-adapter/issues"
"url": "https://github.com/WebThingsIO/homekit-adapter/issues"
},
"dependencies": {
"color": "^3.1.2",
Expand All @@ -27,7 +27,7 @@
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^7.5.0"
"eslint": "^7.10.0"
},
"files": [
"LICENSE",
Expand Down
5 changes: 5 additions & 0 deletions package.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash -e

# Setup environment for building inside Dockerized toolchain
export NVM_DIR="${HOME}/.nvm"
[ -s "${NVM_DIR}/nvm.sh" ] && source "${NVM_DIR}/nvm.sh"
[ $(id -u) = 0 ] && umask 0

rm -rf node_modules

if [ -z "${ADDON_ARCH}" ]; then
Expand Down

0 comments on commit f171843

Please sign in to comment.