Skip to content

Commit

Permalink
Merge branch 'main' into re-add-winston
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott authored Aug 1, 2024
2 parents bc73fe5 + ee13170 commit a1f5673
Show file tree
Hide file tree
Showing 41 changed files with 718 additions and 393 deletions.
25 changes: 0 additions & 25 deletions .eslintrc.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/close-stalled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Close stalled issues and PRs
on:
schedule:
- cron: 0 0 * * *

env:
CLOSE_MESSAGE: >
Closing this because it has stalled. Feel free to reopen if this issue/PR is
still relevant, or to ping the collaborator who labelled it stalled if you
have any questions.
permissions:
contents: read

jobs:
stale:
permissions:
issues: write # for actions/stale to close stale issues
pull-requests: write # for actions/stale to close stale PRs
if: github.repository == 'nodejs/citgm'
runs-on: ubuntu-latest
steps:
- uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e # v9.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-close: 30
stale-pr-label: stalled
stale-issue-label: stalled
close-issue-message: ${{ env.CLOSE_MESSAGE }}
close-pr-message: ${{ env.CLOSE_MESSAGE }}
# used to filter issues to check whether or not should be closed, avoids hitting maximum operations allowed if needing to paginate through all open issues
only-labels: stalled
# max requests it will send per run to the GitHub API before it deliberately exits to avoid hitting API rate limits
operations-per-run: 500
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
lint:
name: Lint using ESLint
name: Lint using ESLint and Prettier

runs-on: ubuntu-latest

Expand All @@ -19,7 +19,7 @@ jobs:
show-progress: false

- name: Use LTS Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: lts/*

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
node-version:
- 18.x
- 20.x
- 21.x
- 22.x

runs-on: ${{ matrix.os }}

Expand All @@ -50,7 +52,7 @@ jobs:
show-progress: false

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ node_modules/
test/scaffold/*/node_modules
test/.*
coverage/
/.tap
.nyc_output/
.eslintcache
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/README.md
/test/fixtures/custom-lookup-broken.json
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ This is for adding a module to be included in the default `citgm-all` runs.
- Module source code must be on Github.
- Published versions must include a tag on Github
- The test process must be executable with only the commands
`npm install && npm test` or (`yarn install && yarn test`) using the tarball
downloaded from the Github tag mentioned above
`npm install && npm test` or (`yarn install && yarn test` or
`pnpm install && pnpm test`) using the tarball downloaded from the GitHub tag
mentioned above
- The tests pass on supported major release lines
- The maintainers of the module remain responsive when there are problems
- At least one module maintainer must be added to the lookup maintainers field
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
citgm is a simple tool for pulling down an arbitrary module from npm and testing
it using a specific version of the node runtime.

