Merge branch 'master' into send-tracking-to-analytics-backend

This commit is contained in:
Otávio Jacobi 2022-10-18 08:15:33 -03:00 committed by GitHub
commit 4a5d44a0f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 810 additions and 100 deletions

View File

@ -1,3 +1,59 @@
- commits:
- subject: Update simple-git to 3.14.1
hash: 70330759007bfdba81986e6c7db1f5c2cb0d7d5f
body: ""
footer:
Change-type: patch
change-type: patch
Signed-off-by: Thodoris Greasidis <thodoris@balena.io>
signed-off-by: Thodoris Greasidis <thodoris@balena.io>
author: Thodoris Greasidis
nested: []
version: 14.4.4
title: "'Update simple git'"
date: 2022-10-18T10:00:35.080Z
- commits:
- subject: "config generate: Fix the incompatible arch errors showing as not found"
hash: 2e115968d5dce98fe05ab0607e1c04bd9f4c67c8
body: ""
footer:
Change-type: patch
change-type: patch
Signed-off-by: Thodoris Greasidis <thodoris@balena.io>
signed-off-by: Thodoris Greasidis <thodoris@balena.io>
author: Thodoris Greasidis
nested: []
version: 14.4.3
title: "'config generate: Fix the incompatible arch errors showing as not found'"
date: 2022-10-17T20:46:59.653Z
- commits:
- subject: Stop relying on device-type.json for resolving the device type aliases
hash: a20d2a04a86797d77819c63e556d8ec7d4c128ca
body: ""
footer:
Resolves: "#2541"
resolves: "#2541"
Change-type: patch
change-type: patch
Signed-off-by: Thodoris Greasidis <thodoris@balena.io>
signed-off-by: Thodoris Greasidis <thodoris@balena.io>
author: Thodoris Greasidis
nested: []
- subject: Stop relying on device-type.json for resolving the cpu architecture
hash: 57b0dccc7d12197dc78c2b8fd4f3cdb6329ec510
body: ""
footer:
Resolves: "#2542"
resolves: "#2542"
Change-type: patch
change-type: patch
Signed-off-by: Thodoris Greasidis <thodoris@balena.io>
signed-off-by: Thodoris Greasidis <thodoris@balena.io>
author: Thodoris Greasidis
nested: []
version: 14.4.2
title: "'Stop relying on device-type.json for resolving the cpu architecture'"
date: 2022-10-17T16:15:07.388Z
- commits:
- subject: "balena os initialize: Clarify that the process includes flashing"
hash: e46902e6839eeb2f59f445aeef94500bd34b8c14

View File

@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).
## 14.4.4 - 2022-10-18
* Update simple-git to 3.14.1 [Thodoris Greasidis]
## 14.4.3 - 2022-10-17
* config generate: Fix the incompatible arch errors showing as not found [Thodoris Greasidis]
## 14.4.2 - 2022-10-17
* Stop relying on device-type.json for resolving the device type aliases [Thodoris Greasidis]
* Stop relying on device-type.json for resolving the cpu architecture [Thodoris Greasidis]
## 14.4.1 - 2022-10-12
* balena os initialize: Clarify that the process includes flashing [Heath Raftery]

View File

