-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (103 loc) · 3.66 KB
/
generate.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: 'Generate Assets'
on:
# schedule:
# - cron: '30 0,12 * * *' # Runs at 00:30 and 12:30, every day
workflow_call:
inputs:
VERSION:
description: 'Generate assets for a specific version. Used by "versions.yml" workflow to generate assets for multiple versions.'
type: string
required: true
workflow_dispatch:
inputs:
VERSION:
description: 'Generate assets 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-assets:
name: 'Generate new assets'
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: 'Generate assets to "./default"'
id: download_assets
uses: MinecraftPlayground/generate-assets@v3
with:
version: ${{ env.VERSION }}
parallel-downloads: 10
- name: 'Upload assets'
uses: actions/upload-artifact@v4
with:
name: 'default_${{ env.VERSION }}'
path: './default'
outputs:
VERSION: ${{ needs.check-version.outputs.VERSION }}
commit-and-tag-new-assets:
name: 'Commit and tag new assets'
runs-on: ubuntu-24.04
needs: [generate-new-assets]
env:
VERSION: ${{ needs.generate-new-assets.outputs.VERSION }}
steps:
- name: 'Checkout repository'
uses: actions/checkout@v4
with:
ref: 'generated'
- name: 'Remove old assets'
run: |
git rm -rf --ignore-unmatch "./"
- name: 'Add new assets'
uses: actions/download-artifact@v4
with:
name: 'default_${{ env.VERSION }}'
path: './'
- name: 'Commit and push assets'
run: |
echo "Commit Message: \"New assets 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 assets for version $VERSION" || exit 0
git tag -a "$VERSION" -m "Version $VERSION"
git push origin generated --tags