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 ca1f58e commit b5af844
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 11 deletions.
File renamed without changes.
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/create-release@v1.0.0
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/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: gpio-adapter-${{ env.RELEASE_VERSION }}-${{ matrix.platform }}-v${{ matrix.version }}.tgz
asset_name: gpio-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/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: gpio-adapter-${{ env.RELEASE_VERSION }}-${{ matrix.platform }}-v${{ matrix.version }}.tgz.sha256sum
asset_name: gpio-adapter-${{ env.RELEASE_VERSION }}-${{ matrix.platform }}-v${{ matrix.version }}.tgz.sha256sum
asset_content_type: text/plain
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
8 changes: 4 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"author": "Mozilla IoT",
"description": "GPIO adapter plugin for Mozilla WebThings Gateway",
"author": "WebThingsIO",
"description": "GPIO adapter plugin for WebThings Gateway",
"gateway_specific_settings": {
"webthings": {
"exec": "{nodeLoader} {path}",
Expand All @@ -9,7 +9,7 @@
"strict_min_version": "0.10.0"
}
},
"homepage_url": "https://github.com/mozilla-iot/gpio-adapter",
"homepage_url": "https://github.com/WebThingsIO/gpio-adapter",
"id": "gpio-adapter",
"license": "MPL-2.0",
"manifest_version": 1,
Expand Down Expand Up @@ -91,5 +91,5 @@
}
},
"short_name": "GPIO",
"version": "0.7.4"
"version": "0.7.5"
}
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "gpio-adapter",
"version": "0.7.4",
"description": "GPIO adapter plugin for Mozilla WebThings Gateway",
"author": "Mozilla IoT",
"version": "0.7.5",
"description": "GPIO adapter plugin for WebThings Gateway",
"author": "WebThingsIO",
"main": "index.js",
"scripts": {
"lint": "eslint ."
},
"homepage": "https://github.com/mozilla-iot/gpio-adapter",
"homepage": "https://github.com/WebThingsIO/gpio-adapter",
"license": "MPL-2.0",
"repository": {
"type": "git",
"url": "https://github.com/mozilla-iot/gpio-adapter.git"
"url": "https://github.com/WebThingsIO/gpio-adapter.git"
},
"bugs": {
"url": "https://github.com/mozilla-iot/gpio-adapter/issues"
"url": "https://github.com/WebThingsIO/gpio-adapter/issues"
},
"files": [
"LICENSE",
Expand All @@ -29,6 +29,6 @@
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^7.5.0"
"eslint": "^7.10.0"
}
}
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 b5af844

Please sign in to comment.