-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bundle node #58
Bundle node #58
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: 'Verify' | ||
description: 'Verifies the current branch' | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '22.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- run: npm install --force | ||
shell: bash | ||
|
||
- run: npm run lint:cli | ||
shell: bash | ||
|
||
- run: npm run build | ||
shell: bash | ||
|
||
- run: npm run test | ||
shell: bash | ||
|
||
- name: cache the dist directory | ||
uses: actions/cache/save@v4 | ||
with: | ||
path: ./dist/apps/cli | ||
key: hdcli-dist-${{ github.run_id }} | ||
|
||
- name: package for local testing | ||
shell: bash | ||
working-directory: ./dist/apps/cli | ||
run: | | ||
npm version 0.0.0-local --no-git-tag-version | ||
npm pack | ||
|
||
- name: cache the tarball | ||
uses: actions/cache/save@v4 | ||
with: | ||
path: ./dist/apps/cli/herodevs-cli-0.0.0-local.tgz | ||
key: hdcli-tarball-${{ github.run_id }} | ||
|
||
- name: install CLI dependencies | ||
run: npm install | ||
working-directory: ./dist/apps/cli | ||
shell: bash | ||
|
||
- name: create commonjs bundle using esbuild | ||
run: npx -y esbuild src/main.js --bundle --platform=node --outfile=sea.cjs --minify | ||
working-directory: ./dist/apps/cli | ||
shell: bash | ||
|
||
- name: create blob for sea | ||
run: node --experimental-sea-config ./sea-config.json | ||
working-directory: ./dist/apps/cli | ||
shell: bash | ||
|
||
- name: copy node to use to create sea | ||
run: cp $(command -v node) hdcli | ||
working-directory: ./dist/apps/cli | ||
shell: bash | ||
|
||
- name: inject the CLI sea into the copied node | ||
run: npx postject hdcli NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 | ||
working-directory: ./dist/apps/cli | ||
shell: bash | ||
|
||
- name: cache the sea | ||
uses: actions/cache/save@v4 | ||
with: | ||
path: ./dist/apps/cli/hdcli | ||
key: hdcli-sea-${{ github.run_id }} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Runtime Tests | ||
on: | ||
workflow_call: | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
jobs: | ||
via-npx: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node: ['14', '16', '18', '20', '22'] | ||
name: node ${{ matrix.node }} | ||
|
||
steps: | ||
- name: uncache the tarball | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ./dist/apps/cli/herodevs-cli-0.0.0-local.tgz | ||
key: hdcli-tarball-${{ github.run_id }} | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
|
||
- run: npm init -y | ||
|
||
- name: setup local git repo | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Github CI" | ||
git init | ||
echo "test" > test.txt | ||
git add . | ||
git commit -m "test commit" | ||
echo "test 2" > test.txt | ||
git add . | ||
git commit -m "test commit 2" | ||
|
||
- run: npm install ./dist/apps/cli/herodevs-cli-0.0.0-local.tgz | ||
|
||
- run: npx @herodevs/cli --version | ||
|
||
- run: npx @herodevs/cli report committers | ||
|
||
via-sea: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node: ['10', '12'] | ||
name: node ${{ matrix.node }} | ||
|
||
steps: | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
|
||
- name: uncache build output | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ./dist/apps/cli/hdcli | ||
key: hdcli-sea-${{ github.run_id }} | ||
|
||
- name: setup local git repo | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Github CI" | ||
git init | ||
echo "test" > test.txt | ||
git add . | ||
git commit -m "test commit" | ||
echo "test 2" > test.txt | ||
git add . | ||
git commit -m "test commit 2" | ||
|
||
- name: run the cli | ||
run: ./dist/apps/cli/hdcli report committers |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"main": "sea.cjs", | ||
"output": "sea-prep.blob", | ||
"disableExperimentalSEAWarning": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,51 @@ | ||
// eslint-disable-next-line @nx/enforce-module-boundaries | ||
import * as getJson from 'get-json'; | ||
import * as https from 'https'; | ||
import { Color, color } from './log-colors'; | ||
|
||
const red = color(Color.FgRed); | ||
const yellow = color(Color.FgYellow); | ||
|
||
async function getLatestVersion(pkgName: string) { | ||
return getJson(`https://registry.npmjs.org/${pkgName}`).then( | ||
(packageData: { 'dist-tags': { latest: string } }) => { | ||
return packageData['dist-tags'].latest; | ||
} | ||
); | ||
const url = `https://registry.npmjs.org/${pkgName}`; | ||
return new Promise((resolve, reject) => { | ||
const options = { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}; | ||
const request = https.get(url, options, (response) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use fetch instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was concerned about using fetch because this needs to run in node v14+ and IIRC fetch was added after 14 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes thats what I thought too, just wanted to confirm, fetch has been marked stable from 18 |
||
const chunks: string[] = []; | ||
|
||
response.on('data', (chunk) => chunks.push(chunk)); | ||
|
||
response.on('error', reject); | ||
|
||
response.on('end', () => { | ||
const validResponse = response.statusCode | ||
? response.statusCode >= 200 && response.statusCode <= 299 | ||
: true; | ||
const body = chunks.join(''); | ||
|
||
if (validResponse) { | ||
resolve(JSON.parse(body)['dist-tags'].latest); | ||
} else | ||
reject( | ||
new Error(`Request failed. status: ${response.statusCode || 'N/A'}, body: ${body}`) | ||
); | ||
}); | ||
}); | ||
|
||
request.on('error', (err) => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
export async function isVersionUpToDate( | ||
packageName: string, | ||
packageVersion: string, | ||
quietIfSuccessful = false | ||
): Promise<boolean> { | ||
if (packageVersion === '0.0.0') { | ||
if (packageVersion.startsWith('0.0.0')) { | ||
return true; | ||
} | ||
const latestVersion = await getLatestVersion(packageName); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a specific reason for Node 22? or we can set to latest