forked from stackgl/headless-gl
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
350 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Build and upload | ||
|
||
on: workflow_dispatch | ||
|
||
jobs: | ||
build: | ||
name: ${{ matrix.platform.name }} Node.js v${{ matrix.node }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: | ||
- { name: 'Linux (x64)' ,os: ubuntu-22.04 } | ||
- { name: 'Windows (x64)' ,os: windows-2022 } | ||
- { name: 'Mac (x64)' ,os: macos-12 } | ||
- { name: 'Mac (arm64)' ,os: macos-12 ,arch: arm64 } | ||
node: [ 14, 16, 18 ] | ||
|
||
runs-on: ${{ matrix.platform.os }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
|
||
- if: ${{ startsWith(matrix.platform.os, 'ubuntu-') }} | ||
run: npm run install-deps-ubuntu | ||
|
||
- run: npm run release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
CROSS_COMPILE_ARCH: ${{ matrix.platform.arch }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
example/* | ||
test/* | ||
.github | ||
.travis.yml | ||
appveyor.yml | ||
build/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Fs from 'node:fs' | ||
import { execSync } from 'node:child_process' | ||
import C from './util/common.js' | ||
|
||
await Promise.all([ | ||
C.dir.build, | ||
C.dir.dist, | ||
C.dir.publish, | ||
].map(async (dir) => { | ||
await Fs.promises.rm(dir, { recursive: true }).catch(() => {}) | ||
})) | ||
|
||
console.log("build in", C.dir.build) | ||
|
||
let archFlag = '' | ||
if (process.env.CROSS_COMPILE_ARCH) { | ||
archFlag = `--arch ${process.env.CROSS_COMPILE_ARCH}` | ||
} | ||
|
||
process.chdir(C.dir.root) | ||
execSync(`npx node-gyp rebuild ${archFlag} -j max --verbose`, { stdio: 'inherit' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Fs from 'node:fs' | ||
import Path from 'node:path' | ||
import C from './util/common.js' | ||
|
||
const dirs = [ | ||
Path.join(C.dir.root, 'node_modules'), | ||
C.dir.build, | ||
C.dir.dist, | ||
C.dir.publish, | ||
] | ||
|
||
console.log("delete") | ||
await Promise.all(dirs.map(async (dir) => { | ||
console.log(" ", dir) | ||
await Fs.promises.rm(dir, { recursive: true }).catch(() => {}) | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Fs from 'node:fs' | ||
import { once } from 'node:events' | ||
import C from './util/common.js' | ||
import { fetch } from './util/fetch.js' | ||
import Tar from 'tar' | ||
|
||
const url = `https://github.com/${C.owner}/${C.repo}/releases/download/v${C.version}/${C.assetName}` | ||
|
||
console.log("fetch", url) | ||
const response = await fetch(url) | ||
|
||
console.log("unpack to", C.dir.release) | ||
await Fs.promises.rm(C.dir.build, { recursive: true }).catch(() => {}) | ||
await Fs.promises.mkdir(C.dir.release, { recursive: true }) | ||
const tar = Tar.extract({ gzip: true, C: C.dir.release }) | ||
response.stream().pipe(tar) | ||
await once(tar, 'finish') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
sudo apt update | ||
sudo apt install build-essential libxi-dev \ | ||
libglu1-mesa-dev libglew-dev pkg-config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
if (!process.env.GL_FROM_SOURCE) { | ||
try { | ||
await import('./download-release.mjs') | ||
process.exit() | ||
} catch (error) {} | ||
} else { | ||
console.log("skip download and build from source") | ||
} | ||
|
||
await import('./build.mjs') |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { execSync } from 'node:child_process' | ||
|
||
await import('./clean.mjs') | ||
|
||
process.env.GL_FROM_SOURCE = 1 | ||
execSync('npm install', { | ||
stdio: 'inherit', | ||
}) | ||
|
||
await import('./upload-release.mjs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Path from 'node:path' | ||
import { execSync } from 'node:child_process' | ||
import { fstat } from 'node:fs' | ||
|
||
process.chdir(Path.resolve(__dirname, '../tests')) | ||
const files = await fstat.readdir('.') | ||
for (const name of files) { | ||
if (!name.endsWith('.test.js')) { continue } | ||
execSync(`node ${name}`, { stdio: 'inherit' }) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import Fs from 'node:fs' | ||
import Path from 'node:path' | ||
import C from './util/common.js' | ||
import { fetch } from './util/fetch.js' | ||
import Tar from 'tar' | ||
|
||
console.log("gather files in", C.dir.dist) | ||
await Fs.promises.rm(C.dir.dist, { recursive: true }).catch(() => {}) | ||
await Fs.promises.mkdir(C.dir.dist, { recursive: true }) | ||
await Fs.promises.copyFile( | ||
Path.join(C.dir.release, 'webgl.node'), | ||
Path.join(C.dir.dist, 'webgl.node'), | ||
) | ||
|
||
if (C.platform === 'win32') { | ||
const names = await Fs.promises.readdir(C.dir.release) | ||
await Promise.all(names.map(async (name) => { | ||
if (!name.endsWith('.dll')) { return } | ||
await Fs.promises.copyFile( | ||
Path.join(C.dir.release, name), | ||
Path.join(C.dir.dist, name), | ||
) | ||
})) | ||
} | ||
|
||
const commonHeaders = { | ||
"Accept": 'application/vnd.github+json', | ||
"Authorization": `Bearer ${process.env.GITHUB_TOKEN}`, | ||
'User-Agent': `@kmamal/gl@${C.version}`, | ||
} | ||
|
||
let response | ||
|
||
getRelease: { | ||
console.log("get release", C.version) | ||
|
||
try { | ||
response = await fetch( | ||
`https://api.github.com/repos/${C.owner}/${C.repo}/releases/tags/v${C.version}`, | ||
{ headers: commonHeaders }, | ||
) | ||
console.log("release exists", C.version) | ||
break getRelease | ||
} catch (error) { | ||
console.log(error.message) | ||
} | ||
|
||
console.log("create release", C.version) | ||
|
||
response = await fetch( | ||
`https://api.github.com/repos/${C.owner}/${C.repo}/releases`, | ||
{ | ||
method: 'POST', | ||
headers: commonHeaders, | ||
body: JSON.stringify({ | ||
tag_name: `v${C.version}`, // eslint-disable-line camelcase | ||
name: `v${C.version}`, | ||
}), | ||
}, | ||
) | ||
} | ||
const releaseId = (await response.json()).id | ||
|
||
console.log("create archive", C.assetName) | ||
await Fs.promises.rm(C.dir.publish, { recursive: true }).catch(() => {}) | ||
await Fs.promises.mkdir(C.dir.publish, { recursive: true }) | ||
const assetPath = Path.join(C.dir.publish, C.assetName) | ||
|
||
process.chdir(C.dir.dist) | ||
await Tar.create( | ||
{ gzip: true, file: assetPath }, | ||
await Fs.promises.readdir('.'), | ||
) | ||
const buffer = await Fs.promises.readFile(assetPath) | ||
|
||
response = await fetch( | ||
`https://api.github.com/repos/${C.owner}/${C.repo}/releases/${releaseId}/assets`, | ||
{ headers: commonHeaders }, | ||
) | ||
|
||
const list = await response.json() | ||
const asset = list.find((x) => x.name === C.assetName) | ||
if (asset) { | ||
console.log("delete asset", C.assetName) | ||
await fetch( | ||
`https://api.github.com/repos/${C.owner}/${C.repo}/releases/assets/${asset.id}`, | ||
{ | ||
method: 'DELETE', | ||
headers: commonHeaders, | ||
}, | ||
) | ||
} | ||
|
||
console.log("upload", C.assetName) | ||
await fetch( | ||
`https://uploads.github.com/repos/${C.owner}/${C.repo}/releases/${releaseId}/assets?name=${C.assetName}`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
...commonHeaders, | ||
'Content-Type': 'application/gzip', | ||
}, | ||
body: buffer, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const Fs = require('node:fs') | ||
const Path = require('node:path') | ||
|
||
const dir = {} | ||
dir.root = Path.resolve(__dirname, '../..') | ||
dir.build = Path.join(dir.root, 'build') | ||
dir.release = Path.join(dir.build, 'Release') | ||
dir.dist = Path.join(dir.root, 'dist') | ||
dir.publish = Path.join(dir.root, 'publish') | ||
|
||
const pkgPath = Path.join(dir.root, 'package.json') | ||
const pkg = JSON.parse(Fs.readFileSync(pkgPath).toString()) | ||
const version = pkg.version.slice(0, pkg.version.indexOf('-')) | ||
const [ , owner, repo ] = pkg.repository.url.match(/([^/:]+)\/([^/]+).git$/u) | ||
|
||
const { platform, arch } = process | ||
const abi = process.versions.modules | ||
const targetArch = process.env.CROSS_COMPILE_ARCH || arch | ||
const assetName = `gl-v${version}-node_v${abi}-${platform}-${targetArch}.tar.gz` | ||
|
||
module.exports = { | ||
dir, | ||
version, | ||
owner, | ||
repo, | ||
platform, | ||
arch, | ||
targetArch, | ||
assetName, | ||
} |
Oops, something went wrong.