actions-up 1.14.0 → 1.14.2

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 (65) hide show
  1. package/dist/cli/build-json-report.js +18 -18
  2. package/dist/cli/index.js +101 -101
  3. package/dist/cli/merge-scan-results.js +2 -2
  4. package/dist/cli/normalize-update-mode.js +2 -2
  5. package/dist/cli/normalize-update-style.js +2 -2
  6. package/dist/cli/print-mode-warning.js +5 -5
  7. package/dist/cli/print-skipped-warning.js +7 -7
  8. package/dist/cli/resolve-scan-directories.js +8 -8
  9. package/dist/cli/validate-cli-options.js +2 -2
  10. package/dist/core/api/check-updates.js +114 -113
  11. package/dist/core/api/create-github-client.js +26 -26
  12. package/dist/core/api/get-all-releases.js +12 -12
  13. package/dist/core/api/get-all-tags.js +4 -4
  14. package/dist/core/api/get-compatible-update.js +6 -6
  15. package/dist/core/api/get-latest-release.js +15 -15
  16. package/dist/core/api/get-reference-type.js +5 -5
  17. package/dist/core/api/get-tag-info.js +14 -14
  18. package/dist/core/api/get-tag-sha.js +7 -7
  19. package/dist/core/api/internal-rate-limit-error.js +2 -2
  20. package/dist/core/api/make-request.js +4 -4
  21. package/dist/core/api/resolve-github-token-sync.js +7 -7
  22. package/dist/core/api/update-rate-limit-info.js +3 -6
  23. package/dist/core/ast/guards/has-range.js +2 -2
  24. package/dist/core/ast/guards/is-node.js +2 -2
  25. package/dist/core/ast/guards/is-pair.js +2 -2
  26. package/dist/core/ast/guards/is-scalar.js +2 -2
  27. package/dist/core/ast/guards/is-yaml-map.js +2 -2
  28. package/dist/core/ast/guards/is-yaml-sequence.js +2 -2
  29. package/dist/core/ast/scanners/scan-composite-action-ast.js +13 -13
  30. package/dist/core/ast/scanners/scan-workflow-ast.js +21 -21
  31. package/dist/core/ast/update/apply-updates.js +24 -24
  32. package/dist/core/ast/utils/extract-uses-from-steps.js +14 -14
  33. package/dist/core/ast/utils/find-map-pair.js +6 -6
  34. package/dist/core/ast/utils/get-line-number.js +4 -4
  35. package/dist/core/constants.js +2 -2
  36. package/dist/core/filters/parse-exclude-patterns.js +2 -2
  37. package/dist/core/fs/find-yaml-files-recursive.js +9 -9
  38. package/dist/core/fs/is-yaml-file.js +2 -2
  39. package/dist/core/fs/read-yaml-document.js +6 -6
  40. package/dist/core/ignore/should-ignore.js +4 -4
  41. package/dist/core/index.js +5 -5
  42. package/dist/core/interactive/format-version.js +14 -14
  43. package/dist/core/interactive/pad-string.js +4 -4
  44. package/dist/core/interactive/prompt-update-selection.js +153 -138
  45. package/dist/core/interactive/strip-ansi.js +2 -2
  46. package/dist/core/parsing/parse-action-reference.js +2 -2
  47. package/dist/core/scan-action-file.js +6 -6
  48. package/dist/core/scan-github-actions.js +83 -83
  49. package/dist/core/scan-recursive.js +24 -24
  50. package/dist/core/scan-workflow-file.js +6 -6
  51. package/dist/core/schema/composite/is-composite-action-runs.js +2 -2
  52. package/dist/core/schema/composite/is-composite-action-structure.js +2 -2
  53. package/dist/core/schema/workflow/is-workflow-structure.js +2 -2
  54. package/dist/core/updates/resolve-target-reference.js +26 -15
  55. package/dist/core/versions/find-compatible-tag.js +16 -16
  56. package/dist/core/versions/get-update-level.js +8 -8
  57. package/dist/core/versions/is-semver-like.js +2 -2
  58. package/dist/core/versions/is-sha.js +2 -2
  59. package/dist/core/versions/normalize-version.js +4 -4
  60. package/dist/core/versions/preserve-tag-format.d.ts +17 -0
  61. package/dist/core/versions/preserve-tag-format.js +11 -0
  62. package/dist/core/versions/read-inline-version-comment.js +4 -4
  63. package/dist/package.js +2 -2
  64. package/package.json +3 -3
  65. package/readme.md +8 -6
