Support documented rules

This commit is contained in:
Elliot Iddon 2022-09-03 17:06:07 +01:00
parent aeb2155209
commit 55b310744e

View File

@ -1,23 +1,40 @@
const core = require('@actions/core');
/**
https://docs.docker.com/engine/reference/commandline/tag/#description
Name components may contain lowercase letters, digits and separators.
A separator is defined as a period, one or two underscores, or one or
more dashes. A name component may not start or end with a separator.
**/
try {
const path = core.getInput('path');
const prefix = core.getInput('prefix')
let result = path
const prefix = core.getInput('prefix');
let result = path;
// Remove prefix
if (path.startsWith(prefix)) {
result = result.substr(prefix.length)
result = result.substr(prefix.length);
}
// Replace '/'
result = result.replaceAll('/', '-')
// Remove start
result = result.replace(/^\./, '');
// Replace '/' (we expect lots of / in paths)
result = result.replaceAll('/', '-');
// Remove start and end path characters
result = result.replace(/^\./, '')
result = result.replace(/^-/, '')
result = result.replace(/-$/, '')
// Replace excessive underscores
result = result.replaceAll(/___+/, '__');
// Lower case
result = result.toLowerCase();
// Remove invalid characters
result = result.replaceAll(/[^a-z0-9\._-]/, '')
// Remove start and end seperators
result = result.replace(/^[-\._]+/, '')
result = result.replace(/[-\._]+$/, '')
core.setOutput('image-name', result);