Skip to content

Commit d30e1d4

Browse files
authored
better ci matrix (csstools#188)
* better CI matrix * only annotate in node 16 + ubuntu * fixes * fixes * fixes * avoid absolute paths by self referencing a plugin by it's name * wip * wip * wip * wip
1 parent f88ba66 commit d30e1d4

7 files changed

Lines changed: 65 additions & 36 deletions

File tree

.github/workflows/test.yml

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,47 @@ concurrency:
77
cancel-in-progress: true
88

99
jobs:
10-
test_with_workspaces_support:
11-
runs-on: ubuntu-latest
10+
test:
11+
runs-on: ${{ matrix.os }}
1212
strategy:
13+
# Test node 16/17 on ubuntu
14+
# Test node 16 on macos/windows
15+
# Enable annotations only for node 16 + ubuntu
1316
matrix:
17+
os: [ubuntu-latest]
1418
node: [16, 17]
19+
include:
20+
- os: macos-latest
21+
node: 16
22+
- os: windows-latest
23+
node: 16
24+
- node: 16
25+
enable_annotations_for_node: true
26+
- os: ubuntu-latest
27+
enable_annotations_for_os: true
1528
steps:
1629
- uses: actions/checkout@v2
1730
- uses: actions/setup-node@v2.5.1
1831
with:
1932
node-version: ${{ matrix.node }}
2033

34+
# Build, lint and PostCSS Tape tests must all work and pass :
35+
# - with exact dependencies from package-lock.json
36+
# - without requiring postinstall scripts from dependencies to run
2137
- run: npm ci --ignore-scripts
2238
- run: npm run build --workspaces --if-present
2339
- run: npm run lint --workspaces --if-present
24-
- run: npm run test --workspaces --if-present
2540

26-
# Run cross platform test of the basic CLI.
27-
test_cli:
28-
runs-on: ${{ matrix.os }}
29-
strategy:
30-
matrix:
31-
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
32-
steps:
33-
- uses: actions/checkout@v2
34-
- uses: actions/setup-node@v2.5.1
35-
with:
36-
node-version: 16
37-
38-
- run: npm ci --ignore-scripts
39-
- run: npm run build --workspaces --if-present
41+
# PostCSS Tape tests
42+
- run: npm run test --workspaces --if-present
43+
env:
44+
ENABLE_ANNOTATIONS_FOR_NODE: ${{ matrix.enable_annotations_for_node }}
45+
ENABLE_ANNOTATIONS_FOR_OS: ${{ matrix.enable_annotations_for_os }}
4046

47+
# CLI Tests
4148
# running "npm install" places the cli in node_modules/bin
4249
- run: npm install --ignore-scripts
43-
44-
- run: |
45-
npm run test --workspace="@csstools/base-cli"
46-
npm run test:cli --workspace="@csstools/postcss-base-plugin"
50+
- run: npm run test:cli --workspace="@csstools/postcss-base-plugin"
4751

4852
# Run Deno tests one by one
4953
test_deno:

packages/postcss-tape/src/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { formatGitHubActionAnnotation } from './github-annotations';
1111
import { dashesSeparator, formatCSSAssertError, formatWarningsAssertError } from './format-asserts';
1212
import noopPlugin from './noop-plugin';
1313

14+
const emitGitHubAnnotations = process.env.GITHUB_ACTIONS && process.env.ENABLE_ANNOTATIONS_FOR_NODE === 'true' && process.env.ENABLE_ANNOTATIONS_FOR_OS === 'true';
15+
1416
type TestCaseOptions = {
1517
// Debug message
1618
message?: string,
@@ -40,7 +42,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
4042
if (currentPlugin.postcss !== true) {
4143
hasErrors = true;
4244

43-
if (process.env.GITHUB_ACTIONS) {
45+
if (emitGitHubAnnotations) {
4446
console.log(formatGitHubActionAnnotation(
4547
'postcss flag not set to "true" on exported plugin object',
4648
'error',
@@ -57,7 +59,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
5759
if (!plugin.postcssPlugin || typeof plugin.postcssPlugin !== 'string') {
5860
hasErrors = true;
5961

60-
if (process.env.GITHUB_ACTIONS) {
62+
if (emitGitHubAnnotations) {
6163
console.log(formatGitHubActionAnnotation(
6264
'plugin name not set via "postcssPlugin"',
6365
'error',
@@ -74,7 +76,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
7476
if (!packageInfo.keywords.includes('postcss-plugin')) {
7577
hasErrors = true;
7678

77-
if (process.env.GITHUB_ACTIONS) {
79+
if (emitGitHubAnnotations) {
7880
console.log(formatGitHubActionAnnotation(
7981
'package.json does not include "postcss-plugin" keyword',
8082
'error',
@@ -90,7 +92,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
9092
if (!packageInfo.name.startsWith('postcss-') && !packageInfo.name.startsWith('@csstools/postcss-')) {
9193
hasErrors = true;
9294

93-
if (process.env.GITHUB_ACTIONS) {
95+
if (emitGitHubAnnotations) {
9496
console.log(formatGitHubActionAnnotation(
9597
'plugin name in package.json does not start with "postcss-"',
9698
'error',
@@ -106,7 +108,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
106108
if (Object.keys(Object(packageInfo.dependencies)).includes('postcss') && !('postcssTapeSelfTest' in currentPlugin)) {
107109
hasErrors = true;
108110

109-
if (process.env.GITHUB_ACTIONS) {
111+
if (emitGitHubAnnotations) {
110112
console.log(formatGitHubActionAnnotation(
111113
'postcss should only be a peer and/or dev dependency',
112114
'error',
@@ -154,14 +156,14 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
154156
hasErrors = true;
155157
expected = false;
156158

157-
if (process.env.GITHUB_ACTIONS) {
159+
if (emitGitHubAnnotations) {
158160
console.log(formatGitHubActionAnnotation(
159-
`${testCaseLabel}\n\nmissing or broken "expect" file: "${expectFilePath}"`,
161+
`${testCaseLabel}\n\nmissing or broken "expect" file: "${path.parse(expectFilePath).base}"`,
160162
'error',
161163
{ file: testFilePath, line: 1, col: 1 },
162164
));
163165
} else {
164-
console.error(`\n${testCaseLabel}\n\nmissing or broken "expect" file: "${expectFilePath}"\n\n${dashesSeparator}`);
166+
console.error(`\n${testCaseLabel}\n\nmissing or broken "expect" file: "${path.parse(expectFilePath).base}"\n\n${dashesSeparator}`);
165167
}
166168
}
167169

@@ -195,7 +197,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
195197
} catch (err) {
196198
hasErrors = true;
197199

198-
if (process.env.GITHUB_ACTIONS) {
200+
if (emitGitHubAnnotations) {
199201
console.log(formatGitHubActionAnnotation(
200202
formatCSSAssertError(testCaseLabel, testCaseOptions, err, true),
201203
'error',
@@ -216,7 +218,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
216218
} catch (err) {
217219
hasErrors = true;
218220

219-
if (process.env.GITHUB_ACTIONS) {
221+
if (emitGitHubAnnotations) {
220222
console.log(formatGitHubActionAnnotation(
221223
`${testCaseLabel}\n\nbroken source map: ${JSON.stringify(result.map.toJSON().sources)}`,
222224
'error',
@@ -252,7 +254,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
252254
} catch (_) {
253255
hasErrors = true;
254256

255-
if (process.env.GITHUB_ACTIONS) {
257+
if (emitGitHubAnnotations) {
256258
console.log(formatGitHubActionAnnotation(
257259
`${testCaseLabel}\n\nresult was not parsable with PostCSS.`,
258260
'error',
@@ -287,7 +289,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
287289
} catch (err) {
288290
hasErrors = true;
289291

290-
if (process.env.GITHUB_ACTIONS) {
292+
if (emitGitHubAnnotations) {
291293
console.log(formatGitHubActionAnnotation(
292294
'testing older PostCSS:\n' + formatCSSAssertError(testCaseLabel, testCaseOptions, err, true),
293295
'error',
@@ -308,7 +310,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
308310
} catch (err) {
309311
hasErrors = true;
310312

311-
if (process.env.GITHUB_ACTIONS) {
313+
if (emitGitHubAnnotations) {
312314
console.log(formatGitHubActionAnnotation(
313315
formatWarningsAssertError(testCaseLabel, testCaseOptions, result.warnings().length, testCaseOptions.warnings, true),
314316
'error',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
basic:without-expect
33

4-
missing or broken "expect" file: "test/basic.without-expect.expect.css"
4+
missing or broken "expect" file: "basic.without-expect.expect.css"
55

66
----------------------------------------

plugins/postcss-custom-properties/.tape.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ postcssTape(plugin)({
7373
expect: 'basic.import.expect.css',
7474
result: 'basic.import.result.css'
7575
},
76+
'basic:import-cjs': {
77+
message: 'supports { importFrom: "test/import-properties{-2}?.cjs" } usage',
78+
options: {
79+
importFrom: [
80+
'test/import-properties.cjs',
81+
'test/import-properties-2.cjs'
82+
]
83+
},
84+
expect: 'basic.import.expect.css',
85+
result: 'basic.import.result.css'
86+
},
7687
'basic:import-mjs': {
7788
message: 'supports { importFrom: "test/import-properties{-2}?.mjs" } usage',
7889
options: {

plugins/postcss-custom-properties/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Unreleased
44

55
- Fix `.mjs` in `importFrom` when using `export default`
6+
- Fix `.mjs` in `importFrom` on Windows
67

78
### 12.1.3 (January 17, 2022)
89

plugins/postcss-custom-properties/src/lib/get-custom-properties-from-imports.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import getCustomPropertiesFromRoot from './get-custom-properties-from-root';
22
import path from 'path';
3+
import { pathToFileURL } from 'url';
34
import type { ImportCustomProperties, ImportOptions } from './options';
45
import valuesParser from 'postcss-value-parser';
56
import { parse } from 'postcss';
@@ -49,7 +50,15 @@ async function getCustomPropertiesFromJSONFile(from): Promise<Map<string, values
4950
/* ========================================================================== */
5051

5152
async function getCustomPropertiesFromJSFile(from): Promise<Map<string, valuesParser.ParsedValue>> {
52-
const object = await import(from);
53+
let object;
54+
55+
try {
56+
object = await import(from);
57+
} catch (_) {
58+
// windows support
59+
object = await import(pathToFileURL(from).href);
60+
}
61+
5362
if ('default' in object) {
5463
return getCustomPropertiesFromObject(object.default);
5564
}

rollup/configs/externals.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const externalsForCLI = [
22
'fs',
33
'path',
4+
'url',
45

56
'autoprefixer',
67
'browserslist',
@@ -44,6 +45,7 @@ export const externalsForPlugin = [
4445
'assert',
4546
'fs',
4647
'path',
48+
'url',
4749

4850
'postcss',
4951
/^postcss-\d\.\d$/,

0 commit comments

Comments
 (0)