Skip to content

Commit

Permalink
chore: use import instead of require to support modern NodeJS
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Jan 28, 2025
1 parent 72d88d9 commit a1c9e87
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ jobs:
fetch-depth: 50
- id: set-matrix
run: |
node .github/workflows/matrix.js
node .github/workflows/matrix.mjs
build-test:
name: '${{ matrix.name }}'
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/matrix.js → .github/workflows/matrix.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// The script generates a random subset of valid jdk, os, timezone, and other axes.
// You can preview the results by running "node matrix.js"
// You can preview the results by running "node matrix.mjs"
// See https://github.com/vlsi/github-actions-random-matrix
let fs = require('fs');
let os = require('os');
const { RNG } = require('./rng');
let {MatrixBuilder} = require('./matrix_builder');
import { appendFileSync } from 'fs';
import { EOL } from 'os';
import { RNG } from './rng.mjs';
import { MatrixBuilder } from './matrix_builder.mjs';
const matrix = new MatrixBuilder();

// Some of the filter conditions might become unsatisfiable, and by default
Expand Down Expand Up @@ -362,7 +362,7 @@ console.log(include);

let filePath = process.env['GITHUB_OUTPUT'] || '';
if (filePath) {
fs.appendFileSync(filePath, `matrix<<MATRIX_BODY${os.EOL}${JSON.stringify({include})}${os.EOL}MATRIX_BODY${os.EOL}`, {
appendFileSync(filePath, `matrix<<MATRIX_BODY${EOL}${JSON.stringify({include})}${EOL}MATRIX_BODY${EOL}`, {
encoding: 'utf8'
});
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// License: Apache-2.0
// Copyright Vladimir Sitnikov, 2021
// See https://github.com/vlsi/github-actions-random-matrix
const { RNG } = require('./rng');
import { RNG } from './rng.mjs';

class Axis {
constructor({name, title, values}) {
Expand Down Expand Up @@ -253,4 +253,4 @@ class MatrixBuilder {
}
}

module.exports = {Axis, MatrixBuilder};
export { Axis, MatrixBuilder };
12 changes: 6 additions & 6 deletions .github/workflows/rng.js → .github/workflows/rng.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const crypto = require('crypto');
const seedrandom = require('./seedrandom');
import { appendFileSync } from 'fs';
import { randomBytes } from 'crypto';
import { default as seedrandom } from './seedrandom.js';

function genSeedText() {
const { RNG_SEED } = process.env;
Expand All @@ -14,7 +14,7 @@ function genSeedText() {
return 'pr_' + GITHUB_PR_NUMBER;
}
// Otherwise generate a random seed. Note that we do not actually care
return 'seed_' + Date.now() + '_' + crypto.randomBytes(16).toString('hex');
return 'seed_' + Date.now() + '_' + randomBytes(16).toString('hex');
}

function createRNG() {
Expand All @@ -25,7 +25,7 @@ function createRNG() {
console.log('Initialized RNG with RNG_SEED = %s', seedText);
console.log('::endgroup::');
if (process.env.GITHUB_STEP_SUMMARY) {
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, [
appendFileSync(process.env.GITHUB_STEP_SUMMARY, [
'# Random Number Generator Seed',
'To regenerate this matrix in a different build, run it with the following seed:',
'',
Expand All @@ -41,4 +41,4 @@ function createRNG() {
};
}

module.exports.RNG = createRNG();
export const RNG = createRNG();

0 comments on commit a1c9e87

Please sign in to comment.