Skip to content

Commit

Permalink
Move prebuilds to GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
zbjornson committed May 1, 2020
1 parent 2e9ea73 commit 1e142b7
Show file tree
Hide file tree
Showing 13 changed files with 518 additions and 1 deletion.
234 changes: 234 additions & 0 deletions .github/workflows/prebuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
name: Make Prebuilds
on:
push:
branches:
- 'master'
paths:
- '.github/workflows/prebuild.yaml'

# When a new Node.js version is released or for any other reason that a build
# needs to be triggered, amend this file and force-push.

env:
# These should generally be the same:
CANVAS_VERSION_TO_BUILD: "2.6.1" # no "v" prefix. TODO switch to $GITHUB_REF if we switch to `on: release`
CANVAS_PREBUILT_VERSION: "2.6.1"

jobs:
Linux:
strategy:
matrix:
# Make sure to set this for the other builds also!
node: [8, 9, 10, 11, 12, 13, 14]
name: Node.js ${{ matrix.node }} on Linux
runs-on: ubuntu-latest
container:
image: chearon/canvas-prebuilt:7
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Build
env:
OS: ${{ runner.os }}
run: |
npm install -g node-gyp
npm install --ignore-scripts
. prebuild/$OS/preinstall.sh
cp prebuild/$OS/binding.gyp binding.gyp
node-gyp rebuild -j 2
. prebuild/$OS/bundle.sh
- name: Test binary
run: node -e "require('.')"

- name: Make bundle
id: make_bundle
run: . prebuild/tarball.sh

- name: Upload
uses: actions/[email protected]
with:
script: |
const fs = require("fs");
const assetName = "${{ steps.make_bundle.outputs.asset_name }}";
const tagName = `v${process.env.CANVAS_PREBUILT_VERSION}`;
const releases = await github.repos.listReleases({
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1]
});
const release = releases.data.find(r => r.tag_name === tagName);
for (const asset of release.assets) {
if (asset.name === assetName) {
await github.repos.deleteReleaseAsset({
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
asset_id: asset.id
});
break;
}
}
// (This is equivalent to actions/upload-release-asset. We're
// already in a script, so might as well do it here.)
const r = await github.repos.uploadReleaseAsset({
url: release.upload_url,
headers: {
"content-type": "application/x-gzip",
"content-length": `${fs.statSync(assetName).size}`
},
name: assetName,
data: fs.readFileSync(assetName)
});
macOS:
strategy:
matrix:
node: [8, 9, 10, 11, 12, 13, 14]
name: Node.js ${{ matrix.node }} on macOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Build
env:
OS: ${{ runner.os }}
run: |
npm install -g node-gyp
npm install --ignore-scripts
. prebuild/$OS/preinstall.sh
cp prebuild/$OS/binding.gyp binding.gyp
node-gyp rebuild -j 2
. prebuild/$OS/bundle.sh
- name: Test binary
run: node -e "require('.')"

- name: Make bundle
id: make_bundle
run: . prebuild/tarball.sh

- name: Upload
uses: actions/[email protected]
with:
script: |
const fs = require("fs");
const assetName = "${{ steps.make_bundle.outputs.asset_name }}";
const tagName = `v${process.env.CANVAS_PREBUILT_VERSION}`;
const releases = await github.repos.listReleases({
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1]
});
const release = releases.data.find(r => r.tag_name === tagName);
for (const asset of release.assets) {
if (asset.name === assetName) {
await github.repos.deleteReleaseAsset({
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
asset_id: asset.id
});
break;
}
}
// (This is equivalent to actions/upload-release-asset. We're
// already in a script, so might as well do it here.)
const r = await github.repos.uploadReleaseAsset({
url: release.upload_url,
headers: {
"content-type": "application/x-gzip",
"content-length": `${fs.statSync(assetName).size}`
},
name: assetName,
data: fs.readFileSync(assetName)
});
Win:
strategy:
matrix:
node: [8, 9, 10, 11, 12, 13, 14]
name: Node.js ${{ matrix.node }} on Windows
runs-on: windows-latest
steps:
# TODO drop when https://github.com/actions/virtual-environments/pull/632 lands
- uses: numworks/setup-msys2@v1
with:
update: true
path-type: inherit

- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- uses: actions/checkout@v2

- name: Setup
run: |
msys2do npm install -g node-gyp
msys2do npm install --ignore-scripts
msys2do . prebuild/Windows/preinstall.sh
- name: Build
run: |
msys2do cp prebuild/Windows/binding.gyp binding.gyp
msys2do node-gyp configure
msys2do node-gyp rebuild -j 2
- name: Bundle
run: msys2do . prebuild/Windows/bundle.sh

- name: Test binary
run: node -e "require('.')"

- name: Make asset
id: make_bundle
# I can't figure out why this isn't an env var already. It shows up with `env`.
run: msys2do CANVAS_PREBUILT_VERSION=${{ env.CANVAS_PREBUILT_VERSION }} . prebuild/tarball.sh

- name: Upload
uses: actions/[email protected]
with:
script: |
const fs = require("fs");
const assetName = "${{ steps.make_bundle.outputs.asset_name }}";
const tagName = `v${process.env.CANVAS_PREBUILT_VERSION}`;
const releases = await github.repos.listReleases({
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1]
});
const release = releases.data.find(r => r.tag_name === tagName);
for (const asset of release.assets) {
if (asset.name === assetName) {
await github.repos.deleteReleaseAsset({
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
asset_id: asset.id
});
break;
}
}
// (This is equivalent to actions/upload-release-asset. We're
// already in a script, so might as well do it here.)
const r = await github.repos.uploadReleaseAsset({
url: release.upload_url,
headers: {
"content-type": "application/x-gzip",
"content-length": `${fs.statSync(assetName).size}`
},
name: assetName,
data: fs.readFileSync(assetName)
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"binary": {
"module_name": "canvas",
"module_path": "build/Release",
"host": "https://github.com/node-gfx/node-canvas-prebuilt/releases/download/",
"host": "https://github.com/Automattic/node-canvas/releases/download/",
"remote_path": "v{version}",
"package_name": "{module_name}-v{version}-{node_abi}-{platform}-{libc}-{arch}.tar.gz"
},
Expand Down
53 changes: 53 additions & 0 deletions prebuild/Linux/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
'targets': [
{
'target_name': 'canvas',
'sources': [
'src/backend/Backend.cc',
'src/backend/ImageBackend.cc',
'src/backend/PdfBackend.cc',
'src/backend/SvgBackend.cc',
'src/bmp/BMPParser.cc',
'src/Backends.cc',
'src/Canvas.cc',
'src/CanvasGradient.cc',
'src/CanvasPattern.cc',
'src/CanvasRenderingContext2d.cc',
'src/closure.cc',
'src/color.cc',
'src/Image.cc',
'src/ImageData.cc',
'src/init.cc',
'src/register_font.cc'
],
'defines': [
'HAVE_GIF',
'HAVE_JPEG',
'HAVE_RSVG'
],
'libraries': [
'<!@(pkg-config pixman-1 --libs)',
'<!@(pkg-config cairo --libs)',
'<!@(pkg-config libpng --libs)',
'<!@(pkg-config pangocairo --libs)',
'<!@(pkg-config freetype2 --libs)',
'<!@(pkg-config librsvg-2.0 --libs)',
'-ljpeg',
'-lgif'
],
'include_dirs': [
'<!(node -e "require(\'nan\')")',
'<!@(pkg-config cairo --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config libpng --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config pangocairo --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config freetype2 --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config librsvg-2.0 --cflags-only-I | sed s/-I//g)'
],
'ldflags': [
'-Wl,-rpath \'-Wl,$$ORIGIN\''
],
'cflags!': ['-fno-exceptions'],
'cflags_cc!': ['-fno-exceptions']
}
]
}
5 changes: 5 additions & 0 deletions prebuild/Linux/bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
copies=$(lddtree.sh -l build/Release/canvas.node | sed -r -e '/^\/lib/d' -e '/canvas.node$/d');

for so in $copies; do
cp $so build/Release
done;
8 changes: 8 additions & 0 deletions prebuild/Linux/preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# apt-get-style dependencies aren't done here since the
# linux build is done on a docker image that has them

git clone git://anongit.gentoo.org/proj/pax-utils.git
cd pax-utils
PATH=$PATH:$PWD
make
cd ..
79 changes: 79 additions & 0 deletions prebuild/Windows/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
'targets': [
{
'target_name': 'canvas',
'sources': [
'src/backend/Backend.cc',
'src/backend/ImageBackend.cc',
'src/backend/PdfBackend.cc',
'src/backend/SvgBackend.cc',
'src/bmp/BMPParser.cc',
'src/Backends.cc',
'src/Canvas.cc',
'src/CanvasGradient.cc',
'src/CanvasPattern.cc',
'src/CanvasRenderingContext2d.cc',
'src/closure.cc',
'src/color.cc',
'src/Image.cc',
'src/ImageData.cc',
'src/init.cc',
'src/register_font.cc'
],
'defines': [
'HAVE_GIF',
'HAVE_JPEG',
'HAVE_RSVG',
'HAVE_BOOLEAN', # or jmorecfg.h tries to define it
'_USE_MATH_DEFINES' # for M_PI
],
'libraries': [
'D:/a/_temp/msys/msys64/mingw64/lib/libcairo-2.lib',
'D:/a/_temp/msys/msys64/mingw64/lib/libpng16-16.lib',
'D:/a/_temp/msys/msys64/mingw64/lib/libjpeg-8.lib',
'D:/a/_temp/msys/msys64/mingw64/lib/libpango-1.0-0.lib',
'D:/a/_temp/msys/msys64/mingw64/lib/libpangocairo-1.0-0.lib',
'D:/a/_temp/msys/msys64/mingw64/lib/libgobject-2.0-0.lib',
'D:/a/_temp/msys/msys64/mingw64/lib/libglib-2.0-0.lib',
'D:/a/_temp/msys/msys64/mingw64/lib/libturbojpeg.lib',
'D:/a/_temp/msys/msys64/mingw64/lib/libgif-7.lib',
'D:/a/_temp/msys/msys64/mingw64/lib/libfreetype-6.lib',
'D:/a/_temp/msys/msys64/mingw64/lib/librsvg-2-2.lib'
],
'include_dirs': [
'<!(node -e "require(\'nan\')")',
'D:/a/_temp/msys/msys64/mingw64/include',
'D:/a/_temp/msys/msys64/mingw64/include/pango-1.0',
'D:/a/_temp/msys/msys64/mingw64/include/cairo',
'D:/a/_temp/msys/msys64/mingw64/include/libpng16',
'D:/a/_temp/msys/msys64/mingw64/include/glib-2.0',
'D:/a/_temp/msys/msys64/mingw64/lib/glib-2.0/include',
'D:/a/_temp/msys/msys64/mingw64/include/pixman-1',
'D:/a/_temp/msys/msys64/mingw64/include/freetype2',
'D:/a/_temp/msys/msys64/mingw64/include/fontconfig',
'D:/a/_temp/msys/msys64/mingw64/include/librsvg-2.0',
'D:/a/_temp/msys/msys64/mingw64/include/gdk-pixbuf-2.0'
],
'configurations': {
'Debug': {
'msvs_settings': {
'VCCLCompilerTool': {
'WarningLevel': 4,
'ExceptionHandling': 1,
'DisableSpecificWarnings': [4100, 4127, 4201, 4244, 4267, 4506, 4611, 4714, 4512]
}
}
},
'Release': {
'msvs_settings': {
'VCCLCompilerTool': {
'WarningLevel': 4,
'ExceptionHandling': 1,
'DisableSpecificWarnings': [4100, 4127, 4201, 4244, 4267, 4506, 4611, 4714, 4512]
}
}
}
}
}
]
}
Loading

0 comments on commit 1e142b7

Please sign in to comment.