From aafdb6469435ce3869fd4a21b2a6436ebc69abd2 Mon Sep 17 00:00:00 2001 From: Vitaly Date: Mon, 15 Apr 2024 05:44:25 +0300 Subject: [PATCH] outdated commit hints in ci!! (#101) --- .github/workflows/ci.yml | 9 +++- package.json | 3 ++ prismarine-viewer/package.json | 2 +- .../viewer/prepare/generateTextures.ts | 6 +-- .../viewer/prepare/postinstall.ts | 12 +++++ scripts/outdatedGitPackages.mjs | 52 +++++++++++++++++++ scripts/updateGitPackages.mjs | 26 ---------- 7 files changed, 77 insertions(+), 33 deletions(-) create mode 100644 prismarine-viewer/viewer/prepare/postinstall.ts create mode 100644 scripts/outdatedGitPackages.mjs delete mode 100644 scripts/updateGitPackages.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe7c8ba64..3bc45b5ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,10 @@ jobs: uses: actions/checkout@master - name: Install pnpm run: npm i -g pnpm - # todo this needs investigating fixing + - uses: actions/setup-node@v4 + with: + node-version: 18 + # cache: "pnpm" - run: pnpm install - run: pnpm lint - run: pnpm check-build @@ -24,3 +27,7 @@ jobs: with: name: cypress-images path: cypress/integration/__image_snapshots__/ + - run: node scripts/outdatedGitPackages.mjs + # if: github.ref == 'refs/heads/next' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/package.json b/package.json index 881be9cc6..d6ea66556 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,9 @@ "prismarine-provider-anvil": "github:zardoy/prismarine-provider-anvil#everything", "minecraft-protocol": "github:zardoy/minecraft-protocol#everything", "react": "^18.2.0" + }, + "updateConfig": { + "ignoreDependencies": [] } } } diff --git a/prismarine-viewer/package.json b/prismarine-viewer/package.json index 529aa9ae4..7d7b6b81d 100644 --- a/prismarine-viewer/package.json +++ b/prismarine-viewer/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "postinstall": "pnpm generate-textures && node buildWorker.mjs", - "generate-textures": "tsx viewer/prepare/generateTextures.ts" + "generate-textures": "tsx viewer/prepare/postinstall.ts" }, "author": "PrismarineJS", "license": "MIT", diff --git a/prismarine-viewer/viewer/prepare/generateTextures.ts b/prismarine-viewer/viewer/prepare/generateTextures.ts index b9a5e3e5f..2a196ccbb 100644 --- a/prismarine-viewer/viewer/prepare/generateTextures.ts +++ b/prismarine-viewer/viewer/prepare/generateTextures.ts @@ -1,6 +1,6 @@ import path from 'path' import { makeBlockTextureAtlas } from './atlas' -import { McAssets, prepareBlocksStates } from './modelsBuilder' +import { prepareBlocksStates } from './modelsBuilder' import mcAssets from 'minecraft-assets' import fs from 'fs-extra' import { prepareMoreGeneratedBlocks } from './moreGeneratedBlocks' @@ -9,10 +9,6 @@ import { generateItemsAtlases } from './genItemsAtlas' const publicPath = path.resolve(__dirname, '../../public') const texturesPath = path.join(publicPath, 'textures') -if (fs.existsSync(texturesPath) && !process.argv.includes('-f')) { - console.log('textures folder already exists, skipping...') - process.exit(0) -} fs.mkdirSync(texturesPath, { recursive: true }) const blockStatesPath = path.join(publicPath, 'blocksStates') diff --git a/prismarine-viewer/viewer/prepare/postinstall.ts b/prismarine-viewer/viewer/prepare/postinstall.ts new file mode 100644 index 000000000..bf70d26c0 --- /dev/null +++ b/prismarine-viewer/viewer/prepare/postinstall.ts @@ -0,0 +1,12 @@ +import path from 'path' +import fs from 'fs' + +const publicPath = path.resolve(__dirname, '../../public') +const texturesPath = path.join(publicPath, 'textures') + +if (fs.existsSync(texturesPath) && !process.argv.includes('-f')) { + console.log('textures folder already exists, skipping...') + process.exit(0) +} else { + import('./generateTextures') +} diff --git a/scripts/outdatedGitPackages.mjs b/scripts/outdatedGitPackages.mjs new file mode 100644 index 000000000..c6a3b2d5f --- /dev/null +++ b/scripts/outdatedGitPackages.mjs @@ -0,0 +1,52 @@ +// pnpm bug workaround +import fs from 'fs' +import { parse } from 'yaml' +import _ from 'lodash' + +const lockfile = parse(fs.readFileSync('./pnpm-lock.yaml', 'utf8')) +const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8')) +const depsKeys = ['dependencies', 'devDependencies'] + +const githubToken = process.env.GITHUB_TOKEN +const ignoreDeps = packageJson.pnpm?.updateConfig?.ignoreDependencies ?? [] + +const outdatedDeps = [] + +const allDepsObj = {} + +for (const [key, val] of Object.entries(lockfile.importers)) { + // Object.assign(allDepsObj, val) + _.merge(allDepsObj, val) +} + +for (const [depsKey, deps] of Object.entries(allDepsObj)) { + for (const [depName, { specifier, version }] of Object.entries(deps)) { + if (ignoreDeps.includes(depName)) continue + if (!specifier.startsWith('github:')) continue + // console.log('checking github:', depName, version, specifier) + + let possiblyBranch = specifier.match(/#(.*)$/)?.[1] ?? '' + if (possiblyBranch) possiblyBranch = `/${possiblyBranch}` + const sha = version.split('/').slice(3).join('/').replace(/\(.+/, '') + const repo = version.split('/').slice(1, 3).join('/') + + const lastCommitJson = await fetch(`https://api.github.com/repos/${repo}/commits${possiblyBranch}?per_page=1`, { + headers: { + Authorization: githubToken ? `token ${githubToken}` : undefined, + }, + }).then(res => res.json()) + + const lastCommitActual = lastCommitJson ?? lastCommitJson[0] + const lastCommitActualSha = Array.isArray(lastCommitActual) ? lastCommitActual[0]?.sha : lastCommitActual?.sha + if (lastCommitActualSha === undefined) debugger + if (sha !== lastCommitActualSha) { + // console.log(`Outdated ${depName} github.com/${repo} : ${sha} -> ${lastCommitActualSha} (${lastCommitActual.commit.message})`) + outdatedDeps.push({ depName, repo, sha, lastCommitActualSha }) + } + } + +} + +if (outdatedDeps.length) { + throw new Error(`Outdated dependencies found: \n${outdatedDeps.map(({ depName, repo, sha, lastCommitActualSha }) => `${depName} github.com/${repo} : ${sha} -> ${lastCommitActualSha}`).join('\n')}`) +} diff --git a/scripts/updateGitPackages.mjs b/scripts/updateGitPackages.mjs deleted file mode 100644 index 14524587e..000000000 --- a/scripts/updateGitPackages.mjs +++ /dev/null @@ -1,26 +0,0 @@ -// pnpm bug workaround -import fs from 'fs' -import { parse } from 'yaml' - -const lockfile = parse(fs.readFileSync('./pnpm-lock.yaml', 'utf8')) - -const depsKeys = ['dependencies', 'devDependencies'] - -for (const importer of Object.values(lockfile.importers)) { - for (const depsKey of depsKeys) { - for (const [depName, { specifier, version }] of Object.entries(importer[depsKey])) { - if (!specifier.startsWith('github:')) continue - let branch = specifier.match(/#(.*)$/)?.[1] ?? '' - if (branch) branch = `/${branch}` - const sha = version.split('/').slice(3).join('/').replace(/\(.+/, '') - const repo = version.split('/').slice(1, 3).join('/') - const lastCommitJson = await fetch(`https://api.github.com/repos/${repo}/commits${branch}?per_page=1`).then(res => res.json()) - const lastCommitActual = lastCommitJson ?? lastCommitJson[0] - const lastCommitActualSha = lastCommitActual?.sha - if (lastCommitActualSha === undefined) debugger - if (sha !== lastCommitActualSha) { - console.log(`Outdated ${depName} github.com/${repo} : ${sha} -> ${lastCommitActualSha} (${lastCommitActual.commit.message})`) - } - } - } -}