@docker/actions-toolkit 0.75.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.
Files changed (184) hide show
  1. package/lib/buildkit/buildkit.d.ts +3 -3
  2. package/lib/buildkit/buildkit.js +67 -117
  3. package/lib/buildkit/buildkit.js.map +1 -1
  4. package/lib/buildkit/config.js +7 -14
  5. package/lib/buildkit/config.js.map +1 -1
  6. package/lib/buildkit/git.d.ts +1 -1
  7. package/lib/buildkit/git.js +8 -12
  8. package/lib/buildkit/git.js.map +1 -1
  9. package/lib/buildx/bake.d.ts +4 -4
  10. package/lib/buildx/bake.js +76 -93
  11. package/lib/buildx/bake.js.map +1 -1
  12. package/lib/buildx/build.d.ts +5 -5
  13. package/lib/buildx/build.js +44 -78
  14. package/lib/buildx/build.js.map +1 -1
  15. package/lib/buildx/builder.d.ts +2 -2
  16. package/lib/buildx/builder.js +42 -91
  17. package/lib/buildx/builder.js.map +1 -1
  18. package/lib/buildx/buildx.d.ts +3 -3
  19. package/lib/buildx/buildx.js +212 -274
  20. package/lib/buildx/buildx.js.map +1 -1
  21. package/lib/buildx/history.d.ts +2 -2
  22. package/lib/buildx/history.js +226 -284
  23. package/lib/buildx/history.js.map +1 -1
  24. package/lib/buildx/imagetools.d.ts +5 -5
  25. package/lib/buildx/imagetools.js +67 -92
  26. package/lib/buildx/imagetools.js.map +1 -1
  27. package/lib/buildx/install.d.ts +14 -3
  28. package/lib/buildx/install.js +239 -276
  29. package/lib/buildx/install.js.map +1 -1
  30. package/lib/cache.js +88 -138
  31. package/lib/cache.js.map +1 -1
  32. package/lib/compose/compose.js +53 -107
  33. package/lib/compose/compose.js.map +1 -1
  34. package/lib/compose/install.d.ts +2 -2
  35. package/lib/compose/install.js +129 -191
  36. package/lib/compose/install.js.map +1 -1
  37. package/lib/context.js +10 -50
  38. package/lib/context.js.map +1 -1
  39. package/lib/cosign/cosign.js +55 -106
  40. package/lib/cosign/cosign.js.map +1 -1
  41. package/lib/cosign/dockerfile.js +1 -4
  42. package/lib/cosign/dockerfile.js.map +1 -1
  43. package/lib/cosign/install.d.ts +6 -3
  44. package/lib/cosign/install.js +183 -261
  45. package/lib/cosign/install.js.map +1 -1
  46. package/lib/docker/assets.js +15 -24
  47. package/lib/docker/assets.js.map +1 -1
  48. package/lib/docker/docker.d.ts +1 -1
  49. package/lib/docker/docker.js +112 -182
  50. package/lib/docker/docker.js.map +1 -1
  51. package/lib/docker/install.d.ts +3 -3
  52. package/lib/docker/install.js +543 -617
  53. package/lib/docker/install.js.map +1 -1
  54. package/lib/dockerhub.d.ts +1 -1
  55. package/lib/dockerhub.js +67 -125
  56. package/lib/dockerhub.js.map +1 -1
  57. package/lib/exec.js +9 -59
  58. package/lib/exec.js.map +1 -1
  59. package/lib/git.d.ts +2 -1
  60. package/lib/git.js +144 -220
  61. package/lib/git.js.map +1 -1
  62. package/lib/github/artifact.d.ts +19 -0
  63. package/lib/github/artifact.js +49 -0
  64. package/lib/github/artifact.js.map +1 -0
  65. package/lib/{github.d.ts → github/github.d.ts} +4 -8
  66. package/lib/github/github.js +135 -0
  67. package/lib/github/github.js.map +1 -0
  68. package/lib/github/summary.d.ts +20 -0
  69. package/lib/github/summary.js +166 -0
  70. package/lib/github/summary.js.map +1 -0
  71. package/lib/index.js +17 -64
  72. package/lib/index.js.map +1 -1
  73. package/lib/oci/oci.d.ts +2 -2
  74. package/lib/oci/oci.js +52 -104
  75. package/lib/oci/oci.js.map +1 -1
  76. package/lib/regclient/install.d.ts +2 -2
  77. package/lib/regclient/install.js +83 -141
  78. package/lib/regclient/install.js.map +1 -1
  79. package/lib/regclient/regctl.d.ts +1 -1
  80. package/lib/regclient/regctl.js +67 -123
  81. package/lib/regclient/regctl.js.map +1 -1
  82. package/lib/sigstore/sigstore.d.ts +5 -3
  83. package/lib/sigstore/sigstore.js +361 -344
  84. package/lib/sigstore/sigstore.js.map +1 -1
  85. package/lib/toolkit.d.ts +16 -16
  86. package/lib/toolkit.js +49 -37
  87. package/lib/toolkit.js.map +1 -1
  88. package/lib/types/buildkit/buildkit.js +1 -4
  89. package/lib/types/buildkit/buildkit.js.map +1 -1
  90. package/lib/types/buildkit/client.d.ts +2 -2
  91. package/lib/types/buildkit/client.js +1 -2
  92. package/lib/types/buildkit/client.js.map +1 -1
  93. package/lib/types/buildkit/control.d.ts +4 -4
  94. package/lib/types/buildkit/control.js +1 -2
  95. package/lib/types/buildkit/control.js.map +1 -1
  96. package/lib/types/buildkit/git.js +1 -2
  97. package/lib/types/buildkit/git.js.map +1 -1
  98. package/lib/types/buildkit/ops.js +1 -2
  99. package/lib/types/buildkit/ops.js.map +1 -1
  100. package/lib/types/buildkit/rpc.js +1 -2
  101. package/lib/types/buildkit/rpc.js.map +1 -1
  102. package/lib/types/buildx/bake.js +1 -2
  103. package/lib/types/buildx/bake.js.map +1 -1
  104. package/lib/types/buildx/build.js +1 -2
  105. package/lib/types/buildx/build.js.map +1 -1
  106. package/lib/types/buildx/builder.js +1 -2
  107. package/lib/types/buildx/builder.js.map +1 -1
  108. package/lib/types/buildx/buildx.d.ts +1 -1
  109. package/lib/types/buildx/buildx.js +1 -2
  110. package/lib/types/buildx/buildx.js.map +1 -1
  111. package/lib/types/buildx/history.js +1 -2
  112. package/lib/types/buildx/history.js.map +1 -1
  113. package/lib/types/buildx/imagetools.d.ts +3 -3
  114. package/lib/types/buildx/imagetools.js +1 -2
  115. package/lib/types/buildx/imagetools.js.map +1 -1
  116. package/lib/types/compose/compose.d.ts +1 -1
  117. package/lib/types/compose/compose.js +1 -2
  118. package/lib/types/compose/compose.js.map +1 -1
  119. package/lib/types/cosign/cosign.d.ts +1 -1
  120. package/lib/types/cosign/cosign.js +1 -2
  121. package/lib/types/cosign/cosign.js.map +1 -1
  122. package/lib/types/docker/docker.js +1 -2
  123. package/lib/types/docker/docker.js.map +1 -1
  124. package/lib/types/docker/mediatype.js +3 -6
  125. package/lib/types/docker/mediatype.js.map +1 -1
  126. package/lib/types/dockerhub.js +1 -2
  127. package/lib/types/dockerhub.js.map +1 -1
  128. package/lib/types/github/artifact.d.ts +26 -0
  129. package/lib/types/{git.d.ts → github/artifact.js} +3 -3
  130. package/lib/types/github/artifact.js.map +1 -0
  131. package/lib/types/{github.d.ts → github/github.d.ts} +4 -23
  132. package/lib/types/{git.js → github/github.js} +2 -3
  133. package/lib/types/github/github.js.map +1 -0
  134. package/lib/types/github/summary.d.ts +29 -0
  135. package/lib/types/{github.js → github/summary.js} +3 -4
  136. package/lib/types/github/summary.js.map +1 -0
  137. package/lib/types/intoto/intoto.js +2 -5
  138. package/lib/types/intoto/intoto.js.map +1 -1
  139. package/lib/types/intoto/slsa_provenance/v0.2/provenance.js +1 -4
  140. package/lib/types/intoto/slsa_provenance/v0.2/provenance.js.map +1 -1
  141. package/lib/types/oci/config.d.ts +2 -2
  142. package/lib/types/oci/config.js +1 -2
  143. package/lib/types/oci/config.js.map +1 -1
  144. package/lib/types/oci/descriptor.d.ts +1 -1
  145. package/lib/types/oci/descriptor.js +3 -6
  146. package/lib/types/oci/descriptor.js.map +1 -1
  147. package/lib/types/oci/digest.js +1 -2
  148. package/lib/types/oci/digest.js.map +1 -1
  149. package/lib/types/oci/index.d.ts +2 -2
  150. package/lib/types/oci/index.js +1 -2
  151. package/lib/types/oci/index.js.map +1 -1
  152. package/lib/types/oci/layout.js +4 -7
  153. package/lib/types/oci/layout.js.map +1 -1
  154. package/lib/types/oci/manifest.d.ts +2 -2
  155. package/lib/types/oci/manifest.js +1 -2
  156. package/lib/types/oci/manifest.js.map +1 -1
  157. package/lib/types/oci/mediatype.js +6 -9
  158. package/lib/types/oci/mediatype.js.map +1 -1
  159. package/lib/types/oci/oci.d.ts +4 -4
  160. package/lib/types/oci/oci.js +1 -2
  161. package/lib/types/oci/oci.js.map +1 -1
  162. package/lib/types/oci/versioned.js +1 -2
  163. package/lib/types/oci/versioned.js.map +1 -1
  164. package/lib/types/regclient/regclient.d.ts +1 -1
  165. package/lib/types/regclient/regclient.js +1 -2
  166. package/lib/types/regclient/regclient.js.map +1 -1
  167. package/lib/types/sigstore/sigstore.d.ts +11 -2
  168. package/lib/types/sigstore/sigstore.js +4 -7
  169. package/lib/types/sigstore/sigstore.js.map +1 -1
  170. package/lib/types/undock/undock.d.ts +1 -1
  171. package/lib/types/undock/undock.js +1 -2
  172. package/lib/types/undock/undock.js.map +1 -1
  173. package/lib/undock/install.d.ts +2 -2
  174. package/lib/undock/install.js +93 -151
  175. package/lib/undock/install.js.map +1 -1
  176. package/lib/undock/undock.js +88 -141
  177. package/lib/undock/undock.js.map +1 -1
  178. package/lib/util.js +36 -89
  179. package/lib/util.js.map +1 -1
  180. package/package.json +31 -42
  181. package/lib/github.js +0 -421
  182. package/lib/github.js.map +0 -1
  183. package/lib/types/git.js.map +0 -1
  184. package/lib/types/github.js.map +0 -1