@@ -1,63 +1,63 @@
1
- import { readInlineVersionComment } from "../versions/read-inline-version-comment.js";
2
- import { formatVersion } from "./format-version.js";
3
- import { GITHUB_DIRECTORY } from "../constants.js";
4
- import { isSha } from "../versions/is-sha.js";
5
- import { stripAnsi } from "./strip-ansi.js";
6
- import { padString } from "./pad-string.js";
7
- import path from "node:path";
1
+ import { readInlineVersionComment as e } from "../versions/read-inline-version-comment.js";
2
+ import { formatVersion as t } from "./format-version.js";
3
+ import { GITHUB_DIRECTORY as n } from "../constants.js";
4
+ import { isSha as r } from "../versions/is-sha.js";
5
+ import { stripAnsi as i } from "./strip-ansi.js";
6
+ import { padString as a } from "./pad-string.js";
7
+ import o from "node:path";
8
8
  import "node:worker_threads";
9
- import pc from "picocolors";
10
- import enquirer from "enquirer";
11
- var MIN_ACTION_WIDTH = 40, MIN_JOB_WIDTH = 4, MIN_CURRENT_WIDTH = 16, MAX_VERSION_WIDTH = 7;
12
- async function promptUpdateSelection(b, S = {}) {
13
- let { showAge: C = !1 } = S;
14
- if (b.length === 0) return null;
15
- let w = b.filter((e) => e.hasUpdate);
16
- if (w.length === 0) return console.info(pc.green("✓ All actions are up to date!")), null;
17
- let T = /* @__PURE__ */ new Map();
18
- for (let [e, c] of w.entries()) {
19
- let u = c.action.file ?? "unknown file", d = path.relative(path.join(process.cwd(), GITHUB_DIRECTORY), u);
20
- d === "" && (d = u);
21
- let f = T.get(d) ?? [];
22
- f.push({
23
- update: c,
9
+ import s from "picocolors";
10
+ import c from "enquirer";
11
+ var l = 40, u = 4, d = 16, f = 7;
12
+ async function p(p, T = {}) {
13
+ let { showAge: E = !1 } = T;
14
+ if (p.length === 0) return null;
15
+ let D = p.filter((e) => e.hasUpdate);
16
+ if (D.length === 0) return console.info(s.green("✓ All actions are up to date!")), null;
17
+ let O = /* @__PURE__ */ new Map();
18
+ for (let [e, t] of D.entries()) {
19
+ let r = t.action.file ?? "unknown file", i = o.relative(o.join(process.cwd(), n), r);
20
+ i === "" && (i = r);
21
+ let a = O.get(i) ?? [];
22
+ a.push({
23
+ update: t,
24
24
  index: e
25
- }), T.set(d, f);
25
+ }), O.set(i, a);
26
26
  }
27
- let E = await Promise.all(w.map(async (c) => {
28
- let l = formatVersionOrSha(c.currentVersion), d = c.currentVersion ?? void 0, f = null, p = null;
29
- if (!c.currentVersion || !isSha(c.currentVersion)) return {
30
- versionForPadding: f,
31
- effectiveForDiff: d,
32
- shortSha: p,
33
- display: l
27
+ let k = await Promise.all(D.map(async (t) => {
28
+ let n = v(t.currentVersion), i = t.currentVersion ?? void 0, a = null, o = null;
29
+ if (!t.currentVersion || !r(t.currentVersion)) return {
30
+ versionForPadding: a,
31
+ effectiveForDiff: i,
32
+ shortSha: o,
33
+ display: n
34
34
  };
35
- let m = await readInlineVersionComment(c.action.file, c.action.line);
36
- return m && (p = c.currentVersion.slice(0, 7), f = formatVersionOrSha(m), l = f, d = m), {
37
- versionForPadding: f,
38
- effectiveForDiff: d,
39
- shortSha: p,
40
- display: l
35
+ let s = await e(t.action.file, t.action.line);
36
+ return s && (o = t.currentVersion.slice(0, 7), a = v(s), n = a, i = s), {
37
+ versionForPadding: a,
38
+ effectiveForDiff: i,
39
+ shortSha: o,
40
+ display: n
41
41
  };
42
- })), D = [], O = stripAnsi("Action").length, k = stripAnsi("Current").length, A = stripAnsi("Job").length, j = 0, M = !1;
43
- for (let [e, l] of w.entries()) {
44
- let u = l.action.name, p = E[e], h = p.display, g = l.action.job ?? "–";
45
- if (O = Math.max(O, u.length), k = Math.max(k, stripAnsi(h).length, p.versionForPadding && p.shortSha ? stripAnsi(`${padString(p.versionForPadding, j + 1)}${pc.gray(`(${p.shortSha})`)}`).length : 0), A = Math.max(A, g.length), l.latestVersion) {
46
- let u = formatVersion(l.targetRefStyle === "tag" && l.targetRef ? l.targetRef : l.latestVersion, E[e]?.effectiveForDiff ?? l.currentVersion);
47
- j = Math.max(j, stripAnsi(u).length);
42
+ })), A = [], j = i("Action").length, M = i("Current").length, N = i("Job").length, P = 0, F = !1;
43
+ for (let [e, n] of D.entries()) {
44
+ let r = n.action.name, o = k[e], c = o.display, l = n.action.job ?? "–";
45
+ if (j = Math.max(j, r.length), M = Math.max(M, i(c).length, o.versionForPadding && o.shortSha ? i(`${a(o.versionForPadding, P + 1)}${s.gray(`(${o.shortSha})`)}`).length : 0), N = Math.max(N, l.length), n.latestVersion) {
46
+ let r = t(n.targetRefStyle === "tag" && n.targetRef ? n.targetRef : n.latestVersion, k[e]?.effectiveForDiff ?? n.currentVersion);
47
+ P = Math.max(P, i(r).length);
48
48
  }
49
- let _ = E[e]?.versionForPadding;
50
- _ && (j = Math.max(j, stripAnsi(_).length)), l.publishedAt && (M = !0);
49
+ let u = k[e]?.versionForPadding;
50
+ u && (P = Math.max(P, i(u).length)), n.publishedAt && (F = !0);
51
51
  }
52
- let N = Math.max(O, MIN_ACTION_WIDTH), P = Math.max(k, MIN_CURRENT_WIDTH), F = Math.max(A, MIN_JOB_WIDTH), I = Math.min(j, MAX_VERSION_WIDTH), L = I + 1 + 9, R = C && M ? 6 : 0, z = [...T.keys()].toSorted();
53
- for (let [e, l] of z.entries()) {
54
- let u = T.get(l);
55
- if (!u) {
56
- console.warn(`Unexpected missing group for file: ${l}`);
52
+ let I = Math.max(j, l), L = Math.max(M, d), R = Math.max(N, u), z = Math.min(P, f), B = z + 1 + 9, V = E && F ? 6 : 0, H = [...O.keys()].toSorted();
53
+ for (let [e, n] of H.entries()) {
54
+ let r = O.get(n);
55
+ if (!r) {
56
+ console.warn(`Unexpected missing group for file: ${n}`);
57
57
  continue;
58
58
  }
59
- let d = [], p = u;
60
- d.push({
59
+ let i = [], o = r;
60
+ i.push({
61
61
  current: "Current",
62
62
  action: "Action",
63
63
  target: "Target",
@@ -65,61 +65,61 @@ async function promptUpdateSelection(b, S = {}) {
65
65
  job: "Job",
66
66
  age: "Age"
67
67
  });
68
- for (let { update: e, index: l } of p) {
69
- let u = hasResolvedTarget(e), p = E[l], h = p.display;
70
- p.versionForPadding && p.shortSha && (h = `${padString(p.versionForPadding, I + 1)}${pc.gray(`(${p.shortSha})`)}`);
71
- let g = p.effectiveForDiff ?? e.currentVersion, _ = formatVersion(getTargetVersion(e), g), v = e.action.name;
72
- if (getResolvedTargetStyle(e) === "sha" && getResolvedTarget(e)) {
73
- let c = getResolvedTarget(e).slice(0, 7);
74
- _ = `${padString(_, I + 1)}${pc.gray(`(${c})`)}`;
68
+ for (let { update: e, index: n } of o) {
69
+ let r = w(e), o = k[n], c = o.display;
70
+ o.versionForPadding && o.shortSha && (c = `${a(o.versionForPadding, z + 1)}${s.gray(`(${o.shortSha})`)}`);
71
+ let l = o.effectiveForDiff ?? e.currentVersion, u = t(y(e), l), d = e.action.name;
72
+ if (b(e) === "sha" && S(e)) {
73
+ let t = S(e).slice(0, 7);
74
+ u = `${a(u, z + 1)}${s.gray(`(${t})`)}`;
75
75
  }
76
- u || (_ = pc.gray(_), h = pc.gray(h), v = pc.gray(v));
77
- let y = e.action.job ?? "–", b = formatAge(e.publishedAt);
78
- d.push({
79
- job: u ? y : pc.gray(y),
80
- age: u ? b : pc.gray(b),
81
- action: v,
82
- target: _,
76
+ r || (u = s.gray(u), c = s.gray(c), d = s.gray(d));
77
+ let f = e.action.job ?? "–", p = h(e.publishedAt);
78
+ i.push({
79
+ job: r ? f : s.gray(f),
80
+ age: r ? p : s.gray(p),
81
+ action: d,
82
+ target: u,
83
83
  arrow: "❯",
84
- current: h
84
+ current: c
85
85
  });
86
86
  }
87
- let h = Math.max(N, MIN_ACTION_WIDTH), y = Math.max(P, MIN_CURRENT_WIDTH), b = Math.max(F, MIN_JOB_WIDTH), x = [];
88
- for (let [e, c] of d.entries()) {
89
- let l = e === 0, u = formatTableRow({
90
- targetWidth: L,
91
- currentWidth: y,
92
- actionWidth: h,
93
- ageWidth: R,
94
- jobWidth: b,
95
- row: c
87
+ let c = Math.max(I, l), f = Math.max(L, d), p = Math.max(R, u), m = [];
88
+ for (let [e, t] of i.entries()) {
89
+ let n = e === 0, r = g({
90
+ targetWidth: B,
91
+ currentWidth: f,
92
+ actionWidth: c,
93
+ ageWidth: V,
94
+ jobWidth: p,
95
+ row: t
96
96
  });
97
- if (l) x.push({
98
- message: pc.gray(` ○ ${u}`),
97
+ if (n) m.push({
98
+ message: s.gray(` ○ ${r}`),
99
99
  role: "separator",
100
100
  indent: "",
101
101
  name: ""
102
102
  });
103
103
  else {
104
- let { update: c, index: l } = p[e - 1], d = hasResolvedTarget(c), f = d && !c.isBreaking;
105
- x.push({
106
- message: u,
107
- value: String(l),
108
- disabled: !d,
109
- name: String(l),
104
+ let { update: t, index: n } = o[e - 1], i = w(t), a = i && !t.isBreaking;
105
+ m.push({
106
+ message: r,
107
+ value: String(n),
108
+ disabled: !i,
109
+ name: String(n),
110
110
  indent: "",
111
- enabled: f
111
+ enabled: a
112
112
  });
113
113
  }
114
114
  }
115
- D.push({
116
- message: pc.gray(l),
117
- value: `label|${l}`,
118
- choices: x,
119
- name: `label|${l}`,
115
+ A.push({
116
+ message: s.gray(n),
117
+ value: `label|${n}`,
118
+ choices: m,
119
+ name: `label|${n}`,
120
120
  isGroupLabel: !0,
121
121
  enabled: !1
122
- }), e < z.length - 1 && D.push({
122
+ }), e < H.length - 1 && A.push({
123
123
  role: "separator",
124
124
  message: " ",
125
125
  name: ""
@@ -127,21 +127,26 @@ async function promptUpdateSelection(b, S = {}) {
127
127
  }
128
128
  try {
129
129
  let e = {
130
- indicator(e, c) {
131
- if (c.isGroupLabel) {
132
- let e = (c.choices ?? []).filter((e) => !("role" in e)), l = e.length, u = e.filter((e) => !!e.enabled).length === l ? "●" : "○";
133
- return ` ${pc.gray(u)}`;
130
+ indicator(e, t) {
131
+ if (t.isGroupLabel) {
132
+ let e = (t.choices ?? []).filter((e) => !("role" in e)), n = e.length, r = e.filter((e) => !!e.enabled).length === n ? "●" : "○";
133
+ return ` ${s.gray(r)}`;
134
134
  }
135
- return ` ${c.enabled ? "●" : "○"}`;
135
+ return ` ${t.enabled ? "●" : "○"}`;
136
136
  },
137
- message: `Choose which actions to update (Press ${pc.cyan("<space>")} to select, ${pc.cyan("<a>")} to toggle all, ${pc.cyan("<i>")} to invert selection)`,
137
+ format() {
138
+ if (this.state?.submitted !== !0 || this.state.cancelled === !0) return "";
139
+ let e = _(D, m(Array.isArray(this.value) ? this.value : [], O)).length;
140
+ return e === 0 ? "" : x(e);
141
+ },
142
+ message: `Choose which actions to update (Press ${s.cyan("<space>")} to select, ${s.cyan("<a>")} to toggle all, ${s.cyan("<i>")} to invert selection)`,
138
143
  styles: {
139
- success: pc.reset,
140
- em: pc.bgBlack,
141
- dark: pc.reset
144
+ success: s.reset,
145
+ em: s.bgBlack,
146
+ dark: s.reset
142
147
  },
143
148
  cancel() {
144
- return logSelectionCancelled(), null;
149
+ return C(), null;
145
150
  },
146
151
  j() {
147
152
  return this.down?.() ?? Promise.resolve([]);
@@ -153,56 +158,66 @@ async function promptUpdateSelection(b, S = {}) {
153
158
  type: "multiselect",
154
159
  name: "selected",
155
160
  pointer: "❯",
156
- choices: D
157
- }, { selected: c } = await enquirer.prompt(e), l = /* @__PURE__ */ new Set();
158
- for (let e of c) {
159
- if (e.startsWith("label|")) {
160
- let c = e.slice(6), u = T.get(c) ?? [];
161
- for (let { update: e, index: c } of u) hasResolvedTarget(e) && l.add(c);
162
- continue;
163
- }
164
- let c = Number.parseInt(e, 10);
165
- Number.isFinite(c) && l.add(c);
166
- }
167
- let u = [];
168
- for (let [e, c] of w.entries()) l.has(e) && hasResolvedTarget(c) && u.push(c);
169
- return u.length === 0 ? (console.info(pc.yellow("\nNo actions selected")), null) : u;
161
+ choices: A
162
+ }, { selected: t } = await c.prompt(e), n = _(D, m(t, O));
163
+ return n.length === 0 ? (console.info(s.yellow("\nNo actions selected")), null) : n;
170
164
  } catch (e) {
171
- if (e instanceof Error && (e.message.includes("cancelled") || e.message.includes("ESC") || e.name === "ExitPromptError")) return logSelectionCancelled(), null;
172
- throw console.error(pc.red("Unexpected error during selection:"), e), e;
165
+ if (e instanceof Error && (e.message.includes("cancelled") || e.message.includes("ESC") || e.name === "ExitPromptError")) return C(), null;
166
+ throw console.error(s.red("Unexpected error during selection:"), e), e;
173
167
  }
174
168
  }
175
- function formatAge(e) {
169
+ function m(e, t) {
170
+ let n = /* @__PURE__ */ new Set();
171
+ for (let r of e) {
172
+ if (r.startsWith("label|")) {
173
+ let e = r.slice(6), i = t.get(e) ?? [];
174
+ for (let { update: e, index: t } of i) w(e) && n.add(t);
175
+ continue;
176
+ }
177
+ let e = Number.parseInt(r, 10);
178
+ Number.isFinite(e) && n.add(e);
179
+ }
180
+ return n;
181
+ }
182
+ function h(e) {
176
183
  if (!e) return "";
177
- let c = Date.now() - e.getTime(), l = Math.floor(c / (1e3 * 60 * 60)), u = Math.floor(l / 24), d = Math.floor(u / 7), f = u % 7;
178
- return d >= 1 ? f > 0 ? `${d}w ${f}d` : `${d}w` : u >= 1 ? `${u}d` : `${l}h`;
184
+ let t = Date.now() - e.getTime(), n = Math.floor(t / (1e3 * 60 * 60)), r = Math.floor(n / 24), i = Math.floor(r / 7), a = r % 7;
185
+ return i >= 1 ? a > 0 ? `${i}w ${a}d` : `${i}w` : r >= 1 ? `${r}d` : `${n}h`;
179
186
  }
180
- function formatTableRow(e) {
181
- let { currentWidth: c, actionWidth: l, targetWidth: u, jobWidth: d, ageWidth: p, row: m } = e, h = [
182
- padString(m.action, l),
183
- padString(m.job, d),
184
- padString(m.current, c),
185
- m.arrow,
186
- padString(m.target, u)
187
+ function g(e) {
188
+ let { currentWidth: t, actionWidth: n, targetWidth: r, jobWidth: i, ageWidth: o, row: s } = e, c = [
189
+ a(s.action, n),
190
+ a(s.job, i),
191
+ a(s.current, t),
192
+ s.arrow,
193
+ a(s.target, r)
187
194
  ];
188
- return p > 0 && h.push(m.age), h.join(" ").replace(/\s+$/u, "");
195
+ return o > 0 && c.push(s.age), c.join(" ").replace(/\s+$/u, "");
189
196
  }
190
- function formatVersionOrSha(e) {
191
- return e ? isSha(e) ? e.slice(0, 7) : e.replace(/^v/u, "") : pc.gray("unknown");
197
+ function _(e, t) {
198
+ let n = [];
199
+ for (let [r, i] of e.entries()) t.has(r) && w(i) && n.push(i);
200
+ return n;
192
201
  }
193
- function getTargetVersion(e) {
194
- return getResolvedTargetStyle(e) === "tag" && getResolvedTarget(e) ? getResolvedTarget(e) : e.latestVersion;
202
+ function v(e) {
203
+ return e ? r(e) ? e.slice(0, 7) : e.replace(/^v/u, "") : s.gray("unknown");
195
204
  }
196
- function getResolvedTargetStyle(e) {
205
+ function y(e) {
206
+ return b(e) === "tag" && S(e) ? S(e) : e.latestVersion;
207
+ }
208
+ function b(e) {
197
209
  return e.targetRefStyle ? e.targetRefStyle : e.latestSha ? "sha" : null;
198
210
  }
199
- function getResolvedTarget(e) {
211
+ function x(e) {
212
+ return `${e} ${e === 1 ? "action" : "actions"} selected`;
213
+ }
214
+ function S(e) {
200
215
  return e.targetRef ? e.targetRef : e.latestSha;
201
216
  }
202
- function logSelectionCancelled() {
203
- console.info(`\r\u001B[K${pc.yellow("Selection cancelled")}`);
217
+ function C() {
218
+ console.info(`\r\u001B[K${s.yellow("Selection cancelled")}`);
204
219
  }
205
- function hasResolvedTarget(e) {
206
- return !!getResolvedTarget(e);
220
+ function w(e) {
221
+ return !!S(e);
207
222
  }
208
- export { promptUpdateSelection };
223
+ export { p as promptUpdateSelection };
@@ -1,4 +1,4 @@
1
- function stripAnsi(e) {
1
+ function e(e) {
2
2
  let t = "", n = 0;
3
3
  for (; n < e.length;) if (e.charCodeAt(n) === 27 && n + 1 < e.length && e[n + 1] === "[") for (n += 2; n < e.length;) {
4
4
  let r = e[n];
@@ -11,4 +11,4 @@ function stripAnsi(e) {
11
11
  else t += e[n], n++;
12
12
  return t;
13
13
  }
14
- export { stripAnsi };
14
+ export { e as stripAnsi };
@@ -1,4 +1,4 @@
1
- function parseActionReference(e, t, n) {
1
+ function e(e, t, n) {
2
2
  if (!e || e.trim() === "") return null;
3
3
  if (e.startsWith("docker://")) return {
4
4
  version: void 0,
@@ -31,4 +31,4 @@ function parseActionReference(e, t, n) {
31
31
  line: n
32
32
  };
33
33
  }
34
- export { parseActionReference };
34
+ export { e as parseActionReference };
@@ -1,7 +1,7 @@
1
- import { scanCompositeActionAst } from "./ast/scanners/scan-composite-action-ast.js";
2
- import { readYamlDocument } from "./fs/read-yaml-document.js";
3
- async function scanActionFile(n) {
4
- let { document: r, content: i } = await readYamlDocument(n);
5
- return scanCompositeActionAst(r, i, n);
1
+ import { scanCompositeActionAst as e } from "./ast/scanners/scan-composite-action-ast.js";
2
+ import { readYamlDocument as t } from "./fs/read-yaml-document.js";
3
+ async function n(n) {
4
+ let { document: r, content: i } = await t(n);
5
+ return e(r, i, n);
6
6
  }
7
- export { scanActionFile };
7
+ export { n as scanActionFile };
@@ -1,156 +1,156 @@
1
- import { ACTIONS_DIRECTORY, GITHUB_DIRECTORY, WORKFLOWS_DIRECTORY } from "./constants.js";
2
- import { isYamlFile } from "./fs/is-yaml-file.js";
3
- import { scanWorkflowFile } from "./scan-workflow-file.js";
4
- import { scanActionFile } from "./scan-action-file.js";
5
- import { isAbsolute, join, relative, resolve } from "node:path";
6
- import { readFile, readdir, stat } from "node:fs/promises";
7
- async function scanGitHubActions(p = process.cwd(), m = GITHUB_DIRECTORY) {
1
+ import { ACTIONS_DIRECTORY as e, GITHUB_DIRECTORY as t, WORKFLOWS_DIRECTORY as n } from "./constants.js";
2
+ import { isYamlFile as r } from "./fs/is-yaml-file.js";
3
+ import { scanWorkflowFile as i } from "./scan-workflow-file.js";
4
+ import { scanActionFile as a } from "./scan-action-file.js";
5
+ import { isAbsolute as o, join as s, relative as c, resolve as l } from "node:path";
6
+ import { readFile as u, readdir as d, stat as f } from "node:fs/promises";
7
+ async function p(u = process.cwd(), p = t) {
8
8
  let h = {
9
9
  compositeActions: /* @__PURE__ */ new Map(),
10
10
  workflows: /* @__PURE__ */ new Map(),
11
11
  actions: []
12
- }, g = resolve(p);
13
- function _(e, a) {
14
- let o = relative(e, a);
15
- return o !== "" && !o.startsWith("..") && !isAbsolute(o);
12
+ }, g = l(u);
13
+ function _(e, t) {
14
+ let n = c(e, t);
15
+ return n !== "" && !n.startsWith("..") && !o(n);
16
16
  }
17
- let v = join(g, m);
17
+ let v = s(g, p);
18
18
  function y(e) {
19
19
  return e.includes("..") || e.includes("/") || e.includes("\\") ? (console.warn(`Skipping invalid name: ${e}`), !1) : !0;
20
20
  }
21
21
  async function b(e) {
22
22
  try {
23
- let a = await stat(e);
24
- return typeof a.isFile == "function" ? a.isFile() : !1;
23
+ let t = await f(e);
24
+ return typeof t.isFile == "function" ? t.isFile() : !1;
25
25
  } catch {
26
26
  return !1;
27
27
  }
28
28
  }
29
- let x = join(v, WORKFLOWS_DIRECTORY);
29
+ let x = s(v, n);
30
30
  try {
31
- if ((await stat(x)).isDirectory()) {
32
- let e = (await readdir(x)).filter((e) => y(e) ? isYamlFile(e) : !1).map(async (e) => {
33
- let a = join(x, e);
31
+ if ((await f(x)).isDirectory()) {
32
+ let e = (await d(x)).filter((e) => y(e) ? r(e) : !1).map(async (e) => {
33
+ let t = s(x, e);
34
34
  try {
35
- let s = await scanWorkflowFile(a);
35
+ let r = await i(t);
36
36
  return {
37
- path: `${m}/${WORKFLOWS_DIRECTORY}/${e}`,
37
+ path: `${p}/${n}/${e}`,
38
38
  success: !0,
39
- actions: s
39
+ actions: r
40
40
  };
41
41
  } catch {
42
42
  return {
43
- path: `${m}/${WORKFLOWS_DIRECTORY}/${e}`,
43
+ path: `${p}/${n}/${e}`,
44
44
  success: !1,
45
45
  actions: []
46
46
  };
47
47
  }
48
- }), a = await Promise.all(e);
49
- for (let e of a) e.success && e.path && (e.actions.length > 0 ? (h.workflows.set(e.path, e.actions), h.actions.push(...e.actions)) : h.workflows.set(e.path, []));
48
+ }), t = await Promise.all(e);
49
+ for (let e of t) e.success && e.path && (e.actions.length > 0 ? (h.workflows.set(e.path, e.actions), h.actions.push(...e.actions)) : h.workflows.set(e.path, []));
50
50
  }
51
51
  } catch {}
52
52
  try {
53
- let e = join(g, "action.yml"), a = join(g, "action.yaml"), o = null, s = [];
53
+ let e = s(g, "action.yml"), t = s(g, "action.yaml"), n = null, r = [];
54
54
  if (await b(e)) try {
55
- s = await scanActionFile(e), o = e;
55
+ r = await a(e), n = e;
56
56
  } catch {
57
- o = null;
57
+ n = null;
58
58
  }
59
- if (!o && await b(a)) try {
60
- s = await scanActionFile(a), o = a;
59
+ if (!n && await b(t)) try {
60
+ r = await a(t), n = t;
61
61
  } catch {
62
- o = null;
62
+ n = null;
63
63
  }
64
- if (o) {
65
- let e = relative(g, o);
66
- h.compositeActions.set(e, e), s.length > 0 && h.actions.push(...s);
64
+ if (n) {
65
+ let e = c(g, n);
66
+ h.compositeActions.set(e, e), r.length > 0 && h.actions.push(...r);
67
67
  }
68
68
  } catch {}
69
- let S = join(v, ACTIONS_DIRECTORY);
69
+ let S = s(v, e);
70
70
  try {
71
- if ((await stat(S)).isDirectory()) {
72
- let a = (await readdir(S)).map(async (a) => {
73
- if (!y(a)) return null;
74
- let o = join(S, a);
71
+ if ((await f(S)).isDirectory()) {
72
+ let t = (await d(S)).map(async (t) => {
73
+ if (!y(t)) return null;
74
+ let n = s(S, t);
75
75
  try {
76
- if (!(await stat(o)).isDirectory()) return null;
77
- let s = join(o, "action.yml"), c = [];
76
+ if (!(await f(n)).isDirectory()) return null;
77
+ let r = s(n, "action.yml"), i = [];
78
78
  try {
79
- c = await scanActionFile(s);
79
+ i = await a(r);
80
80
  } catch {
81
81
  try {
82
- s = join(o, "action.yaml"), c = await scanActionFile(s);
82
+ r = s(n, "action.yaml"), i = await a(r);
83
83
  } catch {
84
84
  return null;
85
85
  }
86
86
  }
87
87
  return {
88
- path: `${m}/${ACTIONS_DIRECTORY}/${a}`,
89
- name: a,
90
- actions: c
88
+ path: `${p}/${e}/${t}`,
89
+ name: t,
90
+ actions: i
91
91
  };
92
92
  } catch {
93
93
  return null;
94
94
  }
95
- }), o = await Promise.all(a);
96
- for (let e of o) e && (h.compositeActions.set(e.name, e.path), h.actions.push(...e.actions));
95
+ }), n = await Promise.all(t);
96
+ for (let e of n) e && (h.compositeActions.set(e.name, e.path), h.actions.push(...e.actions));
97
97
  }
98
98
  } catch {}
99
99
  try {
100
- let e = await getCurrentRepoSlug(g);
100
+ let e = await m(g);
101
101
  if (e) {
102
102
  if (process.env.ACTIONS_UP_TEST_THROW === "1") throw Error("test");
103
- let a = /* @__PURE__ */ new Set(), o = [];
104
- for (let s of h.actions) {
105
- if (s.type !== "external") continue;
106
- let c = s.name.split("/");
107
- if (c.length < 3 || `${c[0]}/${c[1]}` !== e) continue;
108
- let l = join(g, ...c.slice(2));
109
- _(g, l) && (a.has(l) || (a.add(l), o.push(l)));
103
+ let t = /* @__PURE__ */ new Set(), n = [];
104
+ for (let r of h.actions) {
105
+ if (r.type !== "external") continue;
106
+ let i = r.name.split("/");
107
+ if (i.length < 3 || `${i[0]}/${i[1]}` !== e) continue;
108
+ let a = s(g, ...i.slice(2));
109
+ _(g, a) && (t.has(a) || (t.add(a), n.push(a)));
110
110
  }
111
- async function s() {
112
- if (o.length === 0) return;
113
- let c = o.splice(0), u = await Promise.all(c.map(async (o) => {
111
+ async function r() {
112
+ if (n.length === 0) return;
113
+ let i = n.splice(0), o = await Promise.all(i.map(async (n) => {
114
114
  try {
115
- let s = join(o, "action.yml"), c = join(o, "action.yaml"), u = s;
115
+ let r = s(n, "action.yml"), i = s(n, "action.yaml"), o = r;
116
116
  try {
117
- if (!(await stat(s)).isFile()) throw Error("not a file");
117
+ if (!(await f(r)).isFile()) throw Error("not a file");
118
118
  } catch {
119
- if (!(await stat(c)).isFile()) throw Error("not a file");
120
- u = c;
119
+ if (!(await f(i)).isFile()) throw Error("not a file");
120
+ o = i;
121
121
  }
122
- let d = await scanActionFile(u);
123
- d.length > 0 && h.actions.push(...d);
124
- let f = [];
125
- for (let o of d) {
126
- if (o.type !== "external") continue;
127
- let s = o.name.split("/");
128
- if (s.length < 3 || `${s[0]}/${s[1]}` !== e) continue;
129
- let c = join(g, ...s.slice(2));
130
- _(g, c) && (a.has(c) || (a.add(c), f.push(c)));
122
+ let c = await a(o);
123
+ c.length > 0 && h.actions.push(...c);
124
+ let l = [];
125
+ for (let n of c) {
126
+ if (n.type !== "external") continue;
127
+ let r = n.name.split("/");
128
+ if (r.length < 3 || `${r[0]}/${r[1]}` !== e) continue;
129
+ let i = s(g, ...r.slice(2));
130
+ _(g, i) && (t.has(i) || (t.add(i), l.push(i)));
131
131
  }
132
- return f;
132
+ return l;
133
133
  } catch {
134
134
  return [];
135
135
  }
136
136
  }));
137
- for (let e of u) for (let a of e) o.push(a);
138
- await s();
137
+ for (let e of o) for (let t of e) n.push(t);
138
+ await r();
139
139
  }
140
- await s();
140
+ await r();
141
141
  }
142
142
  } catch {}
143
143
  return h;
144
144
  }
145
- async function getCurrentRepoSlug(e) {
146
- let a = process.env.GITHUB_REPOSITORY;
147
- if (a && /^[^\s/]+\/[^\s/]+$/u.test(a)) return a;
145
+ async function m(e) {
146
+ let t = process.env.GITHUB_REPOSITORY;
147
+ if (t && /^[^\s/]+\/[^\s/]+$/u.test(t)) return t;
148
148
  try {
149
- let a = await readFile(join(e, ".git", "config"), "utf8"), o = a.match(/\[remote "origin"\][\s\S]*?url\s*=\s*(?<url>.+)/u)?.groups?.url?.trim();
150
- if (o ||= a.match(/url\s*=\s*(?<url>.+)/u)?.groups?.url?.trim(), !o) return null;
151
- let s = o.match(/github\.com[/:](?<owner>[^/]+)\/(?<repo>[^./]+)(?:\.git)?$/u);
152
- if (s?.groups) return `${s.groups.owner}/${s.groups.repo}`;
149
+ let t = await u(s(e, ".git", "config"), "utf8"), n = t.match(/\[remote "origin"\][\s\S]*?url\s*=\s*(?<url>.+)/u)?.groups?.url?.trim();
150
+ if (n ||= t.match(/url\s*=\s*(?<url>.+)/u)?.groups?.url?.trim(), !n) return null;
151
+ let r = n.match(/github\.com[/:](?<owner>[^/]+)\/(?<repo>[^./]+)(?:\.git)?$/u);
152
+ if (r?.groups) return `${r.groups.owner}/${r.groups.repo}`;
153
153
  } catch {}
154
154
  return null;
155
155
  }
156
- export { scanGitHubActions };
156
+ export { p as scanGitHubActions };