forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix broken package.json sort verification
- Remove not working check-package-json-sort.ts script. - Add ci action to check for unsorted package.json files. Closes: hyperledger-cacti#2356 Signed-off-by: Tomasz Awramski <tomasz.awramski@fujitsu.com
- Loading branch information
Showing
3 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: sort-package-json-check | ||
on: | ||
push: | ||
# Publish `main` as Docker `latest` image. | ||
branches: | ||
- main | ||
|
||
# Publish `v1.2.3` tags as releases. | ||
tags: | ||
- v* | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
|
||
jobs: | ||
sort-package-json-check: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "14" | ||
- run: npm install --global sort-package-json | ||
- run: ./tools/ci-package-json-check.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { globby, Options as GlobbyOptions } from "globby"; | ||
import { sortPackageJson } from "sort-package-json"; | ||
// eslint-disable-next-line prettier/prettier | ||
import lernaCfg from "../lerna.json" assert { type: "json" }; | ||
|
||
export interface ICheckPackageJsonSort { | ||
readonly argv: string[]; | ||
readonly env: NodeJS.ProcessEnv; | ||
} | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
const SCRIPT_DIR = __dirname; | ||
const PROJECT_DIR = path.join(SCRIPT_DIR, "../"); | ||
const globbyOpts: GlobbyOptions = { | ||
cwd: PROJECT_DIR, | ||
ignore: ["**/node_modules"], | ||
}; | ||
|
||
const DEFAULT_GLOB = "**/cactus-*/package.json"; | ||
|
||
|
||
export async function sortPackages( | ||
): Promise<any> { | ||
const TAG = "[tools/check-package-json-sort.ts]"; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
const SCRIPT_DIR = __dirname; | ||
const PROJECT_DIR = path.join(SCRIPT_DIR, "../../"); | ||
console.log(`${TAG} SCRIPT_DIR=${SCRIPT_DIR}`); | ||
console.log(`${TAG} PROJECT_DIR=${PROJECT_DIR}`); | ||
|
||
const includeGlobs = lernaCfg.packages.map((x) => x.concat("/package.json")); | ||
|
||
const pkgJsonPaths = await globby(includeGlobs, globbyOpts); | ||
for (const pckg of pkgJsonPaths) { | ||
const json = await fs.readJSON(pckg); | ||
const sortredJson = await sortPackageJson(json); | ||
|
||
fs.writeFile(pckg, JSON.stringify(sortredJson, null, 2)); | ||
|
||
} | ||
} | ||
|
||
sortPackages() |