Generate Assets #164
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Generate Assets' | |
on: | |
schedule: | |
- cron: "30 0,12 * * *" # Runs at 00:30 and 12:30, every day | |
workflow_dispatch: | |
permissions: | |
contents: write | |
actions: read | |
checks: write | |
jobs: | |
check-version: | |
name: 'Check version' | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'Check for version change' | |
id: 'minecraft-manifest' | |
uses: MinecraftPlayground/minecraft-manifest@main | |
with: | |
token: ${{secrets.GITHUB_TOKEN}} | |
- name: 'Check for existing version' | |
id: 'check-existing-tag' | |
if: steps.minecraft-manifest.outputs.version-changed | |
uses: mukunku/tag-exists-action@v1.6.0 | |
with: | |
tag: ${{steps.minecraft-manifest.outputs.version-current-snapshot}} | |
outputs: | |
generate-new: ${{steps.minecraft-manifest.outputs.version-changed && steps.check-existing-tag.outputs.exists == 'false'}} | |
version-current-snapshot: ${{steps.minecraft-manifest.outputs.version-current-snapshot}} | |
version-current-snapshot-url: ${{steps.minecraft-manifest.outputs.version-current-snapshot-url}} | |
generate-new-assets: | |
name: 'Generate new assets' | |
runs-on: ubuntu-latest | |
needs: [check-version] | |
if: needs.check-version.outputs.generate-new == 'true' | |
steps: | |
- name: 'Download JSON manifest file' | |
run: | | |
mkdir ./download | |
curl -L -o ./download/manifest.json ${{needs.check-version.outputs.version-current-snapshot-url}} | |
- name: 'Downloading client.jar' | |
run: | | |
JAR_URL=$(jq -r '.downloads.client.url' ./download/manifest.json) | |
echo "Downloading client.jar from $JAR_URL" | |
curl -L -o ./download/client.jar $JAR_URL | |
- name: 'Extracting assets' | |
run: | | |
mkdir -p ./generated | |
unzip ./download/client.jar "pack.png" -d "./generated" | |
unzip ./download/client.jar "assets/*" -d "./generated" | |
- name: 'Uploading artifact' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: 'generated' | |
path: './generated' | |
outputs: | |
version-current-snapshot: ${{needs.check-version.outputs.version-current-snapshot}} | |
commit-and-tag-new-assets: | |
name: 'Commit and tag new assets' | |
runs-on: ubuntu-latest | |
needs: [generate-new-assets] | |
env: | |
VERSION_CURRENT_SNAPSHOT: "${{needs.generate-new-assets.outputs.version-current-snapshot}}" | |
steps: | |
- name: 'Checkout repository' | |
uses: actions/checkout@v4 | |
- name: 'Remove old assets' | |
run: | | |
git rm -rf --ignore-unmatch "./generated" | |
- name: 'Add new assets' | |
uses: actions/download-artifact@v4 | |
with: | |
name: 'generated' | |
path: './generated' | |
- name: 'Commit and push assets' | |
run: | | |
echo "Commit Message: New assets for version ${{env.VERSION_CURRENT_SNAPSHOT}}" | |
echo "Tag: ${{env.VERSION_CURRENT_SNAPSHOT}}" | |
echo "Tag Message: Release ${{env.VERSION_CURRENT_SNAPSHOT}}" | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git add "./generated" | |
git commit -a -m "New assets for version ${{env.VERSION_CURRENT_SNAPSHOT}}" || exit 0 | |
git tag -a "${{env.VERSION_CURRENT_SNAPSHOT}}" -m "Release ${{env.VERSION_CURRENT_SNAPSHOT}}" | |
git push origin main --tags |