Add workflow to autogen mappings

This commit is contained in:
Nassim Jahnke 2023-03-04 22:25:57 +01:00
parent a68d50ed7a
commit 7260f24adb
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
14 changed files with 151 additions and 27812 deletions

66
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,66 @@
name: Check for new Minecraft snapshot
on:
schedule:
- cron: '10 * * * *'
workflow_dispatch:
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
- name: Setup Java JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Maven
uses: s4u/setup-maven-action@v1.7.0
with:
java-version: 17
- name: Configure Git details
run: |
git config --global user.name 'not quite kenny'
git config --global user.email 'notactuallykennytv2@something.com'
- name: Check for snapshot
run: pip install -r requirements.txt && python download_server.py
# Wooyeah
- name: Read last snapshot
id: last_snapshot
uses: juliangruber/read-file-action@v1
with:
path: ./last_snapshot.txt
- name: Read last release
id: last_release
uses: juliangruber/read-file-action@v1
with:
path: ./last_release.txt
- name: Read next release
id: next_release
uses: juliangruber/read-file-action@v1
with:
path: ./next_release.txt
- name: Compile MappingsGenerator jar
run: mvn package && mvn package && mv target/MappingsGenerator-*.jar ./MappingsGenerator.jar
- name: Run MappingsGenerator
run: java -jar MappingsGenerator.jar server.jar ${{ steps.next_release.outputs.content }} ${{ steps.last_release.outputs.content }}
- name: Pack mappings
run: java -cp MappingsGenerator.jar com.viaversion.mappingsgenerator.MappingsOptimizer ${{ steps.last_release.outputs.content }} ${{ steps.next_release.outputs.content }}
- name: Pack backwards mappings
run: java -cp MappingsGenerator.jar com.viaversion.mappingsgenerator.MappingsOptimizer ${{ steps.next_release.outputs.content }} ${{ steps.last_release.outputs.content }}
- name: Commit changes
run: |
git add .
git commit -m "${{ steps.last_snapshot.outputs.content }}"
git push

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
libraries/
generated/
### Java files ###
*.class

View File

@ -35,7 +35,7 @@ If you want to generate the compact mapping files with already present json file
its own by starting the `MappingsOptimizer` class with the two arguments flipped:
```
java -DbundlerMainClass=com.viaversion.mappinggenerator.MappingsOptimizer -jar <from version> <to version>
java -cp MappingsGenerator.jar com.viaversion.mappingsgenerator.MappingsOptimizer <from version> <to version>
```
## Json format
@ -92,7 +92,8 @@ mapped ids in a simple int→int mapping over the two arrays.
### Shifted value storage
The shifted value storage stores two int arrays: One containing the unmapped ids that end a sequence of mapped ids. For
an index `i`, all unmapped ids between `at[i] + sequence` (inclusive) and `at[i + 1]` (exclusive) are mapped to `to[i] + sequence`.
an index `i`, all unmapped ids between `at[i] + sequence` (inclusive) and `at[i + 1]` (exclusive) are mapped
to `to[i] + sequence`.
* `id` (byte tag) is `2`
* `at` (int array tag) contains the unmapped ids, where their mapped is is *not* simply the last mapped id + 1
@ -107,5 +108,5 @@ simply leaving out the entry to make sure ids stay in bounds.
## License
The Java code is licensed under the GNU GPL v3 license. The files under `mappings/` are free to copy, use, and expand
upon in whatever way you like.
The Java and Python code is licensed under the GNU GPL v3 license. The files under `mappings/` are free to copy, use,
and expand upon in whatever way you like.

70
download_server.py Normal file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env python3
import json
import os
import six
import subprocess
import sys
import wget
from pathlib import Path
from urllib.error import HTTPError
MANIFEST_LOCATION = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"
def load_json(url):
try:
with six.moves.urllib.request.urlopen(url) as stream:
return json.load(stream)
except HTTPError as e:
print('HTTP Error')
print(e)
sys.exit(-1)
def main():
# Get latest version from manifest
manifest = load_json(MANIFEST_LOCATION)
latest = manifest["latest"]
snapshot = latest["snapshot"]
release = latest["release"]
# Compare with old version
last_release = release
last_snapshot_path = Path('last_snapshot.txt')
if last_snapshot_path.exists():
with open(last_snapshot_path, 'r') as f:
if f.readline() == snapshot:
sys.exit(1)
# Download version data
manifestEntry = None
for entry in manifest["versions"]:
if entry["id"] == snapshot:
manifestEntry = entry
break
if manifestEntry is None:
print("VERSION DATA FOR", snapshot, "NOT FOUND")
sys.exit(1)
# Rename old server jar as backup and download new one
if os.path.exists("server_old.jar"):
os.remove("server_old.jar")
if os.path.exists("server.jar"):
os.rename('server.jar', 'server_old.jar')
print("=== Downloading server...")
versionData = load_json(manifestEntry["url"])
serverUrl = versionData["downloads"]["server"]["url"]
wget.download(serverUrl, "server.jar")
with open(last_snapshot_path, 'w') as f:
f.write(snapshot)
with open(Path('last_release.txt'), 'w') as f:
f.write(release)
sys.exit(0)
if __name__ == "__main__":
main()

1
last_release.txt Normal file
View File

@ -0,0 +1 @@
1.19.3

1
last_snapshot.txt Normal file
View File

@ -0,0 +1 @@
1.19.4-pre2

File diff suppressed because it is too large Load Diff

1
next_release.txt Normal file
View File

@ -0,0 +1 @@
1.19.4

Binary file not shown.

Binary file not shown.

View File

@ -7,7 +7,7 @@
<groupId>com.viaversion</groupId>
<artifactId>mappingsgenerator</artifactId>
<name>MappingsGenerator</name>
<version>3.0.0</version>
<version>3.0.1</version>
<url>https://github.com/ViaVersion/Mappings</url>
<inceptionYear>2020</inceptionYear>

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
six==1.16.0
wget==3.2

View File

@ -66,13 +66,12 @@ public final class MappingsOptimizer {
private static final String OUTPUT_FILE_FORMAT = "mappings-%sto%s.nbt";
private static final String OUTPUT_IDENTIFIERS_FILE_FORMAT = "identifiers-%s.nbt";
private static final Set<String> SAVED_IDENTIFIER_FILES = new HashSet<>();
private static final boolean RUN_ALL = true;
public static void main(final String[] args) throws IOException {
MAPPINGS_DIR.mkdirs();
OUTPUT_DIR.mkdirs();
if (RUN_ALL) {
if (false) {
runAll();
return;
}