Skip to content

Commit

Permalink
Merge pull request #366 from devcontainers/samruddhikhandale/legacyId…
Browse files Browse the repository at this point in the history
…s-info

Features preamble: Add warnings for Feature renames & deprecation
  • Loading branch information
samruddhikhandale committed Jan 5, 2023
2 parents 3680e54 + 36325b6 commit d1c0dac
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/spec-configuration/containerFeaturesConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ export function getFeatureInstallWrapperScript(feature: Feature, featureSet: Fea
const documentation = escapeQuotesForShell(feature.documentationURL ?? '');
const optionsIndented = escapeQuotesForShell(options.map(x => ` ${x}`).join('\n'));

let warningHeader = '';
if (feature.deprecated) {
warningHeader += `(!) WARNING: Using the deprecated Feature "${escapeQuotesForShell(feature.id)}". This Feature will no longer receive any further updates/support.\n`;
}

if (feature?.legacyIds && feature.legacyIds.length > 0 && feature.currentId && feature.id !== feature.currentId) {
warningHeader += `(!) WARNING: This feature has been renamed. Please update the reference in devcontainer.json to "${escapeQuotesForShell(feature.currentId)}".`;
}

const echoWarning = warningHeader ? `echo '${warningHeader}'` : '';
const errorMessage = `ERROR: Feature "${name}" (${id}) failed to install!`;
const troubleshootingMessage = documentation
? ` Look at the documentation at ${documentation} for help troubleshooting this error.`
Expand All @@ -272,6 +282,7 @@ on_exit () {
trap on_exit EXIT
echo ===========================================================================
${echoWarning}
echo 'Feature : ${name}'
echo 'Description : ${description}'
echo 'Id : ${id}'
Expand Down
169 changes: 169 additions & 0 deletions src/test/container-features/featureHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ on_exit () {
trap on_exit EXIT
echo ===========================================================================
echo 'Feature : Unknown'
echo 'Description : '
echo 'Id : ./test'
Expand Down Expand Up @@ -560,6 +561,7 @@ on_exit () {
trap on_exit EXIT
echo ===========================================================================
echo 'Feature : My Test Feature'
echo 'Description : This is an awesome feature (with ""quotes" for '\\''escaping'\\'' test)'
echo 'Id : ghcr.io/my-org/my-repo/test'
Expand All @@ -575,6 +577,173 @@ set -a
. ./devcontainer-features.env
set +a
chmod +x ./install.sh
./install.sh
`;

const actual = getFeatureInstallWrapperScript(feature, set, options);
assert.equal(actual, expected);
});

it('returns a valid script with warnings for deprecated Features', () => {
const feature: Feature = {
id: 'test',
value: {
version: 'latest',
otherOption: true
},
included: true,
name: 'My Test Feature',
description: 'This is an awesome feature (with ""quotes" for \'escaping\' test)',
version: '1.2.3',
documentationURL: 'https://my-test-feature.localhost',
deprecated: true,
};
const set: FeatureSet = {
features: [feature],
sourceInformation: {
type: 'oci',
userFeatureId: 'ghcr.io/my-org/my-repo/test:1',
userFeatureIdWithoutVersion: 'ghcr.io/my-org/my-repo/test',
featureRef: {
registry: 'ghcr.io',
owner: 'my-org',
namespace: 'my-org/my-repo',
path: 'my-org/my-repo/test',
resource: 'ghcr.io/my-org/my-repo/test',
id: 'test',
version: '1.2.3',
},
manifest: {
schemaVersion: 1,
mediaType: '',
config: {
digest: '',
mediaType: '',
size: 0,
},
layers: [],
}
}
};
const options = [
'VERSION=latest',
'OTHEROPTION=true',
];

const expected =
`#!/bin/sh
set -e
on_exit () {
[ $? -eq 0 ] && exit
echo 'ERROR: Feature "My Test Feature" (ghcr.io/my-org/my-repo/test) failed to install! Look at the documentation at https://my-test-feature.localhost for help troubleshooting this error.'
}
trap on_exit EXIT
echo ===========================================================================
echo '(!) WARNING: Using the deprecated Feature "test". This Feature will no longer receive any further updates/support.\n'
echo 'Feature : My Test Feature'
echo 'Description : This is an awesome feature (with ""quotes" for '\\''escaping'\\'' test)'
echo 'Id : ghcr.io/my-org/my-repo/test'
echo 'Version : 1.2.3'
echo 'Documentation : https://my-test-feature.localhost'
echo 'Options :'
echo ' VERSION=latest
OTHEROPTION=true'
echo ===========================================================================
set -a
. ../devcontainer-features.builtin.env
. ./devcontainer-features.env
set +a
chmod +x ./install.sh
./install.sh
`;

const actual = getFeatureInstallWrapperScript(feature, set, options);
assert.equal(actual, expected);
});

it('returns a valid script with warnings for renamed Features', () => {
const feature: Feature = {
id: 'test',
value: {
version: 'latest',
otherOption: true
},
included: true,
name: 'My New Test Feature',
description: 'This is an awesome feature (with ""quotes" for \'escaping\' test)',
version: '1.2.3',
documentationURL: 'https://my-new-test-feature.localhost',
legacyIds: [
'test'
],
currentId: 'ghcr.io/my-org/my-repo/new-test'
};
const set: FeatureSet = {
features: [feature],
sourceInformation: {
type: 'oci',
userFeatureId: 'ghcr.io/my-org/my-repo/test:1',
userFeatureIdWithoutVersion: 'ghcr.io/my-org/my-repo/test',
featureRef: {
registry: 'ghcr.io',
owner: 'my-org',
namespace: 'my-org/my-repo',
path: 'my-org/my-repo/test',
resource: 'ghcr.io/my-org/my-repo/test',
id: 'test',
version: '1.2.3',
},
manifest: {
schemaVersion: 1,
mediaType: '',
config: {
digest: '',
mediaType: '',
size: 0,
},
layers: [],
}
}
};
const options = [
'VERSION=latest',
'OTHEROPTION=true',
];

const expected =
`#!/bin/sh
set -e
on_exit () {
[ $? -eq 0 ] && exit
echo 'ERROR: Feature "My New Test Feature" (ghcr.io/my-org/my-repo/test) failed to install! Look at the documentation at https://my-new-test-feature.localhost for help troubleshooting this error.'
}
trap on_exit EXIT
echo ===========================================================================
echo '(!) WARNING: This feature has been renamed. Please update the reference in devcontainer.json to "ghcr.io/my-org/my-repo/new-test".'
echo 'Feature : My New Test Feature'
echo 'Description : This is an awesome feature (with ""quotes" for '\\''escaping'\\'' test)'
echo 'Id : ghcr.io/my-org/my-repo/test'
echo 'Version : 1.2.3'
echo 'Documentation : https://my-new-test-feature.localhost'
echo 'Options :'
echo ' VERSION=latest
OTHEROPTION=true'
echo ===========================================================================
set -a
. ../devcontainer-features.builtin.env
. ./devcontainer-features.env
set +a
chmod +x ./install.sh
./install.sh
`;
Expand Down

0 comments on commit d1c0dac

Please sign in to comment.