@@ -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
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
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 === null || opts === void 0 ? void 0 : opts.standalone;
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 || path_1.default.join(docker_1.Docker.configDir, 'buildx');
36
+ return process.env.BUILDX_CONFIG || path.join(Docker.configDir, 'buildx');
81
37
  }
82
38
  static get refsDir() {
83
- return path_1.default.join(Buildx.configDir, 'refs');
39
+ return path.join(Buildx.configDir, 'refs');
84
40
  }
85
41
  static get refsGroupDir() {
86
- return path_1.default.join(Buildx.refsDir, '__group__');
42
+ return path.join(Buildx.refsDir, '__group__');
87
43
  }
88
44
  static get certsDir() {
89
- return path_1.default.join(Buildx.configDir, 'certs');
45
+ return path.join(Buildx.configDir, 'certs');
90
46
  }
91
- isStandalone() {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- var _a;
94
- const standalone = (_a = this._standalone) !== null && _a !== void 0 ? _a : !(yield docker_1.Docker.isAvailable());
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
- return __awaiter(this, void 0, void 0, function* () {
101
- const standalone = yield this.isStandalone();
102
- return {
103
- command: standalone ? 'buildx' : 'docker',
104
- args: standalone ? args : ['buildx', ...args]
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
- return __awaiter(this, void 0, void 0, function* () {
110
- const cmd = yield this.getCommand([]);
111
- const ok = yield exec_1.Exec.getExecOutput(cmd.command, cmd.args, {
112
- ignoreReturnCode: true,
113
- silent: true
114
- })
115
- .then(res => {
116
- if (res.stderr.length > 0 && res.exitCode != 0) {
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
- core.debug(`Buildx.isAvailable: ${ok}`);
127
- return ok;
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
- return __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
151
- const cmd = yield this.getCommand(['version']);
152
- yield exec_1.Exec.exec(cmd.command, cmd.args, {
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
- return __awaiter(this, void 0, void 0, function* () {
166
- const ver = version !== null && version !== void 0 ? version : (yield this.version());
167
- if (!ver) {
168
- core.debug(`Buildx.versionSatisfies false: undefined version`);
169
- return false;
170
- }
171
- const res = semver.satisfies(ver, range) || /^[0-9a-f]{7}$/.exec(ver) !== null;
172
- core.debug(`Buildx.versionSatisfies ${ver} statisfies ${range}: ${res}`);
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 (_a) {
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 = path_1.default.join(Buildx.certsDir, `cacert_${host}.pem`);
197
- fs_1.default.writeFileSync(cacertpath, cert.cacert);
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 = path_1.default.join(Buildx.certsDir, `cert_${host}.pem`);
202
- fs_1.default.writeFileSync(certpath, cert.cert);
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 = path_1.default.join(Buildx.certsDir, `key_${host}.pem`);
207
- fs_1.default.writeFileSync(keypath, cert.key);
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 = path_1.default.join(dir || Buildx.refsDir, builderName, nodeName, id);
221
- if (!fs_1.default.existsSync(lsPath)) {
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(fs_1.default.readFileSync(lsPath, 'utf8')));
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 = path_1.default.resolve(dir);
205
+ let dirpath = path.resolve(dir);
263
206
  if (opts.builderName) {
264
- dirpath = path_1.default.join(dirpath, opts.builderName);
207
+ dirpath = path.join(dirpath, opts.builderName);
265
208
  }
266
209
  if (opts.nodeName) {
267
- dirpath = path_1.default.join(dirpath, opts.nodeName);
210
+ dirpath = path.join(dirpath, opts.nodeName);
268
211
  }
269
- if (!fs_1.default.existsSync(dirpath)) {
212
+ if (!fs.existsSync(dirpath)) {
270
213
  return refs;
271
214
  }
272
- const files = fs_1.default.readdirSync(dirpath);
215
+ const files = fs.readdirSync(dirpath);
273
216
  for (const file of files) {
274
- const filePath = path_1.default.join(dirpath, file);
275
- const stat = fs_1.default.statSync(filePath);
217
+ const filePath = path.join(dirpath, file);
218
+ const stat = fs.statSync(filePath);
276
219
  if (stat.isDirectory()) {
277
- const nopts = Object.assign({}, opts);
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(fs_1.default.readFileSync(filePath, 'utf8')));
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
- return __awaiter(this, void 0, void 0, function* () {
302
- var _a, _b, _c;
303
- if (warnings.length === 0) {
304
- return;
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
- const fnGitURL = function (inp) {
307
- try {
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
- if (dockerfiles.length === 0) {
375
- core.debug(`Buildx.convertWarningsToGitHubAnnotations: no Dockerfiles found`);
376
- return;
254
+ };
255
+ const fnLocalState = function (ref) {
256
+ try {
257
+ return Buildx.localState(ref, refsDir);
377
258
  }
378
- core.debug(`Buildx.convertWarningsToGitHubAnnotations: found ${dockerfiles.length} Dockerfiles: ${JSON.stringify(dockerfiles, null, 2)}`);
379
- const annotations = [];
380
- for (const warning of warnings) {
381
- if (!warning.detail || !warning.short) {
382
- core.debug(`Buildx.convertWarningsToGitHubAnnotations: skipping warning without detail or short`);
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
- const warningSourceFilename = (_a = warning.sourceInfo) === null || _a === void 0 ? void 0 : _a.filename;
386
- const warningSourceData = (_b = warning.sourceInfo) === null || _b === void 0 ? void 0 : _b.data;
387
- if (!warningSourceFilename || !warningSourceData) {
388
- core.debug(`Buildx.convertWarningsToGitHubAnnotations: skipping warning without source info filename or data`);
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
- const title = warning.detail.map(encoded => atob(encoded)).join(' ');
392
- let message = atob(warning.short).replace(/\s\(line \d+\)$/, '');
393
- if (warning.url) {
394
- // https://github.com/docker/buildx/blob/d8c9ebde1fdcf659f1fa3efa6ccc27a28b0f1564/commands/build.go#L854
395
- message += `\nMore info: ${warning.url}`;
396
- }
397
- // GitHub's annotations don't clearly show ranges of lines, so we'll just
398
- // show the first line: https://github.com/orgs/community/discussions/129899
399
- const startLine = warning.range && warning.range.length > 0 ? (_c = warning.range[0]) === null || _c === void 0 ? void 0 : _c.start.line : undefined;
400
- // TODO: When GitHub's annotations support showing ranges properly, we can use this code
401
- // let startLine: number | undefined, endLine: number | undefined;
402
- // for (const range of warning.range ?? []) {
403
- // if (range.start.line && (!startLine || range.start.line < startLine)) {
404
- // startLine = range.start.line;
405
- // }
406
- // if (range.end.line && (!endLine || range.end.line > endLine)) {
407
- // endLine = range.end.line;
408
- // }
409
- // }
410
- let annotated = false;
411
- for (const dockerfile of dockerfiles) {
412
- // a valid dockerfile path and content is required to match the warning
413
- // source info or always assume it's valid if this is a remote git
414
- // context as we can't read the content of the Dockerfile in this case.
415
- if (dockerfile.remote || (dockerfile.path.endsWith(warningSourceFilename) && dockerfile.content === warningSourceData)) {
416
- annotations.push({
417
- title: title,
418
- message: message,
419
- file: dockerfile.path,
420
- startLine: startLine
421
- });
422
- annotated = true;
423
- break;
424
- }
425
- }
426
- if (!annotated) {
427
- core.debug(`Buildx.convertWarningsToGitHubAnnotations: skipping warning without matching Dockerfile ${warningSourceFilename}: ${title}`);
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
- return annotations;
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