Skip to content

Commit c42b670

Browse files
committed
initial commit
0 parents  commit c42b670

File tree

9 files changed

+4915
-0
lines changed

9 files changed

+4915
-0
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
indent_size = 4
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.yaml]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[*.py]
15+
indent_style = space
16+
indent_size = 4

.github/workflows/build.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This should probably be "CD" instead or even some alternative name. I feel like
2+
# we should do some versioning before actually publishing though.
3+
name: Build
4+
on:
5+
push:
6+
branches: [ $default-branch ]
7+
pull_request:
8+
branches: [ $default-branch ]
9+
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
name: Build Node for nexe bundling
15+
runs-on: ${{ matrix.os }}
16+
# Building on Linux takes a bit over 4 hours.
17+
timeout-minutes: 360
18+
strategy:
19+
matrix:
20+
# macos-13 is the most recent Intel available in github actions.
21+
os: [macos-13, macos-latest, ubuntu-latest, windows-latest]
22+
# This allows builds like Linux to continue when builds like Windows fail.
23+
fail-fast: false
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Setup Node
29+
uses: actions/setup-node@v5
30+
with:
31+
node-version: 24.8.0
32+
33+
- run: npm ci
34+
35+
- name: Set up Python 3.13.7
36+
uses: actions/setup-python@v6
37+
with:
38+
python-version: '3.13.7'
39+
40+
- name: Install nasm
41+
if: runner.os == 'Windows'
42+
run: choco install nasm
43+
44+
- name: Check Versions
45+
run: |
46+
python3 --version
47+
node --version
48+
echo "Working directory:"
49+
pwd
50+
51+
- name: Build nexe if required
52+
run: |
53+
node bin/build.mjs
54+
env:
55+
GH_TOKEN: ${{ secrets.GH_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
dist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Urban Dynamics
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.adoc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
== nexe builds for the SmartThings CLI
2+
3+
Cached builds of Node for https://www.npmjs.com/package/nexe[nexe] to be used with nexe for the SmartThings CLI.
4+
5+
This repository is somewhat based on https://github.com/urbdyn/nexe_builds.
6+
7+
== Using this repository
8+
9+
== Creating a new release
10+
11+
Creating a new release of this is somewhat manual at this point.
12+
13+
[arabic]
14+
. Make your changes, e.g. update the Node version or nexe version.
15+
. Update the version number in package.json.
16+
. Create a new release, documenting which version of nexe and Node this release is for.
17+
. Upload and/or build assets.
18+
19+
=== Uploading or building assets
20+
21+
Trigging a build manually will build and upload the binaries for:
22+
23+
* Windows Intel
24+
* Linux Intel
25+
* MacOS Intel
26+
* MacOS ARM
27+
28+
One can build assets locally as well. This can make things quicker in some cases as builds
29+
in github take a very long time.
30+
31+
[arabic]
32+
. Clone this repository
33+
. Install the exact version of Node you will be building for.
34+
. Run `npm install`
35+
. Ensure the machine has the capability of building Node (see https://github.com/nodejs/node/blob/main/BUILDING.md).
36+
. Set GH_TOKEN to a token with read and write Content scopes.
37+
. Run `node bin/build.mjs`
38+
. Once the build is successful, it will be automatically uploaded.

bin/build.mjs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
2+
import path from 'node:path'
3+
import { inspect } from 'node:util'
4+
5+
import { request } from '@octokit/request'
6+
import { compile } from 'nexe'
7+
8+
9+
const skipUpload = process.argv.length > 2 && process.argv[2] === '--skip-upload'
10+
11+
// valid platform values: 'windows' | 'mac' | 'alpine' | 'linux' // NodePlatform in nexe
12+
// valid arch values 'x86' | 'x64' | 'arm' | 'arm64' // NodeArch in nexe
13+
14+
const osByPlatform = {
15+
darwin: 'mac',
16+
win32: 'windows',
17+
}
18+
19+
const os = osByPlatform[process.platform] ?? process.platform
20+
const arch = process.arch
21+
const version = process.version.substring(1)
22+
23+
const target = `${os}-${arch}-${version}`
24+
25+
console.log(`building ${version}`)
26+
console.log(`process.arch = [${process.arch}]`)
27+
console.log(`process.platform = [${process.platform}]`)
28+
console.log(`target = ${target}`)
29+
30+
mkdir('dist').catch((error) => {
31+
if (error.code !== 'EEXIST') throw error
32+
})
33+
34+
const owner = 'SmartThingsCommunity'
35+
const repo = 'cli-nexe-builds'
36+
37+
const ghToken = process.env.GH_TOKEN
38+
39+
if (!ghToken) {
40+
console.error('Did not get github token. Missing secret?')
41+
process.exit(1)
42+
}
43+
44+
const __dirname = import.meta.dirname
45+
const packageData = JSON.parse(await readFile(path.join(__dirname, '../package.json')))
46+
const releaseVersion = packageData.version
47+
48+
const gitAPIHeaders = {
49+
authorization: `token ${ghToken}`,
50+
}
51+
const releases = (await request("GET /repos/:owner/:repo/releases", {
52+
headers: gitAPIHeaders,
53+
owner,
54+
repo,
55+
})).data
56+
const release = releases.find(release => release.tag_name === releaseVersion)
57+
58+
const asset = release.assets?.find(asset => asset.name === target)
59+
60+
const outputFilename = path.join(__dirname, `../dist/${target}`)
61+
if (asset) {
62+
console.log('Found asset already exists; skipping.')
63+
} else {
64+
console.log(`Building ${outputFilename}.`)
65+
compile({
66+
input: 'bin/dummy.mjs',
67+
build: true,
68+
verbose: true,
69+
mangle: false,
70+
output: outputFilename,
71+
python: 'python3',
72+
targets: [target],
73+
}).then(async () => {
74+
if (skipUpload) {
75+
console.log('Build finished; skipping upload.')
76+
} else {
77+
console.log('Build finished; uploading asset.')
78+
79+
const currentDir = path.join(__dirname, '..')
80+
const distFiles = await readdir(path.join(currentDir, 'dist'))
81+
console.log(`files in dist dir = ${JSON.stringify(distFiles)}`)
82+
83+
const filename = os === 'windows' ? `${outputFilename}.exe` : outputFilename
84+
const buildFileContents = await readFile(filename)
85+
console.log(`read file containing ${buildFileContents.length} bytes`)
86+
await request(
87+
`POST /repos/:owner/:repo/releases/:release_id/assets?name=:name`,
88+
{
89+
baseUrl: "https://uploads.github.com",
90+
headers: {
91+
'Content-Type': 'application/x-binary',
92+
'Content-Length': buildFileContents.length,
93+
...gitAPIHeaders,
94+
},
95+
name: target,
96+
owner,
97+
repo,
98+
release_id: release.id,
99+
data: buildFileContents,
100+
},
101+
)
102+
}
103+
})
104+
}

bin/dummy.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('dummy script')

0 commit comments

Comments
 (0)