mirror of
https://github.com/sleepypikachu/actions-branch-to-docker-tag-name.git
synced 2024-11-23 11:03:51 +08:00
Support documented rules
This commit is contained in:
parent
aeb2155209
commit
55b310744e
35
index.js
35
index.js
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user