@docker/actions-toolkit 0.76.0 → 0.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/buildkit/buildkit.d.ts +3 -3
- package/lib/buildkit/buildkit.js +67 -117
- package/lib/buildkit/buildkit.js.map +1 -1
- package/lib/buildkit/config.js +7 -14
- package/lib/buildkit/config.js.map +1 -1
- package/lib/buildkit/git.d.ts +1 -1
- package/lib/buildkit/git.js +8 -12
- package/lib/buildkit/git.js.map +1 -1
- package/lib/buildx/bake.d.ts +4 -4
- package/lib/buildx/bake.js +76 -93
- package/lib/buildx/bake.js.map +1 -1
- package/lib/buildx/build.d.ts +5 -5
- package/lib/buildx/build.js +44 -78
- package/lib/buildx/build.js.map +1 -1
- package/lib/buildx/builder.d.ts +2 -2
- package/lib/buildx/builder.js +42 -91
- package/lib/buildx/builder.js.map +1 -1
- package/lib/buildx/buildx.d.ts +3 -3
- package/lib/buildx/buildx.js +212 -274
- package/lib/buildx/buildx.js.map +1 -1
- package/lib/buildx/history.d.ts +2 -2
- package/lib/buildx/history.js +226 -284
- package/lib/buildx/history.js.map +1 -1
- package/lib/buildx/imagetools.d.ts +5 -5
- package/lib/buildx/imagetools.js +67 -92
- package/lib/buildx/imagetools.js.map +1 -1
- package/lib/buildx/install.d.ts +14 -3
- package/lib/buildx/install.js +239 -276
- package/lib/buildx/install.js.map +1 -1
- package/lib/cache.js +88 -138
- package/lib/cache.js.map +1 -1
- package/lib/compose/compose.js +53 -107
- package/lib/compose/compose.js.map +1 -1
- package/lib/compose/install.d.ts +2 -2
- package/lib/compose/install.js +129 -191
- package/lib/compose/install.js.map +1 -1
- package/lib/context.js +10 -50
- package/lib/context.js.map +1 -1
- package/lib/cosign/cosign.js +55 -106
- package/lib/cosign/cosign.js.map +1 -1
- package/lib/cosign/dockerfile.js +1 -4
- package/lib/cosign/dockerfile.js.map +1 -1
- package/lib/cosign/install.d.ts +6 -3
- package/lib/cosign/install.js +183 -261
- package/lib/cosign/install.js.map +1 -1
- package/lib/docker/assets.js +15 -24
- package/lib/docker/assets.js.map +1 -1
- package/lib/docker/docker.d.ts +1 -1
- package/lib/docker/docker.js +112 -182
- package/lib/docker/docker.js.map +1 -1
- package/lib/docker/install.d.ts +3 -3
- package/lib/docker/install.js +543 -617
- package/lib/docker/install.js.map +1 -1
- package/lib/dockerhub.d.ts +1 -1
- package/lib/dockerhub.js +67 -125
- package/lib/dockerhub.js.map +1 -1
- package/lib/exec.js +9 -59
- package/lib/exec.js.map +1 -1
- package/lib/git.d.ts +2 -1
- package/lib/git.js +144 -220
- package/lib/git.js.map +1 -1
- package/lib/github/artifact.d.ts +19 -0
- package/lib/github/artifact.js +49 -0
- package/lib/github/artifact.js.map +1 -0
- package/lib/{github.d.ts → github/github.d.ts} +4 -8
- package/lib/github/github.js +135 -0
- package/lib/github/github.js.map +1 -0
- package/lib/github/summary.d.ts +20 -0
- package/lib/github/summary.js +166 -0
- package/lib/github/summary.js.map +1 -0
- package/lib/index.js +17 -64
- package/lib/index.js.map +1 -1
- package/lib/oci/oci.d.ts +2 -2
- package/lib/oci/oci.js +52 -104
- package/lib/oci/oci.js.map +1 -1
- package/lib/regclient/install.d.ts +2 -2
- package/lib/regclient/install.js +83 -141
- package/lib/regclient/install.js.map +1 -1
- package/lib/regclient/regctl.d.ts +1 -1
- package/lib/regclient/regctl.js +67 -123
- package/lib/regclient/regctl.js.map +1 -1
- package/lib/sigstore/sigstore.d.ts +5 -3
- package/lib/sigstore/sigstore.js +355 -368
- package/lib/sigstore/sigstore.js.map +1 -1
- package/lib/toolkit.d.ts +16 -16
- package/lib/toolkit.js +49 -37
- package/lib/toolkit.js.map +1 -1
- package/lib/types/buildkit/buildkit.js +1 -4
- package/lib/types/buildkit/buildkit.js.map +1 -1
- package/lib/types/buildkit/client.d.ts +2 -2
- package/lib/types/buildkit/client.js +1 -2
- package/lib/types/buildkit/client.js.map +1 -1
- package/lib/types/buildkit/control.d.ts +4 -4
- package/lib/types/buildkit/control.js +1 -2
- package/lib/types/buildkit/control.js.map +1 -1
- package/lib/types/buildkit/git.js +1 -2
- package/lib/types/buildkit/git.js.map +1 -1
- package/lib/types/buildkit/ops.js +1 -2
- package/lib/types/buildkit/ops.js.map +1 -1
- package/lib/types/buildkit/rpc.js +1 -2
- package/lib/types/buildkit/rpc.js.map +1 -1
- package/lib/types/buildx/bake.js +1 -2
- package/lib/types/buildx/bake.js.map +1 -1
- package/lib/types/buildx/build.js +1 -2
- package/lib/types/buildx/build.js.map +1 -1
- package/lib/types/buildx/builder.js +1 -2
- package/lib/types/buildx/builder.js.map +1 -1
- package/lib/types/buildx/buildx.d.ts +1 -1
- package/lib/types/buildx/buildx.js +1 -2
- package/lib/types/buildx/buildx.js.map +1 -1
- package/lib/types/buildx/history.js +1 -2
- package/lib/types/buildx/history.js.map +1 -1
- package/lib/types/buildx/imagetools.d.ts +3 -3
- package/lib/types/buildx/imagetools.js +1 -2
- package/lib/types/buildx/imagetools.js.map +1 -1
- package/lib/types/compose/compose.d.ts +1 -1
- package/lib/types/compose/compose.js +1 -2
- package/lib/types/compose/compose.js.map +1 -1
- package/lib/types/cosign/cosign.d.ts +1 -1
- package/lib/types/cosign/cosign.js +1 -2
- package/lib/types/cosign/cosign.js.map +1 -1
- package/lib/types/docker/docker.js +1 -2
- package/lib/types/docker/docker.js.map +1 -1
- package/lib/types/docker/mediatype.js +3 -6
- package/lib/types/docker/mediatype.js.map +1 -1
- package/lib/types/dockerhub.js +1 -2
- package/lib/types/dockerhub.js.map +1 -1
- package/lib/types/github/artifact.d.ts +26 -0
- package/lib/types/{git.d.ts → github/artifact.js} +3 -3
- package/lib/types/github/artifact.js.map +1 -0
- package/lib/types/{github.d.ts → github/github.d.ts} +4 -23
- package/lib/types/{git.js → github/github.js} +2 -3
- package/lib/types/github/github.js.map +1 -0
- package/lib/types/github/summary.d.ts +29 -0
- package/lib/types/{github.js → github/summary.js} +3 -4
- package/lib/types/github/summary.js.map +1 -0
- package/lib/types/intoto/intoto.js +2 -5
- package/lib/types/intoto/intoto.js.map +1 -1
- package/lib/types/intoto/slsa_provenance/v0.2/provenance.js +1 -4
- package/lib/types/intoto/slsa_provenance/v0.2/provenance.js.map +1 -1
- package/lib/types/oci/config.d.ts +2 -2
- package/lib/types/oci/config.js +1 -2
- package/lib/types/oci/config.js.map +1 -1
- package/lib/types/oci/descriptor.d.ts +1 -1
- package/lib/types/oci/descriptor.js +3 -6
- package/lib/types/oci/descriptor.js.map +1 -1
- package/lib/types/oci/digest.js +1 -2
- package/lib/types/oci/digest.js.map +1 -1
- package/lib/types/oci/index.d.ts +2 -2
- package/lib/types/oci/index.js +1 -2
- package/lib/types/oci/index.js.map +1 -1
- package/lib/types/oci/layout.js +4 -7
- package/lib/types/oci/layout.js.map +1 -1
- package/lib/types/oci/manifest.d.ts +2 -2
- package/lib/types/oci/manifest.js +1 -2
- package/lib/types/oci/manifest.js.map +1 -1
- package/lib/types/oci/mediatype.js +6 -9
- package/lib/types/oci/mediatype.js.map +1 -1
- package/lib/types/oci/oci.d.ts +4 -4
- package/lib/types/oci/oci.js +1 -2
- package/lib/types/oci/oci.js.map +1 -1
- package/lib/types/oci/versioned.js +1 -2
- package/lib/types/oci/versioned.js.map +1 -1
- package/lib/types/regclient/regclient.d.ts +1 -1
- package/lib/types/regclient/regclient.js +1 -2
- package/lib/types/regclient/regclient.js.map +1 -1
- package/lib/types/sigstore/sigstore.d.ts +11 -2
- package/lib/types/sigstore/sigstore.js +4 -7
- package/lib/types/sigstore/sigstore.js.map +1 -1
- package/lib/types/undock/undock.d.ts +1 -1
- package/lib/types/undock/undock.js +1 -2
- package/lib/types/undock/undock.js.map +1 -1
- package/lib/undock/install.d.ts +2 -2
- package/lib/undock/install.js +93 -151
- package/lib/undock/install.js.map +1 -1
- package/lib/undock/undock.js +88 -141
- package/lib/undock/undock.js.map +1 -1
- package/lib/util.js +36 -89
- package/lib/util.js.map +1 -1
- package/package.json +31 -42
- package/lib/github.js +0 -421
- package/lib/github.js.map +0 -1
- package/lib/types/git.js.map +0 -1
- package/lib/types/github.js.map +0 -1
package/lib/buildx/buildx.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Copyright 2023 actions-toolkit authors
|
|
4
3
|
*
|
|
@@ -14,144 +13,90 @@
|
|
|
14
13
|
* See the License for the specific language governing permissions and
|
|
15
14
|
* limitations under the License.
|
|
16
15
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
-
var ownKeys = function(o) {
|
|
35
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
-
var ar = [];
|
|
37
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
return ownKeys(o);
|
|
41
|
-
};
|
|
42
|
-
return function (mod) {
|
|
43
|
-
if (mod && mod.__esModule) return mod;
|
|
44
|
-
var result = {};
|
|
45
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
-
__setModuleDefault(result, mod);
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
})();
|
|
50
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
51
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
52
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
53
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
54
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
55
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
56
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
60
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
61
|
-
};
|
|
62
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
-
exports.Buildx = void 0;
|
|
64
|
-
const fs_1 = __importDefault(require("fs"));
|
|
65
|
-
const path_1 = __importDefault(require("path"));
|
|
66
|
-
const core = __importStar(require("@actions/core"));
|
|
67
|
-
const semver = __importStar(require("semver"));
|
|
68
|
-
const git_1 = require("../buildkit/git");
|
|
69
|
-
const docker_1 = require("../docker/docker");
|
|
70
|
-
const github_1 = require("../github");
|
|
71
|
-
const exec_1 = require("../exec");
|
|
72
|
-
const util_1 = require("../util");
|
|
73
|
-
class Buildx {
|
|
16
|
+
import fs from 'fs';
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import * as core from '@actions/core';
|
|
19
|
+
import * as semver from 'semver';
|
|
20
|
+
import { Git } from '../buildkit/git.js';
|
|
21
|
+
import { Docker } from '../docker/docker.js';
|
|
22
|
+
import { GitHub } from '../github/github.js';
|
|
23
|
+
import { Exec } from '../exec.js';
|
|
24
|
+
import { Util } from '../util.js';
|
|
25
|
+
export class Buildx {
|
|
26
|
+
_version;
|
|
27
|
+
_versionOnce;
|
|
28
|
+
_standalone;
|
|
29
|
+
static containerNamePrefix = 'buildx_buildkit_';
|
|
74
30
|
constructor(opts) {
|
|
75
|
-
this._standalone = opts
|
|
31
|
+
this._standalone = opts?.standalone;
|
|
76
32
|
this._version = '';
|
|
77
33
|
this._versionOnce = false;
|
|
78
34
|
}
|
|
79
35
|
static get configDir() {
|
|
80
|
-
return process.env.BUILDX_CONFIG ||
|
|
36
|
+
return process.env.BUILDX_CONFIG || path.join(Docker.configDir, 'buildx');
|
|
81
37
|
}
|
|
82
38
|
static get refsDir() {
|
|
83
|
-
return
|
|
39
|
+
return path.join(Buildx.configDir, 'refs');
|
|
84
40
|
}
|
|
85
41
|
static get refsGroupDir() {
|
|
86
|
-
return
|
|
42
|
+
return path.join(Buildx.refsDir, '__group__');
|
|
87
43
|
}
|
|
88
44
|
static get certsDir() {
|
|
89
|
-
return
|
|
45
|
+
return path.join(Buildx.configDir, 'certs');
|
|
90
46
|
}
|
|
91
|
-
isStandalone() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
core.debug(`Buildx.isStandalone: ${standalone}`);
|
|
96
|
-
return standalone;
|
|
97
|
-
});
|
|
47
|
+
async isStandalone() {
|
|
48
|
+
const standalone = this._standalone ?? !(await Docker.isAvailable());
|
|
49
|
+
core.debug(`Buildx.isStandalone: ${standalone}`);
|
|
50
|
+
return standalone;
|
|
98
51
|
}
|
|
99
|
-
getCommand(args) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
};
|
|
106
|
-
});
|
|
52
|
+
async getCommand(args) {
|
|
53
|
+
const standalone = await this.isStandalone();
|
|
54
|
+
return {
|
|
55
|
+
command: standalone ? 'buildx' : 'docker',
|
|
56
|
+
args: standalone ? args : ['buildx', ...args]
|
|
57
|
+
};
|
|
107
58
|
}
|
|
108
|
-
isAvailable() {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
core.debug(`Buildx.isAvailable cmd err: ${res.stderr.trim()}`);
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
return res.exitCode == 0;
|
|
121
|
-
})
|
|
122
|
-
.catch(error => {
|
|
123
|
-
core.debug(`Buildx.isAvailable error: ${error}`);
|
|
59
|
+
async isAvailable() {
|
|
60
|
+
const cmd = await this.getCommand([]);
|
|
61
|
+
const ok = await Exec.getExecOutput(cmd.command, cmd.args, {
|
|
62
|
+
ignoreReturnCode: true,
|
|
63
|
+
silent: true
|
|
64
|
+
})
|
|
65
|
+
.then(res => {
|
|
66
|
+
if (res.stderr.length > 0 && res.exitCode != 0) {
|
|
67
|
+
core.debug(`Buildx.isAvailable cmd err: ${res.stderr.trim()}`);
|
|
124
68
|
return false;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
69
|
+
}
|
|
70
|
+
return res.exitCode == 0;
|
|
71
|
+
})
|
|
72
|
+
.catch(error => {
|
|
73
|
+
core.debug(`Buildx.isAvailable error: ${error}`);
|
|
74
|
+
return false;
|
|
128
75
|
});
|
|
76
|
+
core.debug(`Buildx.isAvailable: ${ok}`);
|
|
77
|
+
return ok;
|
|
129
78
|
}
|
|
130
|
-
version() {
|
|
131
|
-
|
|
132
|
-
if (this._versionOnce) {
|
|
133
|
-
return this._version;
|
|
134
|
-
}
|
|
135
|
-
this._versionOnce = true;
|
|
136
|
-
const cmd = yield this.getCommand(['version']);
|
|
137
|
-
this._version = yield exec_1.Exec.getExecOutput(cmd.command, cmd.args, {
|
|
138
|
-
ignoreReturnCode: true,
|
|
139
|
-
silent: true
|
|
140
|
-
}).then(res => {
|
|
141
|
-
if (res.stderr.length > 0 && res.exitCode != 0) {
|
|
142
|
-
throw new Error(res.stderr.trim());
|
|
143
|
-
}
|
|
144
|
-
return Buildx.parseVersion(res.stdout.trim());
|
|
145
|
-
});
|
|
79
|
+
async version() {
|
|
80
|
+
if (this._versionOnce) {
|
|
146
81
|
return this._version;
|
|
82
|
+
}
|
|
83
|
+
this._versionOnce = true;
|
|
84
|
+
const cmd = await this.getCommand(['version']);
|
|
85
|
+
this._version = await Exec.getExecOutput(cmd.command, cmd.args, {
|
|
86
|
+
ignoreReturnCode: true,
|
|
87
|
+
silent: true
|
|
88
|
+
}).then(res => {
|
|
89
|
+
if (res.stderr.length > 0 && res.exitCode != 0) {
|
|
90
|
+
throw new Error(res.stderr.trim());
|
|
91
|
+
}
|
|
92
|
+
return Buildx.parseVersion(res.stdout.trim());
|
|
147
93
|
});
|
|
94
|
+
return this._version;
|
|
148
95
|
}
|
|
149
|
-
printVersion() {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
failOnStdErr: false
|
|
154
|
-
});
|
|
96
|
+
async printVersion() {
|
|
97
|
+
const cmd = await this.getCommand(['version']);
|
|
98
|
+
await Exec.exec(cmd.command, cmd.args, {
|
|
99
|
+
failOnStdErr: false
|
|
155
100
|
});
|
|
156
101
|
}
|
|
157
102
|
static parseVersion(stdout) {
|
|
@@ -161,24 +106,22 @@ class Buildx {
|
|
|
161
106
|
}
|
|
162
107
|
return matches[1];
|
|
163
108
|
}
|
|
164
|
-
versionSatisfies(range, version) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return res;
|
|
174
|
-
});
|
|
109
|
+
async versionSatisfies(range, version) {
|
|
110
|
+
const ver = version ?? (await this.version());
|
|
111
|
+
if (!ver) {
|
|
112
|
+
core.debug(`Buildx.versionSatisfies false: undefined version`);
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
const res = semver.satisfies(ver, range) || /^[0-9a-f]{7}$/.exec(ver) !== null;
|
|
116
|
+
core.debug(`Buildx.versionSatisfies ${ver} statisfies ${range}: ${res}`);
|
|
117
|
+
return res;
|
|
175
118
|
}
|
|
176
119
|
static resolveCertsDriverOpts(driver, endpoint, cert) {
|
|
177
120
|
let url;
|
|
178
121
|
try {
|
|
179
122
|
url = new URL(endpoint);
|
|
180
123
|
}
|
|
181
|
-
catch
|
|
124
|
+
catch {
|
|
182
125
|
return [];
|
|
183
126
|
}
|
|
184
127
|
if (url.protocol != 'tcp:') {
|
|
@@ -193,18 +136,18 @@ class Buildx {
|
|
|
193
136
|
host += `-${url.port}`;
|
|
194
137
|
}
|
|
195
138
|
if (cert.cacert !== undefined) {
|
|
196
|
-
const cacertpath =
|
|
197
|
-
|
|
139
|
+
const cacertpath = path.join(Buildx.certsDir, `cacert_${host}.pem`);
|
|
140
|
+
fs.writeFileSync(cacertpath, cert.cacert);
|
|
198
141
|
driverOpts.push(`cacert=${cacertpath}`);
|
|
199
142
|
}
|
|
200
143
|
if (cert.cert !== undefined) {
|
|
201
|
-
const certpath =
|
|
202
|
-
|
|
144
|
+
const certpath = path.join(Buildx.certsDir, `cert_${host}.pem`);
|
|
145
|
+
fs.writeFileSync(certpath, cert.cert);
|
|
203
146
|
driverOpts.push(`cert=${certpath}`);
|
|
204
147
|
}
|
|
205
148
|
if (cert.key !== undefined) {
|
|
206
|
-
const keypath =
|
|
207
|
-
|
|
149
|
+
const keypath = path.join(Buildx.certsDir, `key_${host}.pem`);
|
|
150
|
+
fs.writeFileSync(keypath, cert.key);
|
|
208
151
|
driverOpts.push(`key=${keypath}`);
|
|
209
152
|
}
|
|
210
153
|
if (driver != 'remote') {
|
|
@@ -217,11 +160,11 @@ class Buildx {
|
|
|
217
160
|
if (!builderName || !nodeName || !id) {
|
|
218
161
|
throw new Error(`Invalid build reference: ${ref}`);
|
|
219
162
|
}
|
|
220
|
-
const lsPath =
|
|
221
|
-
if (!
|
|
163
|
+
const lsPath = path.join(dir || Buildx.refsDir, builderName, nodeName, id);
|
|
164
|
+
if (!fs.existsSync(lsPath)) {
|
|
222
165
|
throw new Error(`Local state not found in ${lsPath}`);
|
|
223
166
|
}
|
|
224
|
-
return Buildx.fixLocalState(JSON.parse(
|
|
167
|
+
return Buildx.fixLocalState(JSON.parse(fs.readFileSync(lsPath, 'utf8')));
|
|
225
168
|
}
|
|
226
169
|
// https://github.com/docker/buildx/pull/2560
|
|
227
170
|
static fixLocalState(ls) {
|
|
@@ -259,22 +202,22 @@ class Buildx {
|
|
|
259
202
|
}
|
|
260
203
|
static refs(opts, refs = {}) {
|
|
261
204
|
const { dir, builderName, nodeName, since } = opts;
|
|
262
|
-
let dirpath =
|
|
205
|
+
let dirpath = path.resolve(dir);
|
|
263
206
|
if (opts.builderName) {
|
|
264
|
-
dirpath =
|
|
207
|
+
dirpath = path.join(dirpath, opts.builderName);
|
|
265
208
|
}
|
|
266
209
|
if (opts.nodeName) {
|
|
267
|
-
dirpath =
|
|
210
|
+
dirpath = path.join(dirpath, opts.nodeName);
|
|
268
211
|
}
|
|
269
|
-
if (!
|
|
212
|
+
if (!fs.existsSync(dirpath)) {
|
|
270
213
|
return refs;
|
|
271
214
|
}
|
|
272
|
-
const files =
|
|
215
|
+
const files = fs.readdirSync(dirpath);
|
|
273
216
|
for (const file of files) {
|
|
274
|
-
const filePath =
|
|
275
|
-
const stat =
|
|
217
|
+
const filePath = path.join(dirpath, file);
|
|
218
|
+
const stat = fs.statSync(filePath);
|
|
276
219
|
if (stat.isDirectory()) {
|
|
277
|
-
const nopts =
|
|
220
|
+
const nopts = { ...opts };
|
|
278
221
|
if (!builderName) {
|
|
279
222
|
if (file === '__group__') {
|
|
280
223
|
continue;
|
|
@@ -290,147 +233,142 @@ class Buildx {
|
|
|
290
233
|
if (since && stat.mtime < since) {
|
|
291
234
|
continue;
|
|
292
235
|
}
|
|
293
|
-
const localState = Buildx.fixLocalState(JSON.parse(
|
|
236
|
+
const localState = Buildx.fixLocalState(JSON.parse(fs.readFileSync(filePath, 'utf8')));
|
|
294
237
|
const ref = `${builderName}/${nodeName}/${file}`;
|
|
295
238
|
refs[ref] = localState;
|
|
296
239
|
}
|
|
297
240
|
}
|
|
298
241
|
return refs;
|
|
299
242
|
}
|
|
300
|
-
static convertWarningsToGitHubAnnotations(warnings, buildRefs, refsDir) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
243
|
+
static async convertWarningsToGitHubAnnotations(warnings, buildRefs, refsDir) {
|
|
244
|
+
if (warnings.length === 0) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const fnGitURL = function (inp) {
|
|
248
|
+
try {
|
|
249
|
+
return Git.parseURL(inp);
|
|
305
250
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return git_1.Git.parseURL(inp);
|
|
309
|
-
}
|
|
310
|
-
catch (_a) {
|
|
311
|
-
// noop
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
const fnLocalState = function (ref) {
|
|
315
|
-
try {
|
|
316
|
-
return Buildx.localState(ref, refsDir);
|
|
317
|
-
}
|
|
318
|
-
catch (e) {
|
|
319
|
-
core.debug(`Buildx.convertWarningsToGitHubAnnotations(${ref}): local state not found: ${e.message}`);
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
const dockerfiles = [];
|
|
323
|
-
for (const ref of buildRefs) {
|
|
324
|
-
const ls = fnLocalState(ref);
|
|
325
|
-
if (!ls) {
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
if (ls.DockerfilePath == '-') {
|
|
329
|
-
// exclude dockerfile from stdin
|
|
330
|
-
core.debug(`Buildx.convertWarningsToGitHubAnnotations(${ref}): skipping stdin Dockerfile`);
|
|
331
|
-
continue;
|
|
332
|
-
}
|
|
333
|
-
else if (ls.DockerfilePath == '') {
|
|
334
|
-
ls.DockerfilePath = 'Dockerfile';
|
|
335
|
-
}
|
|
336
|
-
const gitURL = fnGitURL(ls.LocalPath);
|
|
337
|
-
if (gitURL) {
|
|
338
|
-
core.debug(`Buildx.convertWarningsToGitHubAnnotations(${ref}): git context detected: ${ls.LocalPath}`);
|
|
339
|
-
const remoteHost = gitURL.host.replace(/:.*/, '');
|
|
340
|
-
if (remoteHost !== 'github.com' && !remoteHost.endsWith('.ghe.com')) {
|
|
341
|
-
// we only support running actions on GitHub for now
|
|
342
|
-
// we might add support for GitLab in the future
|
|
343
|
-
core.debug(`Buildx.convertWarningsToGitHubAnnotations(${ref}): not a GitHub repo: ${remoteHost}`);
|
|
344
|
-
continue;
|
|
345
|
-
}
|
|
346
|
-
// if repository matches then we can link to the Dockerfile
|
|
347
|
-
const remoteRepo = gitURL.path.replace(/^\//, '').replace(/\.git$/, '');
|
|
348
|
-
if (remoteRepo !== github_1.GitHub.repository) {
|
|
349
|
-
core.debug(`Buildx.convertWarningsToGitHubAnnotations(${ref}): not same GitHub repo: ${remoteRepo} != ${github_1.GitHub.repository}`);
|
|
350
|
-
continue;
|
|
351
|
-
}
|
|
352
|
-
dockerfiles.push({
|
|
353
|
-
path: ls.DockerfilePath, // dockerfile path is always relative for a git context
|
|
354
|
-
remote: true
|
|
355
|
-
});
|
|
356
|
-
continue;
|
|
357
|
-
}
|
|
358
|
-
if (!fs_1.default.existsSync(ls.DockerfilePath)) {
|
|
359
|
-
core.debug(`Buildx.convertWarningsToGitHubAnnotations: Dockerfile not found from localstate ref ${ref}: ${ls.DockerfilePath}`);
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
const workspaceDir = github_1.GitHub.workspace;
|
|
363
|
-
// only treat dockerfile path relative to GitHub actions workspace dir
|
|
364
|
-
if (util_1.Util.isPathRelativeTo(workspaceDir, ls.DockerfilePath)) {
|
|
365
|
-
dockerfiles.push({
|
|
366
|
-
path: path_1.default.relative(workspaceDir, ls.DockerfilePath),
|
|
367
|
-
content: Buffer.from(fs_1.default.readFileSync(ls.DockerfilePath, { encoding: 'utf-8' }), 'utf-8').toString('base64')
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
core.debug(`Buildx.convertWarningsToGitHubAnnotations: skipping Dockerfile outside of workspace: ${ls.DockerfilePath}`);
|
|
372
|
-
}
|
|
251
|
+
catch {
|
|
252
|
+
// noop
|
|
373
253
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
254
|
+
};
|
|
255
|
+
const fnLocalState = function (ref) {
|
|
256
|
+
try {
|
|
257
|
+
return Buildx.localState(ref, refsDir);
|
|
377
258
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
259
|
+
catch (e) {
|
|
260
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations(${ref}): local state not found: ${e.message}`);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const dockerfiles = [];
|
|
264
|
+
for (const ref of buildRefs) {
|
|
265
|
+
const ls = fnLocalState(ref);
|
|
266
|
+
if (!ls) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (ls.DockerfilePath == '-') {
|
|
270
|
+
// exclude dockerfile from stdin
|
|
271
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations(${ref}): skipping stdin Dockerfile`);
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
else if (ls.DockerfilePath == '') {
|
|
275
|
+
ls.DockerfilePath = 'Dockerfile';
|
|
276
|
+
}
|
|
277
|
+
const gitURL = fnGitURL(ls.LocalPath);
|
|
278
|
+
if (gitURL) {
|
|
279
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations(${ref}): git context detected: ${ls.LocalPath}`);
|
|
280
|
+
const remoteHost = gitURL.host.replace(/:.*/, '');
|
|
281
|
+
if (remoteHost !== 'github.com' && !remoteHost.endsWith('.ghe.com')) {
|
|
282
|
+
// we only support running actions on GitHub for now
|
|
283
|
+
// we might add support for GitLab in the future
|
|
284
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations(${ref}): not a GitHub repo: ${remoteHost}`);
|
|
383
285
|
continue;
|
|
384
286
|
}
|
|
385
|
-
|
|
386
|
-
const
|
|
387
|
-
if (
|
|
388
|
-
core.debug(`Buildx.convertWarningsToGitHubAnnotations:
|
|
287
|
+
// if repository matches then we can link to the Dockerfile
|
|
288
|
+
const remoteRepo = gitURL.path.replace(/^\//, '').replace(/\.git$/, '');
|
|
289
|
+
if (remoteRepo !== GitHub.repository) {
|
|
290
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations(${ref}): not same GitHub repo: ${remoteRepo} != ${GitHub.repository}`);
|
|
389
291
|
continue;
|
|
390
292
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
293
|
+
dockerfiles.push({
|
|
294
|
+
path: ls.DockerfilePath, // dockerfile path is always relative for a git context
|
|
295
|
+
remote: true
|
|
296
|
+
});
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (!fs.existsSync(ls.DockerfilePath)) {
|
|
300
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations: Dockerfile not found from localstate ref ${ref}: ${ls.DockerfilePath}`);
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
const workspaceDir = GitHub.workspace;
|
|
304
|
+
// only treat dockerfile path relative to GitHub actions workspace dir
|
|
305
|
+
if (Util.isPathRelativeTo(workspaceDir, ls.DockerfilePath)) {
|
|
306
|
+
dockerfiles.push({
|
|
307
|
+
path: path.relative(workspaceDir, ls.DockerfilePath),
|
|
308
|
+
content: Buffer.from(fs.readFileSync(ls.DockerfilePath, { encoding: 'utf-8' }), 'utf-8').toString('base64')
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations: skipping Dockerfile outside of workspace: ${ls.DockerfilePath}`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (dockerfiles.length === 0) {
|
|
316
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations: no Dockerfiles found`);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations: found ${dockerfiles.length} Dockerfiles: ${JSON.stringify(dockerfiles, null, 2)}`);
|
|
320
|
+
const annotations = [];
|
|
321
|
+
for (const warning of warnings) {
|
|
322
|
+
if (!warning.detail || !warning.short) {
|
|
323
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations: skipping warning without detail or short`);
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const warningSourceFilename = warning.sourceInfo?.filename;
|
|
327
|
+
const warningSourceData = warning.sourceInfo?.data;
|
|
328
|
+
if (!warningSourceFilename || !warningSourceData) {
|
|
329
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations: skipping warning without source info filename or data`);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
const title = warning.detail.map(encoded => atob(encoded)).join(' ');
|
|
333
|
+
let message = atob(warning.short).replace(/\s\(line \d+\)$/, '');
|
|
334
|
+
if (warning.url) {
|
|
335
|
+
// https://github.com/docker/buildx/blob/d8c9ebde1fdcf659f1fa3efa6ccc27a28b0f1564/commands/build.go#L854
|
|
336
|
+
message += `\nMore info: ${warning.url}`;
|
|
337
|
+
}
|
|
338
|
+
// GitHub's annotations don't clearly show ranges of lines, so we'll just
|
|
339
|
+
// show the first line: https://github.com/orgs/community/discussions/129899
|
|
340
|
+
const startLine = warning.range && warning.range.length > 0 ? warning.range[0]?.start.line : undefined;
|
|
341
|
+
// TODO: When GitHub's annotations support showing ranges properly, we can use this code
|
|
342
|
+
// let startLine: number | undefined, endLine: number | undefined;
|
|
343
|
+
// for (const range of warning.range ?? []) {
|
|
344
|
+
// if (range.start.line && (!startLine || range.start.line < startLine)) {
|
|
345
|
+
// startLine = range.start.line;
|
|
346
|
+
// }
|
|
347
|
+
// if (range.end.line && (!endLine || range.end.line > endLine)) {
|
|
348
|
+
// endLine = range.end.line;
|
|
349
|
+
// }
|
|
350
|
+
// }
|
|
351
|
+
let annotated = false;
|
|
352
|
+
for (const dockerfile of dockerfiles) {
|
|
353
|
+
// a valid dockerfile path and content is required to match the warning
|
|
354
|
+
// source info or always assume it's valid if this is a remote git
|
|
355
|
+
// context as we can't read the content of the Dockerfile in this case.
|
|
356
|
+
if (dockerfile.remote || (dockerfile.path.endsWith(warningSourceFilename) && dockerfile.content === warningSourceData)) {
|
|
357
|
+
annotations.push({
|
|
358
|
+
title: title,
|
|
359
|
+
message: message,
|
|
360
|
+
file: dockerfile.path,
|
|
361
|
+
startLine: startLine
|
|
362
|
+
});
|
|
363
|
+
annotated = true;
|
|
364
|
+
break;
|
|
428
365
|
}
|
|
429
366
|
}
|
|
430
|
-
|
|
431
|
-
|
|
367
|
+
if (!annotated) {
|
|
368
|
+
core.debug(`Buildx.convertWarningsToGitHubAnnotations: skipping warning without matching Dockerfile ${warningSourceFilename}: ${title}`);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return annotations;
|
|
432
372
|
}
|
|
433
373
|
}
|
|
434
|
-
exports.Buildx = Buildx;
|
|
435
|
-
Buildx.containerNamePrefix = 'buildx_buildkit_';
|
|
436
374
|
//# sourceMappingURL=buildx.js.map
|