Skip to content

Commit

Permalink
ci: attempting to use centralized CI in MatrixAI/.github
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Dec 21, 2024
1 parent ff2437f commit afd4683
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 225 deletions.
220 changes: 0 additions & 220 deletions .github/workflows/ci.yaml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "CI / Feature"

on:
push:
branches:
- feature*
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
use-library-js-feature:
permissions:
packages: read
contents: read
actions: write
checks: write
uses: MatrixAI/.github/.github/workflows/library-js-feature.yml@feature-workflows
21 changes: 21 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "CI / Staging"

on:
push:
branches:
- staging
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
use-library-js-staging:
permissions:
packages: read
contents: read
actions: write
checks: write
pull-requests: write
uses: MatrixAI/.github/.github/workflows/library-js-staging.yml@feature-workflows
15 changes: 15 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "CI / Tag"

on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:

jobs:
use-library-js-tag:
permissions:
packages: read
contents: read
actions: write
uses: MatrixAI/.github/.github/workflows/library-js-tag.yml@feature-workflows
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@
"postversion": "npm install --package-lock-only --ignore-scripts --silent",
"tsx": "tsx",
"test": "node ./scripts/test.mjs",
"lint": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx,json}'",
"lintfix": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx,json}' --fix",
"lintcontent": "prettier --check ./README.md",
"lintcontentfix": "prettier --write ./README.md",
"lint-shell": "find ./src ./tests ./scripts -type f -regextype posix-extended -regex '.*\\.(sh)' -exec shellcheck {} +",
"lint": "node ./scripts/lint.mjs",
"lintfix": "node ./scripts/lint.mjs --fix",
"docs": "shx rm -rf ./docs && typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src",
"bench": "tsc -p ./tsconfig.build.json && shx rm -rf ./benches/results && tsx ./benches/index.ts"
},
Expand Down
89 changes: 89 additions & 0 deletions scripts/lint.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env node

import os from 'node:os';
import path from 'node:path';
import url from 'node:url';
import process from 'node:process';
import childProcess from 'node:child_process';

const projectPath = path.dirname(
path.dirname(url.fileURLToPath(import.meta.url)),
);

const platform = os.platform();

/* eslint-disable no-console */
async function main(argv = process.argv) {
argv = argv.slice(2);
let fix = false;
const restArgs = [];
while (argv.length > 0) {
const option = argv.shift();
if (option === '--fix') {
fix = true;
argv.shift();
} else {
restArgs.push(option);
}
}
// Linting code
const eslintArgs = [
'{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx,json}',
];
if (fix) {
eslintArgs.push('--fix');
}
console.error('Running eslint:');
console.error(['eslint', ...eslintArgs].join(' '));
childProcess.execFileSync('eslint', eslintArgs, {
stdio: ['inherit', 'inherit', 'inherit'],
windowsHide: true,
encoding: 'utf-8',
shell: platform === 'win32' ? true : false,
cwd: projectPath,
});
// Linting shell scripts (this does not have auto-fixing)
const shellCheckArgs = [
'./src',
'./tests',
'./scripts',
'-type',
'f',
'-regextype',
'posix-extended',
'-regex',
'.*\\.(sh)',
'-exec',
'shellcheck',
'{}',
'+',
];
console.error('Running shellcheck:');
console.error(['find', ...shellCheckArgs].join(' '));
childProcess.execFileSync('find', shellCheckArgs, {
stdio: ['inherit', 'inherit', 'inherit'],
windowsHide: true,
encoding: 'utf-8',
shell: platform === 'win32' ? true : false,
cwd: projectPath,
});
// Linting markdown
const prettierArgs = [!fix ? '--check' : '--write', './README.md'];
console.error('Running prettier:');
console.error(['prettier', ...prettierArgs].join(' '));
childProcess.execFileSync('prettier', prettierArgs, {
stdio: ['inherit', 'inherit', 'inherit'],
windowsHide: true,
encoding: 'utf-8',
shell: platform === 'win32' ? true : false,
cwd: projectPath,
});
}
/* eslint-enable no-console */

if (import.meta.url.startsWith('file:')) {
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
void main();
}
}

0 comments on commit afd4683

Please sign in to comment.