Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/helper/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"gh-helpers": "^1.0.0"
}
}
62 changes: 41 additions & 21 deletions .github/helper/updator.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
#!/usr/bin/env node
/**
* Updator script triggered from minecraft-data repository
* This script can be customized to handle updates from minecraft-data
* Updator script triggered from minecraft-data repository to auto generate PR
*/
const github = require('gh-helpers')()
const fs = require('fs')
const cp = require('child_process')
const assert = require('assert')
const github = require('gh-helpers')()
const { join } = require('path')
const exec = (cmd) => github.mock ? console.log('> ', cmd) : (console.log('> ', cmd), cp.execSync(cmd, { stdio: 'inherit' }))

console.log('Starting update process...')
const triggerBranch = process.env.TRIGGER_SOURCE
const newVersion = process.env.DATA_VERSION
const onBehalfOf = process.env.TRIGGER_REASON || 'workflow_dispatch'
console.log('Trigger reason:', onBehalfOf)
console.log('New version:', newVersion)
// Sanitize and validate environment variables all non alpha numeric / underscore / dot
const newVersion = process.env.NEW_MC_VERSION?.replace(/[^a-zA-Z0-9_.]/g, '_')
const triggerBranch = process.env.MCDATA_BRANCH?.replace(/[^a-zA-Z0-9_.]/g, '_')
const mcdataPrURL = process.env.MCDATA_PR_URL
console.log({ newVersion, triggerBranch, mcdataPrURL })

if (!newVersion) {
console.error('No new version provided. Exiting...')
process.exit(1)
}
assert(newVersion)
assert(triggerBranch)

