diff --git a/.github/helper/package.json b/.github/helper/package.json
new file mode 100644
index 00000000..5f88a010
--- /dev/null
+++ b/.github/helper/package.json
@@ -0,0 +1,5 @@
+{
+ "dependencies": {
+ "gh-helpers": "^1.0.0"
+ }
+}
\ No newline at end of file
diff --git a/.github/helper/updator.js b/.github/helper/updator.js
index 6697f3e2..9245b80f 100644
--- a/.github/helper/updator.js
+++ b/.github/helper/updator.js
@@ -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')
@@ -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(' ', `, ${newVersion} `)
+ const newReadmeContents = currentContentsReadme.replace('\n', `, ${newVersion}\n`)
fs.writeFileSync(readmePath, newReadmeContents)
console.log('Updated README with new version:', newVersion)
}
@@ -49,8 +47,7 @@ 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
`)
@@ -58,20 +55,43 @@ async function main () {
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 ${branchName} branch instead of master.
+ `,
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 => {
diff --git a/.github/workflows/commands.yml b/.github/workflows/commands.yml
index d2286e26..40807af7 100644
--- a/.github/workflows/commands.yml
+++ b/.github/workflows/commands.yml
@@ -5,6 +5,8 @@ on:
types: [created]
pull_request: # Handle renamed PRs
types: [edited]
+permissions:
+ contents: write
jobs:
comment-trigger:
diff --git a/.github/workflows/update-from-minecraft-data.yml b/.github/workflows/update-from-minecraft-data.yml
index 667d6b84..752aad54 100644
--- a/.github/workflows/update-from-minecraft-data.yml
+++ b/.github/workflows/update-from-minecraft-data.yml
@@ -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
@@ -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 }}
diff --git a/docs/README.md b/docs/README.md
index 06129f37..028e05bf 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -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
+ * 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
+
+
* Parses all packets and emits events with packet fields as JavaScript
objects.
* Send a packet by supplying fields as a JavaScript object.