[![Build Status](https://github.com/nodejs/citgm/workflows/Node.js%20CI/badge.svg?branch=main)](https://github.com/nodejs/citgm/actions?query=workflow%3A%22Node.js+CI%22)
[![Build Status](https://github.com/nodejs/citgm/actions/workflows/nodejs.yml/badge.svg?branch=main)](https://github.com/nodejs/citgm/actions/workflows/nodejs.yml)

The Node.js project uses citgm to smoke test our releases and controversial
changes. The Jenkins job that utilizes citgm can be found
Expand Down Expand Up @@ -109,6 +109,7 @@ Options:
--excludeTags tag1 tag2 Specify which tags to skip from the lookup (takes priority over includeTags)
Module names are automatically added as tags.
-y, --yarn Install and test the project using yarn instead of npm
--pnpm Install and test the project using pnpm instead of npm
```

When using a JSON config file, the properties need to be the same as the
Expand All @@ -134,13 +135,14 @@ For syntax, see [lookup.json](./lib/lookup.json), the available attributes are:
"stripAnsi": true Strip ansi data from output stream of npm
"sha": "<git-commit-sha>" Test against a specific commit
"envVar" Pass an environment variable before running
"install": ["install", "--param1", "--param2"] - Array of command line parameters passed to 'npm' or 'yarn' as install arguments
"install": ["install", "--param1", "--param2"] - Array of command line parameters passed to `npm` or `yarn` or `pnpm` as install arguments
"maintainers": ["user1", "user2"] - List of module maintainers to be contacted with issues
"scripts": ["script1", "script2"] - List of scripts from package.json to run instead of 'test'
"tags": ["tag1", "tag2"] Specify which tags apply to the module
"useGitClone": true Use a shallow git clone instead of downloading the module
"ignoreGitHead": Ignore the gitHead field if it exists and fallback to using github tags
"yarn": Install and test the project using yarn instead of npm
"pnpm": Install and test the project using pnpm instead of npm
"timeout": Number of milliseconds before timeout. Applies separately to `install` and `test`
```

Expand Down
39 changes: 39 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import js from '@eslint/js';
import prettier from 'eslint-config-prettier';
import globals from 'globals';

export default [
js.configs.recommended,
prettier,
{
languageOptions: {
globals: {
...globals.node
}
},
rules: {
'capitalized-comments': [
'error',
'always',
{ ignoreConsecutiveComments: true }
],
eqeqeq: ['error', 'always'],
'no-template-curly-in-string': 'error',
'no-useless-escape': 'error',
'no-var': 'error',
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: 'directive', next: '*' }
],
'prefer-arrow-callback': 'error',
'prefer-template': 'error',
strict: 'error'
}
},
{
files: ['test/fixtures/**'],
languageOptions: {
sourceType: 'commonjs'
}
}
];
1 change: 1 addition & 0 deletions lib/bin/citgm-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const options = {
tmpDir: app.tmpDir,
customTest: app.customTest,
yarn: app.yarn,
pnpm: app.pnpm,
includeTags: app.includeTags || [],
excludeTags: app.excludeTags || []
};
Expand Down
3 changes: 2 additions & 1 deletion lib/bin/citgm.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const options = {
sha: app.sha,
tmpDir: app.tmpDir,
customTest: app.customTest,
yarn: app.yarn
yarn: app.yarn,
pnpm: app.pnpm
};

if (!windows) {
Expand Down
23 changes: 7 additions & 16 deletions lib/citgm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { createHash } from 'crypto';
import { EventEmitter } from 'events';

import npa from 'npm-package-arg';
import BufferList from 'bl';
import which from 'which';

Expand All @@ -15,6 +13,7 @@ import {
} from './package-manager/index.js';
import * as tempDirectory from './temp-directory.js';
import { unpack } from './unpack.js';
import { parsePackageArg } from './utils.js';

export const windows = process.platform === 'win32';

Expand Down Expand Up @@ -53,18 +52,6 @@ function init(context) {
);
}

function sha1(mod) {
const shasum = createHash('sha1');
shasum.update(mod);
return shasum.digest('hex');
}

function extractDetail(mod) {
const detail = npa(mod); // Will throw if mod is invalid
detail.name = detail.name || `noname-${sha1(mod)}`;
return detail;
}

/**
* The Tester will emit specific events once it is run:
* - end = emitted when the test is complete
Expand All @@ -75,7 +62,7 @@ function extractDetail(mod) {
export class Tester extends EventEmitter {
constructor(mod, options) {
super();
this.module = extractDetail(mod);
this.module = parsePackageArg(mod);
this.options = options;
this.testOutput = new BufferList();
this.testError = new BufferList();
Expand All @@ -89,9 +76,10 @@ export class Tester extends EventEmitter {
init(this);
await findNode(this);

const { npm, yarn } = await getPackageManagers();
const { npm, yarn, pnpm } = await getPackageManagers();
this.npmPath = npm;
this.yarnPath = yarn;
this.pnpmPath = pnpm;

await tempDirectory.create(this);
await grabModuleData(this);
Expand All @@ -111,6 +99,9 @@ export class Tester extends EventEmitter {
flaky: this.module.flaky,
expectFail: this.module.expectFail
};

if (this.options.sha) payload.sha = this.module.sha;

if (err) {
if (!payload.expectFail) {
this.emit('fail', err);
Expand Down
5 changes: 5 additions & 0 deletions lib/common-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export function commonArgs() {
description: 'Install and test the project using yarn instead of npm',
default: false
})
.option('pnpm', {
type: 'boolean',
description: 'Install and test the project using pnpm instead of npm',
default: false
})
.example(
'citgm-all --customTest /path/to/customTest.js',
'Runs a custom node test script instead of "npm test"'
Expand Down
8 changes: 6 additions & 2 deletions lib/grab-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ export async function grabProject(context) {
}

return new Promise((resolve, reject) => {
const packageManager =
context.options.yarn || context.module.useYarn ? 'yarn' : 'npm';
let packageManager = 'npm';
if (context.options.yarn || context.module.useYarn) {
packageManager = 'yarn';
} else if (context.options.pnpm || context.module.usePnpm) {
packageManager = 'pnpm';
}
let packageName = context.module.raw;
if (context.module.type === 'directory') {
context.module.raw = context.module.name = path.basename(packageName);
Expand Down
18 changes: 9 additions & 9 deletions lib/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function getLookupTable(options) {
}

return lookup;
} catch (err) {
} catch {
return undefined;
}
}
Expand Down Expand Up @@ -143,12 +143,13 @@ export function lookup(context) {
context.module.ref = ref;
} else {
const gitHead = rep.head || rep.ignoreGitHead ? null : meta.gitHead;
const sha = context.options.sha || rep.sha || gitHead;
const url = makeUrl(
getRepo(rep.repo, meta),
rep.head ? null : detail.fetchSpec,
meta['dist-tags'],
rep.head ? null : rep.prefix,
context.options.sha || rep.sha || gitHead
sha
);
context.emit(
'data',
Expand Down Expand Up @@ -183,6 +184,9 @@ export function lookup(context) {
if (rep.yarn) {
context.module.useYarn = true;
}
if (rep.pnpm) {
context.module.usePnpm = true;
}
if (rep.timeout) {
context.module.timeout = rep.timeout;
}
Expand All @@ -194,16 +198,12 @@ export function lookup(context) {
: defaultMatcher.isMatch(rep.expectFail);
} else {
context.emit('data', 'info', 'lookup-notfound', detail.name);
const sha = context.options.sha || meta.gitHead;
if (meta.gitHead) {
const url = makeUrl(
getRepo(null, meta),
null,
null,
null,
context.options.sha || meta.gitHead
);
const url = makeUrl(getRepo(null, meta), null, null, null, sha);
context.emit('data', 'info', 'lookup-githead', url);
context.module.raw = url;
context.module.sha = sha;
}
}
}
Expand Down
Loading

0 comments on commit a1f5673

Please sign in to comment.