@sapphire-sh/utils 2.11.0 → 2.12.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.
@@ -14,6 +14,9 @@ const obsoleteFiles = new Set([join('.github', 'workflows', 'utils-update.yml')]
14
14
  const workflowsDir = join('.github', 'workflows');
15
15
  const workflowValuesPath = join('.github', 'sapphire-workflows.json');
16
16
  const withLinePattern = /^\s*with:\s*$/m;
17
+ const pathsIgnoreLinePattern = /^\s*paths-ignore:\s*$/m;
18
+ const pushBlockPattern = /^on:\n(?:[ \t].*\n|\n)*? {2}push:\n((?: {4}.*\n|\n)*)/m;
19
+ const branchesListPattern = /^ {2}push:\n {4}branches:\n(?: {6}- .*\n)*/m;
17
20
  const requiredFiles = new Map([[join(workflowsDir, 'docker-publish.yml'), 'Dockerfile']]);
18
21
 
19
22
  const sectioned = new Set(['.gitignore', '.prettierignore']);
@@ -89,15 +92,33 @@ const writeWorkflow = (outputName, template) => {
89
92
  console.log(`warning: ${outputName} had with: values that are not in ${workflowValuesPath}`);
90
93
  }
91
94
  } else {
95
+ const { 'paths-ignore': pathsIgnore, ...withValues } = values;
96
+
97
+ if (pathsIgnore !== undefined) {
98
+ const pathsIgnoreLines = pathsIgnore.map((value) => ` - ${JSON.stringify(value)}\n`).join('');
99
+ content = content.replace(
100
+ branchesListPattern,
101
+ (branchesList) => `${branchesList} paths-ignore:\n${pathsIgnoreLines}`,
102
+ );
103
+ }
104
+
92
105
  if (withLinePattern.test(template) === false) {
93
106
  content += ' with:\n';
94
107
  }
95
108
 
96
- for (const [key, value] of Object.entries(values)) {
109
+ for (const [key, value] of Object.entries(withValues)) {
97
110
  content += ` ${key}: ${JSON.stringify(value)}\n`;
98
111
  }
99
112
  }
100
113
 
114
+ if (
115
+ (values === undefined || Object.hasOwn(values, 'paths-ignore') === false) &&
116
+ existsSync(filepath) &&
117
+ pathsIgnoreLinePattern.test(readFileSync(filepath, 'utf-8'))
118
+ ) {
119
+ console.log(`warning: ${outputName} had paths-ignore values that are not in ${workflowValuesPath}`);
120
+ }
121
+
101
122
  mkdirSync(dirname(filepath), { recursive: true });
102
123
  writeFileSync(filepath, content);
103
124
  console.log(`wrote ${outputName}`);
@@ -119,6 +140,23 @@ const collectTemplates = (directory, prefix) => {
119
140
  return relativePaths;
120
141
  };
121
142
 
143
+ for (const [name, values] of Object.entries(workflowValues)) {
144
+ const callerPath = join(workflowsDir, `${name}.yml`);
145
+
146
+ if (Object.hasOwn(values, 'paths-ignore') === false) {
147
+ continue;
148
+ }
149
+
150
+ const pushBlock = pushBlockPattern.exec(readFileSync(join(templatesDir, callerPath), 'utf-8'));
151
+
152
+ if (pushBlock === null || /^ {4}paths:/m.test(pushBlock[1])) {
153
+ console.error(
154
+ `error: ${workflowValuesPath} sets paths-ignore for ${callerPath}, whose template has no push trigger without paths`,
155
+ );
156
+ process.exit(1);
157
+ }
158
+ }
159
+
122
160
  for (const relativePath of collectTemplates(templatesDir, '')) {
123
161
  const outputName = renameMap.get(relativePath) ?? relativePath;
124
162
  const outputPath = join(cwd, outputName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire-sh/utils",
3
- "version": "2.11.0",
3
+ "version": "2.12.0",
4
4
  "description": "@sapphire-sh/utils",
5
5
  "type": "module",
6
6
  "sideEffects": false,