async function main () {
const currentSupportedPath = require.resolve('../../src/version.js')
Expand All @@ -39,7 +37,7 @@ async function main () {
// Update the README.md
const currentContentsReadme = fs.readFileSync(readmePath, 'utf8')
if (!currentContentsReadme.includes(newVersion)) {
const newReadmeContents = currentContentsReadme.replace(' <!-- NEXT_VERSION -->', `, ${newVersion} <!-- NEXT_VERSION -->`)
const newReadmeContents = currentContentsReadme.replace('\n<!--add_next_version_above-->', `, ${newVersion}\n<!--add_next_version_above-->`)
fs.writeFileSync(readmePath, newReadmeContents)
console.log('Updated README with new version:', newVersion)
}
Expand All @@ -49,29 +47,51 @@ async function main () {
const currentContentsCI = fs.readFileSync(ciPath, 'utf8')
if (!currentContentsCI.includes(newVersion)) {
const newCIContents = currentContentsCI.replace(
' run: npm install', `
run: npm install
'run: npm install', `run: npm install
- run: cd node_modules && cd minecraft-data && mv minecraft-data minecraft-data-old && git clone -b ${triggerBranch} https://github.com/PrismarineJS/minecraft-data --depth 1 && node bin/generate_data.js
- run: curl -o node_modules/protodef/src/serializer.js https://raw.githubusercontent.com/extremeheat/node-protodef/refs/heads/dlog/src/serializer.js && curl -o node_modules/protodef/src/compiler.js https://raw.githubusercontent.com/extremeheat/node-protodef/refs/heads/dlog/src/compiler.js
`)
fs.writeFileSync(ciPath, newCIContents)
console.log('Updated CI workflow with new version:', newVersion)
}

const branchName = 'pc' + newVersion.replace(/[^a-zA-Z0-9_]/g, '.')
const branchName = 'pc' + newVersion.replace(/[^a-zA-Z0-9_]/g, '_')
exec(`git checkout -b ${branchName}`)
exec('git config user.name "github-actions[bot]"')
exec('git config user.email "41898282+github-actions[bot]@users.noreply.github.com"')
exec('git add --all')
exec(`git commit -m "Update to version ${newVersion}"`)
exec(`git push origin ${branchName}`)
exec(`git push origin ${branchName} --force`)
// createPullRequest(title: string, body: string, fromBranch: string, intoBranch?: string): Promise<{ number: number, url: string }>;
const pr = await github.createPullRequest(
`${newVersion} updates`,
`Automatically generated PR for Minecraft version ${newVersion}.\n\nRef: ${onBehalfOf}`,
`🎈 ${newVersion}`,
`This automated PR sets up the relevant boilerplate for Minecraft version ${newVersion}.

Ref: ${mcdataPrURL}

* You can help contribute to this PR by opening a PR against this <code branch>${branchName}</code> branch instead of <code>master</code>.
`,
branchName,
'master'
)
console.log(`Pull request created: ${pr.url} (PR #${pr.number})`)
console.log('Update process completed successfully!')
console.log(`Pull request created`, pr)

// Ask mineflayer to handle new update
const nodeDispatchPayload = {
owner: 'PrismarineJS',
repo: 'mineflayer',
workflow: 'handle-update.yml',
branch: 'master',
inputs: {
new_mc_version: newVersion,
mcdata_branch: triggerBranch,
mcdata_pr_url: mcdataPrURL,
nmp_branch: branchName,
nmp_pr_url: pr.url
}
}
console.log('Sending workflow dispatch', nodeDispatchPayload)
await github.sendWorkflowDispatch(nodeDispatchPayload)
}

main().catch(err => {
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
types: [created]
pull_request: # Handle renamed PRs
types: [edited]
permissions:
contents: write

jobs:
comment-trigger:
Expand Down
57 changes: 16 additions & 41 deletions .github/workflows/update-from-minecraft-data.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
name: Update from minecraft-data

# This workflow can be triggered from external repositories (like minecraft-data)
# via workflow_dispatch API call or repository_dispatch webhook
on:
# Allow manual triggering
workflow_dispatch:
inputs:
trigger_source:
description: 'Repository branch that triggered this update'
required: false
default: 'minecraft-data'
new_mc_version:
description: New minecraft version number
required: true
type: string
trigger_reason:
description: 'What PR or issue triggered this update'
required: false
default: ''
mcdata_branch:
description: minecraft-data branch for this version
required: true
type: string
data_version:
description: 'MC Version that triggered this update'
mcdata_pr_url:
description: minecraft-data PR number to open a PR here against
required: false
default: ''
type: string

# Listen for repository dispatch events (webhook-based triggers)
repository_dispatch:
types: [minecraft-data-update]

jobs:
update:
runs-on: ubuntu-latest
Expand All @@ -33,29 +25,12 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Use a token that has write permissions if you need to push changes
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: npm install gh-helpers

- name: Set environment variables
run: |
echo "TRIGGER_SOURCE=${{ github.event.inputs.trigger_source || github.event.client_payload.repository || 'minecraft-data' }}" >> $GITHUB_ENV
echo "TRIGGER_REASON=${{ github.event.inputs.trigger_reason || github.event.client_payload.reason || 'repository_dispatch' }}" >> $GITHUB_ENV
echo "DATA_VERSION=${{ github.event.inputs.data_version || github.event.client_payload.version || 'unknown' }}" >> $GITHUB_ENV

token: ${{ secrets.PAT_PASSWORD }}

- name: Run updator script
run: node .github/helper/updator.js
run: cd .github/helper && npm install && node updator.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TRIGGER_SOURCE: ${{ env.TRIGGER_SOURCE }}
TRIGGER_REASON: ${{ env.TRIGGER_REASON }}
DATA_VERSION: ${{ env.DATA_VERSION }}

GITHUB_TOKEN: ${{ secrets.PAT_PASSWORD }}
MCDATA_BRANCH: ${{ github.event.inputs.mcdata_branch }}
MCDATA_PR_URL: ${{ github.event.inputs.mcdata_pr_url }}
NEW_MC_VERSION: ${{ github.event.inputs.new_mc_version }}
14 changes: 10 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ Parse and serialize minecraft packets, plus authentication and encryption.

## Features

* Supports Minecraft PC version 1.7.10, 1.8.8, 1.9 (15w40b, 1.9, 1.9.1-pre2, 1.9.2, 1.9.4),
1.10 (16w20a, 1.10-pre1, 1.10, 1.10.1, 1.10.2), 1.11 (16w35a, 1.11, 1.11.2), 1.12 (17w15a, 17w18b, 1.12-pre4, 1.12, 1.12.1, 1.12.2), and 1.13 (17w50a, 1.13, 1.13.1, 1.13.2-pre1, 1.13.2-pre2, 1.13.2), 1.14 (1.14, 1.14.1, 1.14.3, 1.14.4)
, 1.15 (1.15, 1.15.1, 1.15.2) and 1.16 (20w13b, 20w14a, 1.16-rc1, 1.16, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5), 1.17 (21w07a, 1.17, 1.17.1), 1.18 (1.18, 1.18.1 and 1.18.2), 1.19 (1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4), 1.20 (1.20, 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6), 1.21 (1.21, 1.21.1, 1.21.3, 1.21.4, 1.21.5)
, 1.21.6, 1.21.8 <!-- NEXT_VERSION -->
* Supports Minecraft PC version
1.7.10, 1.8.8, 1.9 (15w40b, 1.9, 1.9.1-pre2, 1.9.2, 1.9.4), 1.10 (16w20a, 1.10-pre1, 1.10, 1.10.1, 1.10.2),
1.11 (16w35a, 1.11, 1.11.2), 1.12 (17w15a, 17w18b, 1.12-pre4, 1.12, 1.12.1, 1.12.2),
1.13 (17w50a, 1.13, 1.13.1, 1.13.2-pre1, 1.13.2-pre2, 1.13.2),1.14 (1.14, 1.14.1, 1.14.3, 1.14.4),
1.15 (1.15, 1.15.1, 1.15.2), 1.16 (20w13b, 20w14a, 1.16-rc1, 1.16, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5),
1.17 (21w07a, 1.17, 1.17.1), 1.18 (1.18, 1.18.1 and 1.18.2),
1.19 (1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4), 1.20 (1.20, 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6),
1.21, 1.21.1, 1.21.3, 1.21.4, 1.21.5, 1.21.6, 1.21.8
<!--add_next_version_above-->

* Parses all packets and emits events with packet fields as JavaScript
objects.
* Send a packet by supplying fields as a JavaScript object.
Expand Down
Loading