Skip to content

Commit

Permalink
outdated commit hints in ci!! (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Apr 15, 2024
1 parent 889e652 commit aafdb64
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 33 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
}
}
2 changes: 1 addition & 1 deletion prismarine-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions prismarine-viewer/viewer/prepare/generateTextures.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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')
Expand Down
12 changes: 12 additions & 0 deletions prismarine-viewer/viewer/prepare/postinstall.ts
Original file line number Diff line number Diff line change
@@ -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')
}
52 changes: 52 additions & 0 deletions scripts/outdatedGitPackages.mjs
Original file line number Diff line number Diff line change
@@ -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')}`)
}
26 changes: 0 additions & 26 deletions scripts/updateGitPackages.mjs

This file was deleted.

0 comments on commit aafdb64

Please sign in to comment.