Skip to content

Generate Data

Generate Data #4

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: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: "go-manifest/go.mod"
- name: "Download client.jar"
run: |
sudo apt install rename
echo "Downloading client.jar for version \"$VERSION\""
go run -C go-manifest examples/get_client/main.go $VERSION
rename 's/.*/client.jar/s' go-manifest/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: "Upload data"
uses: actions/upload-artifact@v4
with:
name: "default_${{ env.VERSION }}"
path: "./default"
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