Skip to content

Commit 684c6b1

Browse files
author
Rodrigo
committed
ci: enforce baileys lock sync
1 parent 9cd0302 commit 684c6b1

4 files changed

Lines changed: 71 additions & 17 deletions

File tree

.github/workflows/main.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ jobs:
2424
steps:
2525
- uses: actions/checkout@v5
2626
- uses: actions/setup-node@v5
27-
with:
28-
node-version: 24
29-
cache: yarn
30-
- run: yarn install
31-
- run: yarn lint
32-
- run: yarn format
33-
- run: yarn test
27+
with:
28+
node-version: 24
29+
cache: yarn
30+
- run: yarn check:baileys-lock
31+
- run: yarn install --frozen-lockfile
32+
- run: yarn check:baileys-lock
33+
- run: yarn lint
34+
- run: yarn format
35+
- run: yarn test
3436

3537
build:
3638
needs: test

.github/workflows/sync-upstream.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ jobs:
4949
git checkout -b "$BRANCH"
5050
git merge --no-ff -m "merge: upstream ${{ inputs.tag }}" "tags/${{ inputs.tag }}"
5151
52-
- name: Install Yarn (classic) and dependencies
53-
run: |
54-
npm i -g yarn@1.22.22
55-
yarn install
56-
57-
- name: Build
52+
- name: Install Yarn (classic) and dependencies
53+
run: |
54+
npm i -g yarn@1.22.22
55+
yarn check:baileys-lock
56+
yarn install --frozen-lockfile
57+
yarn check:baileys-lock
58+
59+
- name: Build
5860
run: yarn build
5961

6062
- name: Test

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@
4343
"broker-ts": "node --max-old-space-size=4096 --experimental-strip-types --experimental-transform-types src/broker.ts",
4444
"bridge": "node --max-old-space-size=4096 dist/src/bridge.js",
4545
"bridge-ts": "node --max-old-space-size=4096 --experimental-strip-types --experimental-transform-types src/bridge.ts",
46-
"clean:data": "rm -rf ./data/medias/* ./data/sessions/* ./data/stores/*.json",
47-
"build:docs": "node ./scripts/openapi-to-json.mjs",
48-
"postinstall": "node ./scripts/prepare-baileys.mjs"
49-
},
46+
"clean:data": "rm -rf ./data/medias/* ./data/sessions/* ./data/stores/*.json",
47+
"build:docs": "node ./scripts/openapi-to-json.mjs",
48+
"check:baileys-lock": "node ./scripts/check-baileys-lock.mjs",
49+
"postinstall": "node ./scripts/prepare-baileys.mjs"
50+
},
5051
"devDependencies": {
5152
"@eslint/js": "^9.1.1",
5253
"@types/express": "^4.17.21",

scripts/check-baileys-lock.mjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import fs from 'node:fs'
2+
3+
const dependencyName = '@whiskeysockets/baileys'
4+
const repoPrefix = 'github:ViperTecCorporation/Baileys#'
5+
6+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'))
7+
const wantedRefs = [
8+
packageJson.dependencies?.[dependencyName],
9+
packageJson.resolutions?.[dependencyName],
10+
].filter(Boolean)
11+
12+
const wantedHashes = [...new Set(wantedRefs.map((ref) => `${ref}`.split('#')[1]).filter(Boolean))]
13+
if (!wantedHashes.length) {
14+
console.error(`[check-baileys-lock] ${dependencyName} must be pinned with ${repoPrefix}<commit>`)
15+
process.exit(1)
16+
}
17+
18+
if (wantedHashes.length > 1) {
19+
console.error(`[check-baileys-lock] package.json has conflicting Baileys pins: ${wantedHashes.join(', ')}`)
20+
process.exit(1)
21+
}
22+
23+
const wantedHash = wantedHashes[0]
24+
const lockLines = fs.readFileSync('yarn.lock', 'utf8').split(/\r?\n/)
25+
const entryStart = lockLines.findIndex((line) => line.includes(`"${dependencyName}@${repoPrefix}`))
26+
let lockEntry = ''
27+
if (entryStart >= 0) {
28+
const entryLines = [lockLines[entryStart]]
29+
for (let index = entryStart + 1; index < lockLines.length; index += 1) {
30+
const line = lockLines[index]
31+
if (line && !line.startsWith(' ')) break
32+
entryLines.push(line)
33+
}
34+
lockEntry = entryLines.join('\n')
35+
}
36+
const lockedHash = lockEntry.match(/Baileys#([0-9a-f]{7,40})/)?.[1] || lockEntry.match(/tar\.gz\/([0-9a-f]{7,40})/)?.[1] || ''
37+
38+
if (!lockEntry || !lockedHash) {
39+
console.error('[check-baileys-lock] Baileys entry was not found in yarn.lock')
40+
process.exit(1)
41+
}
42+
43+
if (lockedHash !== wantedHash) {
44+
console.error(`[check-baileys-lock] Baileys lock mismatch: package.json=${wantedHash} yarn.lock=${lockedHash}`)
45+
console.error('[check-baileys-lock] Run yarn install and commit yarn.lock with package.json.')
46+
process.exit(1)
47+
}
48+
49+
console.log(`[check-baileys-lock] Baileys lock is in sync: ${wantedHash}`)

0 commit comments

Comments
 (0)