Skip to content

Generate Data

Generate Data #56

Workflow file for this run

name: "Generate Data"
on:
schedule:
- cron: "30 0,12 * * *" # Runs at 00:30 and 12:30, every day
workflow_call:
inputs:
VERSION:
description: "Generate data for a specific version. Leave blank for latest version."
type: string
required: false
workflow_dispatch:
inputs:
VERSION:
description: "Generate data for a specific version. Leave blank for latest version."
type: string
required: false
permissions:
contents: write
actions: read
env:
MANIFEST_URL: "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"
jobs:
check-version:
name: "Check version"
runs-on: ubuntu-24.04
steps:
- name: "Fetch latest Minecraft version"
id: "fetch-latest-version"
if: inputs.VERSION == ''
run: |
LATEST_VERSION=$(curl -L $MANIFEST_URL | jq -r '.latest.snapshot')
echo "Found latest snapshot: \"$LATEST_VERSION\""
echo "LATEST_VERSION=$LATEST_VERSION" >> "$GITHUB_OUTPUT"
- name: "Checkout repository"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Check for existing version tag"
id: "check-for-existing-tag"
env:
VERSION: ${{ steps.fetch-latest-version.outputs.LATEST_VERSION || inputs.VERSION }}
run: |
if git show-ref --tags --verify --quiet "refs/tags/$VERSION"; then
echo "Tag \"$VERSION\" already exists. Skipping next jobs."
echo "TAG_EXISTS=TRUE" >> "$GITHUB_OUTPUT"
else
echo "Tag \"$VERSION\" does not exist. Running next jobs."
echo "TAG_EXISTS=FALSE" >> "$GITHUB_OUTPUT"
fi
outputs:
TAG_EXISTS: ${{ steps.check-for-existing-tag.outputs.TAG_EXISTS }}
VERSION: ${{ steps.fetch-latest-version.outputs.LATEST_VERSION || inputs.VERSION }}
generate-new-data:
name: "Generate new data"
runs-on: ubuntu-24.04
needs: [check-version]
if: needs.check-version.outputs.TAG_EXISTS == 'FALSE'
env:
VERSION: ${{ needs.check-version.outputs.VERSION }}
steps:
- name: Clone Go-Manifest
uses: actions/checkout@v4
with:
repository: "MinecraftPlayground/go-manifest"
path: "go-manifest"
- name: Clone Go-Manifest
uses: actions/checkout@v4
with:
repository: "Kesuaheli/nbtreader"
path: "nbtreader-source"
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: "go-manifest/go.mod"
- name: "Setup Dependencies"
run: |
sudo apt install rename
go build -C go-manifest -o ../getclient examples/get_client/main.go
go build -C nbtreader-source -o ../nbtreader cli/main.go
- name: "Download client.jar"
run: |
echo "Downloading client.jar for version \"$VERSION\""
./getclient $VERSION
rename 's/.*/client.jar/s' client_*.jar
echo "Saved client.jar"
- name: "Extract data from client.jar"
run: |
mkdir -p ./default
unzip client.jar "pack.png" -d "./default"
unzip client.jar "data/*" -d "./default"
- name: "Process extracted data"
run: |
echo "converting NBT files to SNBT"
for file in $(find default/ -name '*.nbt' -or -name '*.dat'); do
file=${file#default/}
echo NBT file \'$file\'
mkdir -p ./default_processed/$(dirname $file)
./nbtreader -out ./default_processed/${file%.*}.snbt default/$file
done
- name: "Upload data"
uses: actions/upload-artifact@v4
with:
name: "default_${{ env.VERSION }}"
path: "./default"
- name: "Upload processed data"
uses: actions/upload-artifact@v4
with:
name: "default_processed_${{ env.VERSION }}"
path: "./default_processed"
outputs:
VERSION: ${{ needs.check-version.outputs.VERSION }}
commit-and-tag-new-data:
name: "Commit and tag new data"
runs-on: ubuntu-latest
needs: [generate-new-data]
env:
VERSION: ${{ needs.generate-new-data.outputs.VERSION }}
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
ref: "generated"
- name: "Remove old data"
run: |
git rm -rf --ignore-unmatch "./"
- name: "Add new data"
uses: actions/download-artifact@v4
with:
name: "default_${{ env.VERSION }}"
path: "./"
- name: "Commit and push data"
run: |
echo "Commit Message: \"New data for version $VERSION\""
echo "Tag: \"$VERSION\""
echo "Tag Message: \"Version $VERSION\""
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -a -m "New data for version $VERSION" || exit 0
git tag -a "$VERSION" -m "Version $VERSION"
git push origin generated --tags
commit-and-tag-processed-data:
name: "Commit and tag processed data"
runs-on: ubuntu-latest
needs: [generate-new-data]
env:
VERSION: ${{ needs.generate-new-data.outputs.VERSION }}
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
ref: "processed"
- name: "Remove old data"
run: |
git rm -rf --ignore-unmatch "./"
- name: "Add new data"
uses: actions/download-artifact@v4
with:
name: "default_processed_${{ env.VERSION }}"
path: "./"
- name: "Commit and push data"
run: |
echo "Commit Message: \"Processed data for version $VERSION\""
echo "Tag: \"$VERSION-PROCESSED\""
echo "Tag Message: \"Version $VERSION\""
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -a -m "Processed data for version $VERSION" || exit 0
git tag -a "$VERSION-PROCESSED" -m "Version $VERSION (processed)"
git push origin processed --tags