@ -15,11 +15,12 @@
* limitations under the License.
*/
const stripIndent = require('common-tags/lib/stripIndent');
const _ = require('lodash');
const { promises: fs } = require('fs');
const path = require('path');
const simplegit = require('simple-git/promise');
// tslint:disable-next-line:import-blacklist
import { stripIndent } from 'common-tags';
import * as _ from 'lodash';
import { promises as fs } from 'fs';
import * as path from 'path';
import { simpleGit } from 'simple-git';
const ROOT = path.normalize(path.join(__dirname, '..'));
@ -31,7 +32,7 @@ const ROOT = path.normalize(path.join(__dirname, '..'));
* using `touch`.
*/
async function checkBuildTimestamps() {
const git = simplegit(ROOT);
const git = simpleGit(ROOT);
const docFile = path.join(ROOT, 'docs', 'balena-cli.md');
const [docStat, gitStatus] = await Promise.all([
fs.stat(docFile),
@ -81,4 +82,5 @@ async function run() {
}
}
// tslint:disable-next-line:no-floating-promises
run();

View File

@ -175,26 +175,26 @@ export default class ConfigGenerateCmd extends Command {
const deviceType = options.deviceType || resourceDeviceType;
const deviceManifest = await balena.models.device.getManifestBySlug(
deviceType,
);
// Check compatibility if application and deviceType provided
if (options.fleet && options.deviceType) {
const appDeviceManifest = await balena.models.device.getManifestBySlug(
resourceDeviceType,
);
const helpers = await import('../../utils/helpers');
if (
!helpers.areDeviceTypesCompatible(appDeviceManifest, deviceManifest)
!(await helpers.areDeviceTypesCompatible(
resourceDeviceType,
deviceType,
))
) {
throw new balena.errors.BalenaInvalidDeviceType(
const { ExpectedError } = await import('../../errors');
throw new ExpectedError(
`Device type ${options.deviceType} is incompatible with fleet ${options.fleet}`,
);
}
}
const deviceManifest = await balena.models.device.getManifestBySlug(
deviceType,
);
// Prompt for values
// Pass params as an override: if there is any param with exactly the same name as a
// required option, that value is used (and the corresponding question is not asked)

View File

@ -15,6 +15,7 @@
* limitations under the License.
*/
import { flags } from '@oclif/command';
import type * as BalenaSdk from 'balena-sdk';
import * as _ from 'lodash';
import Command from '../../command';
@ -59,36 +60,38 @@ export default class DevicesSupportedCmd extends Command {
public async run() {
const { flags: options } = this.parse<FlagsDef, {}>(DevicesSupportedCmd);
const [dts, configDTs] = await Promise.all([
getBalenaSdk().models.deviceType.getAllSupported({
$expand: { is_of__cpu_architecture: { $select: 'slug' } },
$select: ['slug', 'name'],
}),
getBalenaSdk().models.config.getDeviceTypes(),
]);
const dtsBySlug = _.keyBy(dts, (dt) => dt.slug);
const configDTsBySlug = _.keyBy(configDTs, (dt) => dt.slug);
const pineOptions = {
$select: (['slug', 'name'] as const).slice(),
$expand: {
is_of__cpu_architecture: { $select: 'slug' },
device_type_alias: {
$select: 'is_referenced_by__alias',
$orderby: 'is_referenced_by__alias asc',
},
},
} as const;
const dts = (await getBalenaSdk().models.deviceType.getAllSupported(
pineOptions,
)) as Array<
BalenaSdk.PineTypedResult<BalenaSdk.DeviceType, typeof pineOptions>
>;
interface DT {
slug: string;
aliases: string[];
arch: string;
name: string;
}
let deviceTypes: DT[] = [];
for (const slug of Object.keys(dtsBySlug)) {
const configDT: Partial<typeof configDTs[0]> =
configDTsBySlug[slug] || {};
const aliases = (configDT.aliases || []).filter(
(alias) => alias !== slug,
);
const dt: Partial<typeof dts[0]> = dtsBySlug[slug] || {};
deviceTypes.push({
slug,
let deviceTypes = dts.map((dt): DT => {
const aliases = dt.device_type_alias
.map((dta) => dta.is_referenced_by__alias)
.filter((alias) => alias !== dt.slug);
return {
slug: dt.slug,
aliases: options.json ? aliases : [aliases.join(', ')],
arch: (dt.is_of__cpu_architecture as any)?.[0]?.slug || 'n/a',
arch: dt.is_of__cpu_architecture[0]?.slug || 'n/a',
name: dt.name || 'N/A',
});
}
};
});
const fields = ['slug', 'aliases', 'arch', 'name'];
deviceTypes = _.sortBy(deviceTypes, fields);
if (options.json) {

View File

@ -215,7 +215,7 @@ export default class OsConfigureCmd extends Command {
is_for__device_type: { $select: 'slug' },
},
})) as ApplicationWithDeviceType;
await checkDeviceTypeCompatibility(balena, options, app);
await checkDeviceTypeCompatibility(options, app);
deviceTypeSlug =
options['device-type'] || app.is_for__device_type[0].slug;
}
@ -361,17 +361,17 @@ async function getOsVersionFromImage(
* @param app Balena SDK Application model object
*/
async function checkDeviceTypeCompatibility(
sdk: BalenaSdk.BalenaSDK,
options: FlagsDef,
app: ApplicationWithDeviceType,
) {
if (options['device-type']) {
const [appDeviceType, optionDeviceType] = await Promise.all([
sdk.models.device.getManifestBySlug(app.is_for__device_type[0].slug),
sdk.models.device.getManifestBySlug(options['device-type']),
]);
const helpers = await import('../../utils/helpers');
if (!helpers.areDeviceTypesCompatible(appDeviceType, optionDeviceType)) {
if (
!(await helpers.areDeviceTypesCompatible(
app.is_for__device_type[0].slug,
options['device-type'],
))
) {
throw new ExpectedError(
`Device type ${options['device-type']} is incompatible with fleet ${options.fleet}`,
);

View File

@ -107,16 +107,6 @@ export const getDeviceAndMaybeAppFromUUID = _.memoize(
(_sdk, deviceUUID) => deviceUUID,
);
/** Given a device type alias like 'nuc', return the actual slug like 'intel-nuc'. */
export const unaliasDeviceType = _.memoize(async function (
sdk: SDK.BalenaSDK,
deviceType: string,
): Promise<string> {
return (
(await sdk.models.device.getManifestBySlug(deviceType)).slug || deviceType
);
});
/**
* Download balenaOS image for the specified `deviceType`.
* `OSVersion` may be one of:
@ -255,8 +245,8 @@ export async function getOsVersions(
);
// if slug is an alias, fetch the real slug
if (!versions.length) {
// unaliasDeviceType() produces a nice error msg if slug is invalid
slug = await unaliasDeviceType(sdk, slug);
// unalias device type slug
slug = (await sdk.models.deviceType.get(slug, { $select: 'slug' })).slug;
if (slug !== deviceType) {
versions = await sdk.models.os.getAvailableOsVersions(slug);
}

View File

@ -114,14 +114,35 @@ export async function getManifest(
return getBalenaSdk().models.device.getManifestBySlug(deviceType);
}
export const areDeviceTypesCompatible = (
appDeviceType: BalenaSdk.DeviceTypeJson.DeviceType,
osDeviceType: BalenaSdk.DeviceTypeJson.DeviceType,
) =>
getBalenaSdk().models.os.isArchitectureCompatibleWith(
osDeviceType.arch,
appDeviceType.arch,
) && !!appDeviceType.isDependent === !!osDeviceType.isDependent;
export const areDeviceTypesCompatible = async (
appDeviceTypeSlug: string,
osDeviceTypeSlug: string,
) => {
if (appDeviceTypeSlug === osDeviceTypeSlug) {
return true;
}
const sdk = getBalenaSdk();
const pineOptions = {
$select: 'is_of__cpu_architecture',
$expand: {
is_of__cpu_architecture: {
$select: 'slug',
},
},
} as const;
const [appDeviceType, osDeviceType] = await Promise.all(
[appDeviceTypeSlug, osDeviceTypeSlug].map(
(dtSlug) =>
sdk.models.deviceType.get(dtSlug, pineOptions) as Promise<
BalenaSdk.PineTypedResult<BalenaSdk.DeviceType, typeof pineOptions>
>,
),
);
return sdk.models.os.isArchitectureCompatibleWith(
osDeviceType.is_of__cpu_architecture[0].slug,
appDeviceType.is_of__cpu_architecture[0].slug,
);
};
export async function osProgressHandler(step: InitializeEmitter) {
step.on('stdout', process.stdout.write.bind(process.stdout));

View File

@ -198,31 +198,37 @@ async function selectAppFromList(
async function getOrSelectApplication(
sdk: BalenaSdk.BalenaSDK,
deviceType: string,
deviceTypeSlug: string,
appName?: string,
): Promise<ApplicationWithDeviceType> {
const _ = await import('lodash');
const pineOptions = {
$select: 'slug',
$expand: {
is_of__cpu_architecture: {
$select: 'slug',
},
},
} as const;
const [deviceType, allDeviceTypes] = await Promise.all([
sdk.models.deviceType.get(deviceTypeSlug, pineOptions) as Promise<
BalenaSdk.PineTypedResult<BalenaSdk.DeviceType, typeof pineOptions>
>,
sdk.models.deviceType.getAllSupported(pineOptions) as Promise<
Array<BalenaSdk.PineTypedResult<BalenaSdk.DeviceType, typeof pineOptions>>
>,
]);
const allDeviceTypes = await sdk.models.config.getDeviceTypes();
const deviceTypeManifest = _.find(allDeviceTypes, { slug: deviceType });
if (!deviceTypeManifest) {
throw new ExpectedError(`"${deviceType}" is not a valid device type`);
}
const compatibleDeviceTypes = _(allDeviceTypes)
.filter(
(dt) =>
sdk.models.os.isArchitectureCompatibleWith(
deviceTypeManifest.arch,
dt.arch,
) &&
!!dt.isDependent === !!deviceTypeManifest.isDependent &&
dt.state !== 'DISCONTINUED',
const compatibleDeviceTypes = allDeviceTypes
.filter((dt) =>
sdk.models.os.isArchitectureCompatibleWith(
deviceType.is_of__cpu_architecture[0].slug,
dt.is_of__cpu_architecture[0].slug,
),
)
.map((type) => type.slug)
.value();
.map((type) => type.slug);
if (!appName) {
return createOrSelectApp(sdk, compatibleDeviceTypes, deviceType);
return createOrSelectApp(sdk, compatibleDeviceTypes, deviceTypeSlug);
}
const options: BalenaSdk.PineOptions<BalenaSdk.Application> = {
@ -257,13 +263,13 @@ async function getOrSelectApplication(
undefined,
true,
);
return await createApplication(sdk, deviceType, name);
return await createApplication(sdk, deviceTypeSlug, name);
}
// We've found at least one fleet with the given name.
// Filter out fleets for non-matching device types and see what we're left with.
const validApplications = applications.filter((app) =>
_.includes(compatibleDeviceTypes, app.is_for__device_type[0].slug),
compatibleDeviceTypes.includes(app.is_for__device_type[0].slug),
);
if (validApplications.length === 0) {

16
npm-shrinkwrap.json generated
View File

@ -1,6 +1,6 @@
{
"name": "balena-cli",
"version": "14.4.1",
"version": "14.4.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -15164,20 +15164,20 @@
}
},
"simple-git": {
"version": "2.48.0",
"resolved": "https://registry.npmjs.org/simple-git/-/simple-git-2.48.0.tgz",
"integrity": "sha512-z4qtrRuaAFJS4PUd0g+xy7aN4y+RvEt/QTJpR184lhJguBA1S/LsVlvE/CM95RsYMOFJG3NGGDjqFCzKU19S/A==",
"version": "3.14.1",
"resolved": "https://registry.npmjs.org/simple-git/-/simple-git-3.14.1.tgz",
"integrity": "sha512-1ThF4PamK9wBORVGMK9HK5si4zoGS2GpRO7tkAFObA4FZv6dKaCVHLQT+8zlgiBm6K2h+wEU9yOaFCu/SR3OyA==",
"dev": true,
"requires": {
"@kwsites/file-exists": "^1.1.1",
"@kwsites/promise-deferred": "^1.1.1",
"debug": "^4.3.2"
"debug": "^4.3.4"
},
"dependencies": {
"debug": {
"version": "4.3.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz",
"integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==",
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dev": true,
"requires": {
"ms": "2.1.2"

View File

@ -1,6 +1,6 @@
{
"name": "balena-cli",
"version": "14.4.1",
"version": "14.4.4",
"description": "The official balena Command Line Interface",
"main": "./build/app.js",
"homepage": "https://github.com/balena-io/balena-cli",
@ -95,7 +95,7 @@
},
"husky": {
"hooks": {
"pre-commit": "node automation/check-npm-version.js && node automation/check-doc.js"
"pre-commit": "node automation/check-npm-version.js && ts-node automation/check-doc.ts"
}
},
"oclif": {
@ -188,7 +188,7 @@
"pkg": "^5.5.1",
"publish-release": "^1.6.1",
"rewire": "^5.0.0",
"simple-git": "^2.48.0",
"simple-git": "^3.14.1",
"sinon": "^11.1.2",
"ts-node": "^10.4.0",
"typescript": "^4.6.4"
@ -285,6 +285,6 @@
"windosu": "^0.3.0"
},
"versionist": {
"publishedAt": "2022-10-12T13:55:51.707Z"
"publishedAt": "2022-10-18T10:00:36.262Z"
}
}

View File

@ -44,7 +44,6 @@ describe('balena devices supported', function () {
it('should list currently supported devices, with correct filtering', async () => {
api.expectGetDeviceTypes();
api.expectGetConfigDeviceTypes();
const { out, err } = await runCommand('devices supported');
@ -54,7 +53,7 @@ describe('balena devices supported', function () {
expect(lines).to.have.lengthOf.at.least(2);
expect(lines).to.contain('intel-nuc nuc amd64 Intel NUC');
expect(lines).to.contain(
'odroid-xu4 odroid-ux3, odroid-u3+ armv7hf ODROID-XU4',
'odroid-xu4 odroid-u3+, odroid-ux3 armv7hf ODROID-XU4',
);
expect(err).to.eql([]);
});

File diff suppressed because it is too large Load Diff