Skip to content

Commit

Permalink
test: verify against multiple versions of node
Browse files Browse the repository at this point in the history
  • Loading branch information
Brocco committed Jun 13, 2024
1 parent a101ac1 commit 541447e
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 2,223 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/composite/verify
- uses: ./.github/workflows/composite/build

verify:
needs: build
uses: ./.github/workflows/runtime-tests.yml
72 changes: 72 additions & 0 deletions .github/workflows/composite/build/action.yml
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 }}
21 changes: 0 additions & 21 deletions .github/workflows/composite/verify/action.yml

This file was deleted.

21 changes: 19 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/composite/verify

- uses: ./.github/workflows/composite/build

verify:
needs: build
uses: ./.github/workflows/runtime-tests.yml

release:
runs-on: ubuntu-latest
needs: verify
steps:
- uses: actions/checkout@v4

- name: restore the dist directory from cache
uses: actions/cache/restore@v4
with:
path: ./dist/apps/cli
key: hdcli-dist-${{ github.run_id }}

- name: release-version
uses: actions/github-script@v7
Expand All @@ -23,7 +40,7 @@ jobs:
return releaseVersion;
result-encoding: string

- name: set version in package.json and publish
- name: update package.json and publish
working-directory: dist/apps/cli
env:
NODE_AUTH_TOKEN: ${{ secrets.HD_CLI_NPM_TOKEN }}
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/runtime-tests.yml
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
1 change: 1 addition & 0 deletions apps/cli/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"includeTransitiveDependencies": true,
"useLocalPathsForWorkspaceDependencies": true,
"ignoredDependencies": [
"graphql",
"@herodevs/report-committers",
"@herodevs/report-diagnostics",
"@herodevs/tracker-init",
Expand Down
12 changes: 6 additions & 6 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"version": "0.0.0",
"bin": "./src/main.js",
"dependencies": {
"tslib": "^2.3.0",
"yargs": "^17.7.2",
"get-json": "^1.0.1",
"date-fns": "^3.6.0",
"@apollo/client": "^3.10.1",
"@inquirer/prompts": "^5.0.2",
"date-fns": "^3.6.0",
"git-last-commit": "^1.0.1",
"graphql": "^16.8.1",
"ora": "5.3.0",
"sloc": "^0.3.2",
"@apollo/client": "^3.10.1",
"ora": "5.3.0"
"tslib": "^2.3.0",
"yargs": "^17.7.2"
},
"type": "commonjs",
"main": "./src/main.js",
Expand Down
10 changes: 9 additions & 1 deletion apps/cli/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
"outputPath": "dist/apps/cli",
"main": "apps/cli/src/main.ts",
"tsConfig": "apps/cli/tsconfig.lib.json",
"assets": ["apps/cli/*.md"],
"assets": [
"apps/cli/*.md",
{
"glob": "sea-config.json",
"input": "apps/cli",
"output": "/",
"ignore": []
}
],
"external": "none"
}
},
Expand Down
5 changes: 5 additions & 0 deletions apps/cli/sea-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"main": "sea.cjs",
"output": "sea-prep.blob",
"disableExperimentalSEAWarning": true
}
43 changes: 35 additions & 8 deletions apps/cli/src/lib/ensure-version.ts
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) => {
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);
Expand Down
Loading

0 comments on commit 541447e

Please sign in to comment.