mirror of
https://github.com/docker/build-push-action.git
synced 2024-12-24 07:42:14 -05:00
Check context type
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
10b9d7ec22
commit
9c473659de
6 changed files with 835 additions and 4 deletions
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
|
@ -81,8 +81,11 @@ jobs:
|
|||
-
|
||||
name: Build and push
|
||||
uses: ./
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
GITHUB_REF: ${{ github.ref }}
|
||||
with:
|
||||
context: "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}#${{ github.ref }}"
|
||||
context: ${{ github.repositoryUrl }}
|
||||
file: ./test/Dockerfile
|
||||
builder: ${{ steps.buildx.outputs.name }}
|
||||
platforms: linux/amd64,linux/arm64,linux/386
|
||||
|
|
|
@ -6,6 +6,7 @@ ___
|
|||
|
||||
* [Usage](#usage)
|
||||
* [Quick start](#quick-start)
|
||||
* [Bake](#bake)
|
||||
* [Customizing](#customizing)
|
||||
* [inputs](#inputs)
|
||||
* [outputs](#outputs)
|
||||
|
|
756
dist/index.js
generated
vendored
756
dist/index.js
generated
vendored
|
@ -951,6 +951,213 @@ class ExecState extends events.EventEmitter {
|
|||
}
|
||||
//# sourceMappingURL=toolrunner.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 45:
|
||||
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
// Dependencies
|
||||
|
||||
var parseUrl = __webpack_require__(823),
|
||||
isSsh = __webpack_require__(720);
|
||||
|
||||
/**
|
||||
* gitUp
|
||||
* Parses the input url.
|
||||
*
|
||||
* @name gitUp
|
||||
* @function
|
||||
* @param {String} input The input url.
|
||||
* @return {Object} An object containing the following fields:
|
||||
*
|
||||
* - `protocols` (Array): An array with the url protocols (usually it has one element).
|
||||
* - `port` (null|Number): The domain port.
|
||||
* - `resource` (String): The url domain (including subdomains).
|
||||
* - `user` (String): The authentication user (usually for ssh urls).
|
||||
* - `pathname` (String): The url pathname.
|
||||
* - `hash` (String): The url hash.
|
||||
* - `search` (String): The url querystring value.
|
||||
* - `href` (String): The input url.
|
||||
* - `protocol` (String): The git url protocol.
|
||||
* - `token` (String): The oauth token (could appear in the https urls).
|
||||
*/
|
||||
function gitUp(input) {
|
||||
var output = parseUrl(input);
|
||||
output.token = "";
|
||||
|
||||
var splits = output.user.split(":");
|
||||
if (splits.length === 2) {
|
||||
if (splits[1] === "x-oauth-basic") {
|
||||
output.token = splits[0];
|
||||
} else if (splits[0] === "x-token-auth") {
|
||||
output.token = splits[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (isSsh(output.protocols) || isSsh(input)) {
|
||||
output.protocol = "ssh";
|
||||
} else if (output.protocols.length) {
|
||||
output.protocol = output.protocols[0];
|
||||
} else {
|
||||
output.protocol = "file";
|
||||
}
|
||||
|
||||
output.href = output.href.replace(/\/$/, "");
|
||||
return output;
|
||||
}
|
||||
|
||||
module.exports = gitUp;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 53:
|
||||
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
// TODO: Use the `URL` global when targeting Node.js 10
|
||||
const URLParser = typeof URL === 'undefined' ? __webpack_require__(835).URL : URL;
|
||||
|
||||
const testParameter = (name, filters) => {
|
||||
return filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name);
|
||||
};
|
||||
|
||||
module.exports = (urlString, opts) => {
|
||||
opts = Object.assign({
|
||||
defaultProtocol: 'http:',
|
||||
normalizeProtocol: true,
|
||||
forceHttp: false,
|
||||
forceHttps: false,
|
||||
stripHash: true,
|
||||
stripWWW: true,
|
||||
removeQueryParameters: [/^utm_\w+/i],
|
||||
removeTrailingSlash: true,
|
||||
removeDirectoryIndex: false,
|
||||
sortQueryParameters: true
|
||||
}, opts);
|
||||
|
||||
// Backwards compatibility
|
||||
if (Reflect.has(opts, 'normalizeHttps')) {
|
||||
opts.forceHttp = opts.normalizeHttps;
|
||||
}
|
||||
|
||||
if (Reflect.has(opts, 'normalizeHttp')) {
|
||||
opts.forceHttps = opts.normalizeHttp;
|
||||
}
|
||||
|
||||
if (Reflect.has(opts, 'stripFragment')) {
|
||||
opts.stripHash = opts.stripFragment;
|
||||
}
|
||||
|
||||
urlString = urlString.trim();
|
||||
|
||||
const hasRelativeProtocol = urlString.startsWith('//');
|
||||
const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
|
||||
|
||||
// Prepend protocol
|
||||
if (!isRelativeUrl) {
|
||||
urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, opts.defaultProtocol);
|
||||
}
|
||||
|
||||
const urlObj = new URLParser(urlString);
|
||||
|
||||
if (opts.forceHttp && opts.forceHttps) {
|
||||
throw new Error('The `forceHttp` and `forceHttps` options cannot be used together');
|
||||
}
|
||||
|
||||
if (opts.forceHttp && urlObj.protocol === 'https:') {
|
||||
urlObj.protocol = 'http:';
|
||||
}
|
||||
|
||||
if (opts.forceHttps && urlObj.protocol === 'http:') {
|
||||
urlObj.protocol = 'https:';
|
||||
}
|
||||
|
||||
// Remove hash
|
||||
if (opts.stripHash) {
|
||||
urlObj.hash = '';
|
||||
}
|
||||
|
||||
// Remove duplicate slashes if not preceded by a protocol
|
||||
if (urlObj.pathname) {
|
||||
// TODO: Use the following instead when targeting Node.js 10
|
||||
// `urlObj.pathname = urlObj.pathname.replace(/(?<!https?:)\/{2,}/g, '/');`
|
||||
urlObj.pathname = urlObj.pathname.replace(/((?![https?:]).)\/{2,}/g, (_, p1) => {
|
||||
if (/^(?!\/)/g.test(p1)) {
|
||||
return `${p1}/`;
|
||||
}
|
||||
return '/';
|
||||
});
|
||||
}
|
||||
|
||||
// Decode URI octets
|
||||
if (urlObj.pathname) {
|
||||
urlObj.pathname = decodeURI(urlObj.pathname);
|
||||
}
|
||||
|
||||
// Remove directory index
|
||||
if (opts.removeDirectoryIndex === true) {
|
||||
opts.removeDirectoryIndex = [/^index\.[a-z]+$/];
|
||||
}
|
||||
|
||||
if (Array.isArray(opts.removeDirectoryIndex) && opts.removeDirectoryIndex.length > 0) {
|
||||
let pathComponents = urlObj.pathname.split('/');
|
||||
const lastComponent = pathComponents[pathComponents.length - 1];
|
||||
|
||||
if (testParameter(lastComponent, opts.removeDirectoryIndex)) {
|
||||
pathComponents = pathComponents.slice(0, pathComponents.length - 1);
|
||||
urlObj.pathname = pathComponents.slice(1).join('/') + '/';
|
||||
}
|
||||
}
|
||||
|
||||
if (urlObj.hostname) {
|
||||
// Remove trailing dot
|
||||
urlObj.hostname = urlObj.hostname.replace(/\.$/, '');
|
||||
|
||||
// Remove `www.`
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
if (opts.stripWWW && /^www\.([a-z\-\d]{2,63})\.([a-z\.]{2,5})$/.test(urlObj.hostname)) {
|
||||
// Each label should be max 63 at length (min: 2).
|
||||
// The extension should be max 5 at length (min: 2).
|
||||
// Source: https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
|
||||
urlObj.hostname = urlObj.hostname.replace(/^www\./, '');
|
||||
}
|
||||
}
|
||||
|
||||
// Remove query unwanted parameters
|
||||
if (Array.isArray(opts.removeQueryParameters)) {
|
||||
for (const key of [...urlObj.searchParams.keys()]) {
|
||||
if (testParameter(key, opts.removeQueryParameters)) {
|
||||
urlObj.searchParams.delete(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort query parameters
|
||||
if (opts.sortQueryParameters) {
|
||||
urlObj.searchParams.sort();
|
||||
}
|
||||
|
||||
// Take advantage of many of the Node `url` normalizations
|
||||
urlString = urlObj.toString();
|
||||
|
||||
// Remove ending `/`
|
||||
if (opts.removeTrailingSlash || urlObj.pathname === '/') {
|
||||
urlString = urlString.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
// Restore relative protocol, if applicable
|
||||
if (hasRelativeProtocol && !opts.normalizeProtocol) {
|
||||
urlString = urlString.replace(/^http:\/\//, '//');
|
||||
}
|
||||
|
||||
return urlString;
|
||||
};
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 87:
|
||||
|
@ -967,6 +1174,13 @@ module.exports = require("child_process");
|
|||
|
||||
/***/ }),
|
||||
|
||||
/***/ 191:
|
||||
/***/ (function(module) {
|
||||
|
||||
module.exports = require("querystring");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 198:
|
||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||
|
||||
|
@ -1036,6 +1250,240 @@ run();
|
|||
|
||||
/***/ }),
|
||||
|
||||
/***/ 253:
|
||||
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var gitUp = __webpack_require__(45);
|
||||
|
||||
/**
|
||||
* gitUrlParse
|
||||
* Parses a Git url.
|
||||
*
|
||||
* @name gitUrlParse
|
||||
* @function
|
||||
* @param {String} url The Git url to parse.
|
||||
* @return {GitUrl} The `GitUrl` object containing:
|
||||
*
|
||||
* - `protocols` (Array): An array with the url protocols (usually it has one element).
|
||||
* - `port` (null|Number): The domain port.
|
||||
* - `resource` (String): The url domain (including subdomains).
|
||||
* - `user` (String): The authentication user (usually for ssh urls).
|
||||
* - `pathname` (String): The url pathname.
|
||||
* - `hash` (String): The url hash.
|
||||
* - `search` (String): The url querystring value.
|
||||
* - `href` (String): The input url.
|
||||
* - `protocol` (String): The git url protocol.
|
||||
* - `token` (String): The oauth token (could appear in the https urls).
|
||||
* - `source` (String): The Git provider (e.g. `"github.com"`).
|
||||
* - `owner` (String): The repository owner.
|
||||
* - `name` (String): The repository name.
|
||||
* - `ref` (String): The repository ref (e.g., "master" or "dev").
|
||||
* - `filepath` (String): A filepath relative to the repository root.
|
||||
* - `filepathtype` (String): The type of filepath in the url ("blob" or "tree").
|
||||
* - `full_name` (String): The owner and name values in the `owner/name` format.
|
||||
* - `toString` (Function): A function to stringify the parsed url into another url type.
|
||||
* - `organization` (String): The organization the owner belongs to. This is CloudForge specific.
|
||||
* - `git_suffix` (Boolean): Whether to add the `.git` suffix or not.
|
||||
*
|
||||
*/
|
||||
function gitUrlParse(url) {
|
||||
|
||||
if (typeof url !== "string") {
|
||||
throw new Error("The url must be a string.");
|
||||
}
|
||||
|
||||
var urlInfo = gitUp(url),
|
||||
sourceParts = urlInfo.resource.split("."),
|
||||
splits = null;
|
||||
|
||||
urlInfo.toString = function (type) {
|
||||
return gitUrlParse.stringify(this, type);
|
||||
};
|
||||
|
||||
urlInfo.source = sourceParts.length > 2 ? sourceParts.slice(1 - sourceParts.length).join(".") : urlInfo.source = urlInfo.resource;
|
||||
|
||||
// Note: Some hosting services (e.g. Visual Studio Team Services) allow whitespace characters
|
||||
// in the repository and owner names so we decode the URL pieces to get the correct result
|
||||
urlInfo.git_suffix = /\.git$/.test(urlInfo.pathname);
|
||||
urlInfo.name = decodeURIComponent(urlInfo.pathname.replace(/^\//, '').replace(/\.git$/, ""));
|
||||
urlInfo.owner = decodeURIComponent(urlInfo.user);
|
||||
|
||||
switch (urlInfo.source) {
|
||||
case "git.cloudforge.com":
|
||||
urlInfo.owner = urlInfo.user;
|
||||
urlInfo.organization = sourceParts[0];
|
||||
urlInfo.source = "cloudforge.com";
|
||||
break;
|
||||
case "visualstudio.com":
|
||||
// Handle VSTS SSH URLs
|
||||
if (urlInfo.resource === 'vs-ssh.visualstudio.com') {
|
||||
splits = urlInfo.name.split("/");
|
||||
if (splits.length === 4) {
|
||||
urlInfo.organization = splits[1];
|
||||
urlInfo.owner = splits[2];
|
||||
urlInfo.name = splits[3];
|
||||
urlInfo.full_name = splits[2] + '/' + splits[3];
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
splits = urlInfo.name.split("/");
|
||||
if (splits.length === 2) {
|
||||
urlInfo.owner = splits[1];
|
||||
urlInfo.name = splits[1];
|
||||
urlInfo.full_name = '_git/' + urlInfo.name;
|
||||
} else if (splits.length === 3) {
|
||||
urlInfo.name = splits[2];
|
||||
if (splits[0] === 'DefaultCollection') {
|
||||
urlInfo.owner = splits[2];
|
||||
urlInfo.organization = splits[0];
|
||||
urlInfo.full_name = urlInfo.organization + '/_git/' + urlInfo.name;
|
||||
} else {
|
||||
urlInfo.owner = splits[0];
|
||||
urlInfo.full_name = urlInfo.owner + '/_git/' + urlInfo.name;
|
||||
}
|
||||
} else if (splits.length === 4) {
|
||||
urlInfo.organization = splits[0];
|
||||
urlInfo.owner = splits[1];
|
||||
urlInfo.name = splits[3];
|
||||
urlInfo.full_name = urlInfo.organization + '/' + urlInfo.owner + '/_git/' + urlInfo.name;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Azure DevOps (formerly Visual Studio Team Services)
|
||||
case "dev.azure.com":
|
||||
case "azure.com":
|
||||
if (urlInfo.resource === 'ssh.dev.azure.com') {
|
||||
splits = urlInfo.name.split("/");
|
||||
if (splits.length === 4) {
|
||||
urlInfo.organization = splits[1];
|
||||
urlInfo.owner = splits[2];
|
||||
urlInfo.name = splits[3];
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
splits = urlInfo.name.split("/");
|
||||
if (splits.length === 5) {
|
||||
urlInfo.organization = splits[0];
|
||||
urlInfo.owner = splits[1];
|
||||
urlInfo.name = splits[4];
|
||||
urlInfo.full_name = '_git/' + urlInfo.name;
|
||||
} else if (splits.length === 3) {
|
||||
urlInfo.name = splits[2];
|
||||
if (splits[0] === 'DefaultCollection') {
|
||||
urlInfo.owner = splits[2];
|
||||
urlInfo.organization = splits[0];
|
||||
urlInfo.full_name = urlInfo.organization + '/_git/' + urlInfo.name;
|
||||
} else {
|
||||
urlInfo.owner = splits[0];
|
||||
urlInfo.full_name = urlInfo.owner + '/_git/' + urlInfo.name;
|
||||
}
|
||||
} else if (splits.length === 4) {
|
||||
urlInfo.organization = splits[0];
|
||||
urlInfo.owner = splits[1];
|
||||
urlInfo.name = splits[3];
|
||||
urlInfo.full_name = urlInfo.organization + '/' + urlInfo.owner + '/_git/' + urlInfo.name;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
splits = urlInfo.name.split("/");
|
||||
var nameIndex = splits.length - 1;
|
||||
if (splits.length >= 2) {
|
||||
var blobIndex = splits.indexOf("blob", 2);
|
||||
var treeIndex = splits.indexOf("tree", 2);
|
||||
var commitIndex = splits.indexOf("commit", 2);
|
||||
nameIndex = blobIndex > 0 ? blobIndex - 1 : treeIndex > 0 ? treeIndex - 1 : commitIndex > 0 ? commitIndex - 1 : nameIndex;
|
||||
|
||||
urlInfo.owner = splits.slice(0, nameIndex).join('/');
|
||||
urlInfo.name = splits[nameIndex];
|
||||
if (commitIndex) {
|
||||
urlInfo.commit = splits[nameIndex + 2];
|
||||
}
|
||||
}
|
||||
|
||||
urlInfo.ref = "";
|
||||
urlInfo.filepathtype = "";
|
||||
urlInfo.filepath = "";
|
||||
if (splits.length > nameIndex + 2 && ["blob", "tree"].indexOf(splits[nameIndex + 1]) >= 0) {
|
||||
urlInfo.filepathtype = splits[nameIndex + 1];
|
||||
urlInfo.ref = splits[nameIndex + 2];
|
||||
if (splits.length > nameIndex + 3) {
|
||||
urlInfo.filepath = splits.slice(nameIndex + 3).join('/');
|
||||
}
|
||||
}
|
||||
urlInfo.organization = urlInfo.owner;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!urlInfo.full_name) {
|
||||
urlInfo.full_name = urlInfo.owner;
|
||||
if (urlInfo.name) {
|
||||
urlInfo.full_name && (urlInfo.full_name += "/");
|
||||
urlInfo.full_name += urlInfo.name;
|
||||
}
|
||||
}
|
||||
|
||||
return urlInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* stringify
|
||||
* Stringifies a `GitUrl` object.
|
||||
*
|
||||
* @name stringify
|
||||
* @function
|
||||
* @param {GitUrl} obj The parsed Git url object.
|
||||
* @param {String} type The type of the stringified url (default `obj.protocol`).
|
||||
* @return {String} The stringified url.
|
||||
*/
|
||||
gitUrlParse.stringify = function (obj, type) {
|
||||
type = type || (obj.protocols && obj.protocols.length ? obj.protocols.join('+') : obj.protocol);
|
||||
var port = obj.port ? ":" + obj.port : '';
|
||||
var user = obj.user || 'git';
|
||||
var maybeGitSuffix = obj.git_suffix ? ".git" : "";
|
||||
switch (type) {
|
||||
case "ssh":
|
||||
if (port) return "ssh://" + user + "@" + obj.resource + port + "/" + obj.full_name + maybeGitSuffix;else return user + "@" + obj.resource + ":" + obj.full_name + maybeGitSuffix;
|
||||
case "git+ssh":
|
||||
case "ssh+git":
|
||||
case "ftp":
|
||||
case "ftps":
|
||||
return type + "://" + user + "@" + obj.resource + port + "/" + obj.full_name + maybeGitSuffix;
|
||||
case "http":
|
||||
case "https":
|
||||
var auth = obj.token ? buildToken(obj) : obj.user && (obj.protocols.includes('http') || obj.protocols.includes('https')) ? obj.user + "@" : "";
|
||||
return type + "://" + auth + obj.resource + port + "/" + obj.full_name + maybeGitSuffix;
|
||||
default:
|
||||
return obj.href;
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
* buildToken
|
||||
* Builds OAuth token prefix (helper function)
|
||||
*
|
||||
* @name buildToken
|
||||
* @function
|
||||
* @param {GitUrl} obj The parsed Git url object.
|
||||
* @return {String} token prefix
|
||||
*/
|
||||
function buildToken(obj) {
|
||||
switch (obj.source) {
|
||||
case "bitbucket.org":
|
||||
return "x-token-auth:" + obj.token + "@";
|
||||
default:
|
||||
return obj.token + "@";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = gitUrlParse;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 357:
|
||||
/***/ (function(module) {
|
||||
|
||||
|
@ -1404,13 +1852,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getArgs = exports.getInputs = void 0;
|
||||
const git_url_parse_1 = __importDefault(__webpack_require__(253));
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
function getInputs() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return {
|
||||
context: core.getInput('context') || '.',
|
||||
context: yield getBuildContext(),
|
||||
file: core.getInput('file') || './Dockerfile',
|
||||
buildArgs: yield getInputList('build-args'),
|
||||
labels: yield getInputList('labels'),
|
||||
|
@ -1453,6 +1905,23 @@ function getArgs(inputs) {
|
|||
});
|
||||
}
|
||||
exports.getArgs = getArgs;
|
||||
function getBuildContext() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let context = core.getInput('context');
|
||||
if (!context) {
|
||||
return '.';
|
||||
}
|
||||
try {
|
||||
const gitURL = git_url_parse_1.default(context);
|
||||
gitURL.token = gitURL.token || process.env['GIT_TOKEN'] || process.env['GITHUB_TOKEN'] || '';
|
||||
gitURL.ref = gitURL.ref || process.env['GIT_REF'] || process.env['GITHUB_REF'] || '';
|
||||
return gitURL.toString();
|
||||
}
|
||||
catch (_a) {
|
||||
return context;
|
||||
}
|
||||
});
|
||||
}
|
||||
function getCommonArgs(inputs) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let args = [];
|
||||
|
@ -1548,6 +2017,146 @@ module.exports = require("path");
|
|||
|
||||
/***/ }),
|
||||
|
||||
/***/ 666:
|
||||
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
// Dependencies
|
||||
var protocols = __webpack_require__(737),
|
||||
isSsh = __webpack_require__(720),
|
||||
qs = __webpack_require__(191);
|
||||
|
||||
/**
|
||||
* parsePath
|
||||
* Parses the input url.
|
||||
*
|
||||
* @name parsePath
|
||||
* @function
|
||||
* @param {String} url The input url.
|
||||
* @return {Object} An object containing the following fields:
|
||||
*
|
||||
* - `protocols` (Array): An array with the url protocols (usually it has one element).
|
||||
* - `protocol` (String): The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`.
|
||||
* - `port` (null|Number): The domain port.
|
||||
* - `resource` (String): The url domain (including subdomains).
|
||||
* - `user` (String): The authentication user (usually for ssh urls).
|
||||
* - `pathname` (String): The url pathname.
|
||||
* - `hash` (String): The url hash.
|
||||
* - `search` (String): The url querystring value.
|
||||
* - `href` (String): The input url.
|
||||
* - `query` (Object): The url querystring, parsed as object.
|
||||
*/
|
||||
function parsePath(url) {
|
||||
url = (url || "").trim();
|
||||
var output = {
|
||||
protocols: protocols(url),
|
||||
protocol: null,
|
||||
port: null,
|
||||
resource: "",
|
||||
user: "",
|
||||
pathname: "",
|
||||
hash: "",
|
||||
search: "",
|
||||
href: url,
|
||||
query: Object.create(null)
|
||||
},
|
||||
protocolIndex = url.indexOf("://"),
|
||||
resourceIndex = -1,
|
||||
splits = null,
|
||||
parts = null;
|
||||
|
||||
if (url.startsWith(".")) {
|
||||
if (url.startsWith("./")) {
|
||||
url = url.substring(2);
|
||||
}
|
||||
output.pathname = url;
|
||||
output.protocol = "file";
|
||||
}
|
||||
|
||||
var firstChar = url.charAt(1);
|
||||
if (!output.protocol) {
|
||||
output.protocol = output.protocols[0];
|
||||
if (!output.protocol) {
|
||||
if (isSsh(url)) {
|
||||
output.protocol = "ssh";
|
||||
} else if (firstChar === "/" || firstChar === "~") {
|
||||
url = url.substring(2);
|
||||
output.protocol = "file";
|
||||
} else {
|
||||
output.protocol = "file";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (protocolIndex !== -1) {
|
||||
url = url.substring(protocolIndex + 3);
|
||||
}
|
||||
|
||||
parts = url.split("/");
|
||||
if (output.protocol !== "file") {
|
||||
output.resource = parts.shift();
|
||||
} else {
|
||||
output.resource = "";
|
||||
}
|
||||
|
||||
// user@domain
|
||||
splits = output.resource.split("@");
|
||||
if (splits.length === 2) {
|
||||
output.user = splits[0];
|
||||
output.resource = splits[1];
|
||||
}
|
||||
|
||||
// domain.com:port
|
||||
splits = output.resource.split(":");
|
||||
if (splits.length === 2) {
|
||||
output.resource = splits[0];
|
||||
if (splits[1]) {
|
||||
output.port = Number(splits[1]);
|
||||
if (isNaN(output.port)) {
|
||||
output.port = null;
|
||||
parts.unshift(splits[1]);
|
||||
}
|
||||
} else {
|
||||
output.port = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove empty elements
|
||||
parts = parts.filter(Boolean);
|
||||
|
||||
// Stringify the pathname
|
||||
if (output.protocol === "file") {
|
||||
output.pathname = output.href;
|
||||
} else {
|
||||
output.pathname = output.pathname || (output.protocol !== "file" || output.href[0] === "/" ? "/" : "") + parts.join("/");
|
||||
}
|
||||
|
||||
// #some-hash
|
||||
splits = output.pathname.split("#");
|
||||
if (splits.length === 2) {
|
||||
output.pathname = splits[0];
|
||||
output.hash = splits[1];
|
||||
}
|
||||
|
||||
// ?foo=bar
|
||||
splits = output.pathname.split("?");
|
||||
if (splits.length === 2) {
|
||||
output.pathname = splits[0];
|
||||
output.search = splits[1];
|
||||
}
|
||||
|
||||
output.query = qs.parse(output.search);
|
||||
output.href = output.href.replace(/\/$/, "");
|
||||
output.pathname = output.pathname.replace(/\/$/, "");
|
||||
return output;
|
||||
}
|
||||
|
||||
module.exports = parsePath;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 669:
|
||||
/***/ (function(module) {
|
||||
|
||||
|
@ -1757,6 +2366,82 @@ function isUnixExecutable(stats) {
|
|||
|
||||
/***/ }),
|
||||
|
||||
/***/ 720:
|
||||
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
// Dependencies
|
||||
var protocols = __webpack_require__(737);
|
||||
|
||||
/**
|
||||
* isSsh
|
||||
* Checks if an input value is a ssh url or not.
|
||||
*
|
||||
* @name isSsh
|
||||
* @function
|
||||
* @param {String|Array} input The input url or an array of protocols.
|
||||
* @return {Boolean} `true` if the input is a ssh url, `false` otherwise.
|
||||
*/
|
||||
function isSsh(input) {
|
||||
|
||||
if (Array.isArray(input)) {
|
||||
return input.indexOf("ssh") !== -1 || input.indexOf("rsync") !== -1;
|
||||
}
|
||||
|
||||
if (typeof input !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
var prots = protocols(input);
|
||||
input = input.substring(input.indexOf("://") + 3);
|
||||
if (isSsh(prots)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO This probably could be improved :)
|
||||
return input.indexOf("@") < input.indexOf(":");
|
||||
}
|
||||
|
||||
module.exports = isSsh;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 737:
|
||||
/***/ (function(module) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
/**
|
||||
* protocols
|
||||
* Returns the protocols of an input url.
|
||||
*
|
||||
* @name protocols
|
||||
* @function
|
||||
* @param {String} input The input url.
|
||||
* @param {Boolean|Number} first If `true`, the first protocol will be returned. If number, it will represent the zero-based index of the protocols array.
|
||||
* @return {Array|String} The array of protocols or the specified protocol.
|
||||
*/
|
||||
module.exports = function protocols(input, first) {
|
||||
|
||||
if (first === true) {
|
||||
first = 0;
|
||||
}
|
||||
|
||||
var index = input.indexOf("://"),
|
||||
splits = input.substring(0, index).split("+").filter(Boolean);
|
||||
|
||||
if (typeof first === "number") {
|
||||
return splits[first];
|
||||
}
|
||||
|
||||
return splits;
|
||||
};
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 747:
|
||||
/***/ (function(module) {
|
||||
|
||||
|
@ -1826,6 +2511,75 @@ exports.exec = (command, args = [], silent) => __awaiter(void 0, void 0, void 0,
|
|||
|
||||
/***/ }),
|
||||
|
||||
/***/ 823:
|
||||
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var parsePath = __webpack_require__(666),
|
||||
normalizeUrl = __webpack_require__(53);
|
||||
|
||||
/**
|
||||
* parseUrl
|
||||
* Parses the input url.
|
||||
*
|
||||
* **Note**: This *throws* if invalid urls are provided.
|
||||
*
|
||||
* @name parseUrl
|
||||
* @function
|
||||
* @param {String} url The input url.
|
||||
* @param {Boolean|Object} normalize Wheter to normalize the url or not.
|
||||
* Default is `false`. If `true`, the url will
|
||||
* be normalized. If an object, it will be the
|
||||
* options object sent to [`normalize-url`](https://github.com/sindresorhus/normalize-url).
|
||||
*
|
||||
* For SSH urls, normalize won't work.
|
||||
*
|
||||
* @return {Object} An object containing the following fields:
|
||||
*
|
||||
* - `protocols` (Array): An array with the url protocols (usually it has one element).
|
||||
* - `protocol` (String): The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`.
|
||||
* - `port` (null|Number): The domain port.
|
||||
* - `resource` (String): The url domain (including subdomains).
|
||||
* - `user` (String): The authentication user (usually for ssh urls).
|
||||
* - `pathname` (String): The url pathname.
|
||||
* - `hash` (String): The url hash.
|
||||
* - `search` (String): The url querystring value.
|
||||
* - `href` (String): The input url.
|
||||
* - `query` (Object): The url querystring, parsed as object.
|
||||
*/
|
||||
function parseUrl(url) {
|
||||
var normalize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||||
|
||||
if (typeof url !== "string" || !url.trim()) {
|
||||
throw new Error("Invalid url.");
|
||||
}
|
||||
if (normalize) {
|
||||
if ((typeof normalize === "undefined" ? "undefined" : _typeof(normalize)) !== "object") {
|
||||
normalize = {
|
||||
stripFragment: false
|
||||
};
|
||||
}
|
||||
url = normalizeUrl(url, normalize);
|
||||
}
|
||||
var parsed = parsePath(url);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
module.exports = parseUrl;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 835:
|
||||
/***/ (function(module) {
|
||||
|
||||
module.exports = require("url");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 982:
|
||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||
|
||||
|
|
|
@ -27,9 +27,11 @@
|
|||
"dependencies": {
|
||||
"@actions/core": "^1.2.4",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/tool-cache": "^1.5.5"
|
||||
"@actions/tool-cache": "^1.5.5",
|
||||
"git-url-parse": "^11.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/git-url-parse": "^9.0.0",
|
||||
"@types/node": "^14.0.14",
|
||||
"@zeit/ncc": "^0.22.3",
|
||||
"prettier": "^2.0.5",
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import gitUrlParse from 'git-url-parse';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
export interface Inputs {
|
||||
|
@ -24,7 +25,7 @@ export interface Inputs {
|
|||
|
||||
export async function getInputs(): Promise<Inputs> {
|
||||
return {
|
||||
context: core.getInput('context') || '.',
|
||||
context: await getBuildContext(),
|
||||
file: core.getInput('file') || './Dockerfile',
|
||||
buildArgs: await getInputList('build-args'),
|
||||
labels: await getInputList('labels'),
|
||||
|
@ -65,6 +66,21 @@ export async function getArgs(inputs: Inputs): Promise<Array<string>> {
|
|||
return args;
|
||||
}
|
||||
|
||||
async function getBuildContext(): Promise<string> {
|
||||
let context: string = core.getInput('context');
|
||||
if (!context) {
|
||||
return '.';
|
||||
}
|
||||
try {
|
||||
const gitURL = gitUrlParse(context);
|
||||
gitURL.token = gitURL.token || process.env['GIT_TOKEN'] || process.env['GITHUB_TOKEN'] || '';
|
||||
gitURL.ref = gitURL.ref || process.env['GIT_REF'] || process.env['GITHUB_REF'] || '';
|
||||
return gitURL.toString();
|
||||
} catch {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
async function getCommonArgs(inputs: Inputs): Promise<Array<string>> {
|
||||
let args: Array<string> = [];
|
||||
if (inputs.noCache) {
|
||||
|
|
55
yarn.lock
55
yarn.lock
|
@ -38,6 +38,11 @@
|
|||
semver "^6.1.0"
|
||||
uuid "^3.3.2"
|
||||
|
||||
"@types/git-url-parse@^9.0.0":
|
||||
version "9.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/git-url-parse/-/git-url-parse-9.0.0.tgz#aac1315a44fa4ed5a52c3820f6c3c2fb79cbd12d"
|
||||
integrity sha512-kA2RxBT/r/ZuDDKwMl+vFWn1Z0lfm1/Ik6Qb91wnSzyzCDa/fkM8gIOq6ruB7xfr37n6Mj5dyivileUVKsidlg==
|
||||
|
||||
"@types/node@^14.0.14":
|
||||
version "14.0.27"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.27.tgz#a151873af5a5e851b51b3b065c9e63390a9e0eb1"
|
||||
|
@ -68,6 +73,28 @@ editorconfig@^0.15.0:
|
|||
semver "^5.6.0"
|
||||
sigmund "^1.0.1"
|
||||
|
||||
git-up@^4.0.0:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/git-up/-/git-up-4.0.2.tgz#10c3d731051b366dc19d3df454bfca3f77913a7c"
|
||||
integrity sha512-kbuvus1dWQB2sSW4cbfTeGpCMd8ge9jx9RKnhXhuJ7tnvT+NIrTVfYZxjtflZddQYcmdOTlkAcjmx7bor+15AQ==
|
||||
dependencies:
|
||||
is-ssh "^1.3.0"
|
||||
parse-url "^5.0.0"
|
||||
|
||||
git-url-parse@^11.1.3:
|
||||
version "11.1.3"
|
||||
resolved "https://registry.yarnpkg.com/git-url-parse/-/git-url-parse-11.1.3.tgz#03625b6fc09905e9ad1da7bb2b84be1bf9123143"
|
||||
integrity sha512-GPsfwticcu52WQ+eHp0IYkAyaOASgYdtsQDIt4rUp6GbiNt1P9ddrh3O0kQB0eD4UJZszVqNT3+9Zwcg40fywA==
|
||||
dependencies:
|
||||
git-up "^4.0.0"
|
||||
|
||||
is-ssh@^1.3.0:
|
||||
version "1.3.2"
|
||||
resolved "https://registry.yarnpkg.com/is-ssh/-/is-ssh-1.3.2.tgz#a4b82ab63d73976fd8263cceee27f99a88bdae2b"
|
||||
integrity sha512-elEw0/0c2UscLrNG+OAorbP539E3rhliKPg+hDMWN9VwrDXfYK+4PBEykDPfxlYYtQvl84TascnQyobfQLHEhQ==
|
||||
dependencies:
|
||||
protocols "^1.1.0"
|
||||
|
||||
lru-cache@^4.1.5:
|
||||
version "4.1.5"
|
||||
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
|
||||
|
@ -76,11 +103,39 @@ lru-cache@^4.1.5:
|
|||
pseudomap "^1.0.2"
|
||||
yallist "^2.1.2"
|
||||
|
||||
normalize-url@^3.3.0:
|
||||
version "3.3.0"
|
||||
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559"
|
||||
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
|
||||
|
||||
parse-path@^4.0.0:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/parse-path/-/parse-path-4.0.2.tgz#ef14f0d3d77bae8dd4bc66563a4c151aac9e65aa"
|
||||
integrity sha512-HSqVz6iuXSiL8C1ku5Gl1Z5cwDd9Wo0q8CoffdAghP6bz8pJa1tcMC+m4N+z6VAS8QdksnIGq1TB6EgR4vPR6w==
|
||||
dependencies:
|
||||
is-ssh "^1.3.0"
|
||||
protocols "^1.4.0"
|
||||
|
||||
parse-url@^5.0.0:
|
||||
version "5.0.2"
|
||||
resolved "https://registry.yarnpkg.com/parse-url/-/parse-url-5.0.2.tgz#856a3be1fcdf78dc93fc8b3791f169072d898b59"
|
||||
integrity sha512-Czj+GIit4cdWtxo3ISZCvLiUjErSo0iI3wJ+q9Oi3QuMYTI6OZu+7cewMWZ+C1YAnKhYTk6/TLuhIgCypLthPA==
|
||||
dependencies:
|
||||
is-ssh "^1.3.0"
|
||||
normalize-url "^3.3.0"
|
||||
parse-path "^4.0.0"
|
||||
protocols "^1.4.0"
|
||||
|
||||
prettier@^2.0.5:
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
|
||||
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==
|
||||
|
||||
protocols@^1.1.0, protocols@^1.4.0:
|
||||
version "1.4.8"
|
||||
resolved "https://registry.yarnpkg.com/protocols/-/protocols-1.4.8.tgz#48eea2d8f58d9644a4a32caae5d5db290a075ce8"
|
||||
integrity sha512-IgjKyaUSjsROSO8/D49Ab7hP8mJgTYcqApOqdPhLoPxAplXmkp+zRvsrSQjFn5by0rhm4VH0GAUELIPpx7B1yg==
|
||||
|
||||
pseudomap@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
|
||||
|
|
Loading…
Reference in a new issue