-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 3d8408d
Showing
3 changed files
with
73 additions
and
0 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,13 @@ | ||
# build-action | ||
|
||
This is a Github CI action which wraps Viam's cloud build system. Use this to build and publish your Viam module for multiple platforms. | ||
|
||
## What is Viam cloud build? | ||
|
||
Cloud build is cross-compilation infrastructure that we provide to module authors so you can publish your module for multiple platforms. (x86 and ARM Linux, ideally MacOS as well). | ||
|
||
Your customers are deploying to different kinds of hardware, and prototyping on a laptop. Cloud build helps you to reach them everywhere without doing the heavy lifting of operating your own buildsystem. | ||
|
||
## Basic usage | ||
|
||
## Auth instructions |
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 @@ | ||
viam-cli |
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,59 @@ | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
const https = require('https'); | ||
const stream = require('node:stream/promises'); | ||
const util = require('node:util'); | ||
const execFileAsync = util.promisify(require('node:child_process').execFile); | ||
|
||
const platforms = ['linux', 'darwin']; | ||
const machines = { | ||
// todo: why are arm64 and aarch64 both in their docs https://nodejs.org/api/os.html#osmachine | ||
arm64: 'arm64', | ||
aarch64: 'arm64', | ||
x86_64: 'amd64', | ||
}; | ||
const cliPath = './viam-cli'; | ||
const argsConfig = { | ||
options: { | ||
"skip-download": { type: 'boolean' }, | ||
}, | ||
}; | ||
|
||
/** download a file and optionally set mode bits */ | ||
async function download(url, dest, mode = fs.constants.S_IRWXU) { | ||
const output = fs.createWriteStream(dest); | ||
const incoming = await new Promise(function(resolve, _reject) { | ||
https.get(url, (incoming) => resolve(incoming)); | ||
}) | ||
await stream.pipeline(incoming, output); | ||
if (mode != null) { | ||
fs.chmodSync(dest, mode); | ||
} | ||
} | ||
|
||
/** infer the architecture portion of the URL from os.* methods. */ | ||
function archSlug() { | ||
const platform = os.platform(), machine = os.machine(); | ||
if (platforms.indexOf(platform) == -1) { | ||
throw Error(`unknown platform ${platform}`); | ||
} | ||
if (machines[machine] == null) { | ||
throw Error(`unknown machine ${machine}`); | ||
} | ||
return `${platform}-${machines[machine]}`; | ||
} | ||
|
||
/** async main */ | ||
(async function() { | ||
const args = util.parseArgs(argsConfig); | ||
const slug = archSlug(); | ||
console.log('inferred architecture', slug); | ||
if (!args.values['skip-download']) { | ||
await download(`https://storage.googleapis.com/packages.viam.com/apps/viam-cli/viam-cli-stable-${slug}`, cliPath); | ||
console.log('downloaded CLI'); | ||
} | ||
console.log((await execFileAsync(cliPath, ['version'])).stdout.trim()); | ||
console.warn("TODO: start build"); | ||
console.warn("TODO: wait for build"); | ||
console.warn("TODO: show logs / status"); | ||
})(); |