-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cloud/linting): verify template compatibility
Clean up linting and add a new rule for element template compatibility.
- Loading branch information
1 parent
f9b46bc
commit eec50e9
Showing
5 changed files
with
277 additions
and
43 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 |
---|---|---|
@@ -1,4 +1,29 @@ | ||
export { | ||
elementTemplateLintRule, | ||
ElementTemplateLinterPlugin | ||
} from './LinterPlugin'; | ||
/** | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. | ||
* | ||
* Camunda licenses this file to you under the MIT; you may not use this file | ||
* except in compliance with the MIT License. | ||
*/ | ||
|
||
import StaticResolver from 'bpmnlint/lib/resolver/static-resolver'; | ||
|
||
import validate from './rules/element-templates-validate'; | ||
import compatibility from './rules/element-templates-compatibility'; | ||
|
||
export const ElementTemplateLinterPlugin = function(templates) { | ||
return { | ||
config: { | ||
rules: { | ||
'element-templates/validate': [ 'error', { templates } ], | ||
'element-templates/compatibility': [ 'warn', { templates } ] | ||
} | ||
}, | ||
resolver: new StaticResolver({ | ||
'rule:bpmnlint-plugin-element-templates/validate': validate, | ||
'rule:bpmnlint-plugin-element-templates/compatibility': compatibility | ||
}) | ||
}; | ||
}; |
115 changes: 115 additions & 0 deletions
115
src/cloud-element-templates/linting/rules/element-templates-compatibility.js
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,115 @@ | ||
/** | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. | ||
* | ||
* Camunda licenses this file to you under the MIT; you may not use this file | ||
* except in compliance with the MIT License. | ||
*/ | ||
|
||
import ElementTemplates from '../../ElementTemplates'; | ||
import EventBus from 'diagram-js/lib/core/EventBus'; | ||
|
||
import BpmnModdle from 'bpmn-moddle'; | ||
import { is } from 'bpmn-js/lib/util/ModelUtil'; | ||
|
||
import zeebeModdle from 'zeebe-bpmn-moddle/resources/zeebe'; | ||
|
||
import { Validator } from '../../Validator'; | ||
|
||
export default function({ templates = [] }) { | ||
const moddle = new BpmnModdle({ zeebe: zeebeModdle }); | ||
|
||
const validator = new Validator(moddle).addAll(templates); | ||
const validTemplates = validator.getValidTemplates(); | ||
|
||
// We use the ElementTemplates Module without the required bpmn-js modules | ||
// As we only use it to facilitate template ID and version lookup, | ||
// access to commandstack etc. is not required | ||
const eventBus = new EventBus(); | ||
const elementTemplates = new ElementTemplates(null, null, eventBus, null, null); | ||
|
||
elementTemplates.set(validTemplates); | ||
|
||
function isUpdateAvailable(template) { | ||
|
||
const latestTemplate = elementTemplates.getLatest(template.id, { deprecated: true })[0]; | ||
|
||
if (latestTemplate && latestTemplate !== template) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
function check(node, reporter) { | ||
|
||
if (is(node, 'bpmn:Definitions')) { | ||
elementTemplates.setEngines(getEnginesConfig(node)); | ||
} | ||
|
||
if (!is(node, 'bpmn:FlowElement')) { | ||
return; | ||
} | ||
|
||
let template = elementTemplates.get(node); | ||
|
||
if (!template) { | ||
return; | ||
} | ||
|
||
// Check compatibility | ||
if (template.engines) { | ||
const incomp = elementTemplates.getIncompatibleEngines(template); | ||
Object.keys(incomp).forEach((engine) => { | ||
reporter.report( | ||
node.id, | ||
getIncompatibilityText(engine, incomp[engine], isUpdateAvailable(template)), | ||
{ | ||
name: node.name | ||
} | ||
); | ||
}); | ||
} | ||
} | ||
|
||
return { | ||
check | ||
}; | ||
|
||
}; | ||
|
||
// helpers ////////////////////// | ||
|
||
function getEnginesConfig(definitions) { | ||
const { | ||
exporter, | ||
exporterVersion | ||
} = definitions; | ||
|
||
const engines = {}; | ||
|
||
const executionPlatform = definitions.get('modeler:executionPlatform'); | ||
const executionPlatformVersion = definitions.get('modeler:executionPlatformVersion'); | ||
|
||
if (executionPlatform === 'Camunda Cloud' && executionPlatformVersion) { | ||
engines.camunda = executionPlatformVersion; | ||
} | ||
|
||
if (exporter === 'Camunda Modeler' && exporterVersion) { | ||
engines.camundaDesktopModeler = exporterVersion; | ||
} | ||
|
||
return engines; | ||
} | ||
|
||
|
||
function getIncompatibilityText(engine, { actual, required }, updateAvailable) { | ||
const message = | ||
`Element template incompatible with current <${engine}> environment. ` + | ||
`Requires '${engine} ${required}'; found '${actual}'. ` + | ||
`${updateAvailable ? 'Update available.' : ''}`; | ||
|
||
return message.trim(); | ||
} |
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
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
Oops, something went wrong.