generated from OPDMC/Template-MCServer
-
Notifications
You must be signed in to change notification settings - Fork 0
274 lines (233 loc) · 9.96 KB
/
release.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
name: Release Actions
# Org Secrets:
# - GHCR_USERNAME: GitHub Container Registry username (organization name)
# - GH_USERNAME: GitHub username (an organization admin)
# - GH_TOKEN: GitHub Container Registry token (PAT from an organization admin)
# - QUAY_USERNAME: Quay.io username
# - QUAY_PASSWORD: Quay.io password
# - DOCKERHUB_LOGINNAME: Docker Hub login username
# - DOCKERHUB_PASSWORD: Docker Hub password
# - DOCKERHUB_ORGNAME: Docker Hub organization name
on:
release:
types: [ published ]
jobs:
handle-docker-images:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GH_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_LOGINNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker Images
run: |
IMAGE_NAME=$(basename ${{ github.repository }})
IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')
OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
TAG=$(echo ${{ github.event.release.tag_name }} | tr '[:upper:]' '[:lower:]')
docker buildx create --use
docker buildx inspect --bootstrap
docker buildx build --platform linux/amd64,linux/arm64 --push -t ghcr.io/${OWNER}/${IMAGE_NAME}:${TAG} -t ghcr.io/${OWNER}/${IMAGE_NAME}:latest .
docker buildx build --platform linux/amd64,linux/arm64 --push -t ${{ secrets.DOCKERHUB_ORGNAME }}/${IMAGE_NAME}:${TAG} -t ${{ secrets.DOCKERHUB_ORGNAME }}/${IMAGE_NAME}:latest .
- name: Export Docker images to tar files
run: |
IMAGE_NAME=$(basename ${{ github.repository }})
IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')
TAG=$(echo ${{ github.event.release.tag_name }} | tr '[:upper:]' '[:lower:]')
ARCHS="amd64 arm64"
for ARCH in $ARCHS; do
FILE_NAME=docker-img_${IMAGE_NAME}_${TAG}_${ARCH}.tar
docker pull --platform linux/$ARCH ${{ secrets.DOCKERHUB_ORGNAME }}/${IMAGE_NAME}:${TAG}
docker save -o $FILE_NAME ${{ secrets.DOCKERHUB_ORGNAME }}/${IMAGE_NAME}:${TAG}
echo "FILE_NAME_$ARCH=$FILE_NAME" >> $GITHUB_ENV
done
- name: Upload Docker image tar (amd64) to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.FILE_NAME_amd64 }}
asset_name: ${{ env.FILE_NAME_amd64 }}
asset_content_type: application/x-tar
- name: Upload Docker image tar (arm64) to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.FILE_NAME_arm64 }}
asset_name: ${{ env.FILE_NAME_arm64 }}
asset_content_type: application/x-tar
handle-client-package:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up environment variables
id: vars
run: |
REPO_NAME=$(basename $GITHUB_REPOSITORY)
REPO_NAME_LOWER=$(echo $REPO_NAME | tr '[:upper:]' '[:lower:]')
RELEASE_TAG=$(echo ${{ github.ref }} | sed 's/refs\/tags\///')
RELEASE_TAG_LOWER=$(echo $RELEASE_TAG | tr '[:upper:]' '[:lower:]')
TEMP_DIR="client-versionpack_${REPO_NAME_LOWER}_${RELEASE_TAG_LOWER}"
TEMP_MOD_DIR="client-modpack_${REPO_NAME_LOWER}_${RELEASE_TAG_LOWER}"
echo "::set-output name=repo_name::$REPO_NAME"
echo "::set-output name=repo_name_lower::$REPO_NAME_LOWER"
echo "::set-output name=release_tag::$RELEASE_TAG"
echo "::set-output name=release_tag_lower::$RELEASE_TAG_LOWER"
echo "::set-output name=temp_dir::$TEMP_DIR"
echo "::set-output name=temp_mod_dir::$TEMP_MOD_DIR"
- name: Create temporary directory for version package
run: mkdir -p ${{ steps.vars.outputs.temp_dir }}
- name: Copy minecraft_client_versionpack to temporary directory
run: cp -r minecraft_client_versionpack ${{ steps.vars.outputs.temp_dir }}/${{ steps.vars.outputs.repo_name }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install pyunpack patool
- name: Run ClientPkgReformat.py script
run: python .github/scripts/ClientPkgReformat.py ${{ steps.vars.outputs.temp_dir }}/${{ steps.vars.outputs.repo_name }}
- name: Zip the directory for version package
run: |
cd ${{ steps.vars.outputs.temp_dir }}
zip -r ../${{ steps.vars.outputs.temp_dir }}.zip .
cd ..
- name: Upload version package zip to release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ steps.vars.outputs.temp_dir }}.zip
asset_name: ${{ steps.vars.outputs.temp_dir }}.zip
asset_content_type: application/zip
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Create temporary directory for modpack
run: mkdir -p ${{ steps.vars.outputs.temp_mod_dir }}
- name: Copy minecraft_client_modpack to temporary directory for modpack
run: cp -r minecraft_client_modpack/* ${{ steps.vars.outputs.temp_mod_dir }}
- name: Zip the directory for modpack
run: |
cd ${{ steps.vars.outputs.temp_mod_dir }}
zip -r ../${{ steps.vars.outputs.temp_mod_dir }}.zip .
cd ..
- name: Upload modpack zip to release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ steps.vars.outputs.temp_mod_dir }}.zip
asset_name: ${{ steps.vars.outputs.temp_mod_dir }}.zip
asset_content_type: application/zip
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
handle-file-uploads:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
token: ${{ secrets.GH_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Get previous tag
id: prev-tag
run: |
git fetch --tags
tags=$(git tag --sort=-creatordate | tr '\n' ' ')
echo "All tags: $tags"
tag_count=$(echo "$tags" | wc -w)
echo "Tag count: $tag_count"
if [ "$tag_count" -lt 2 ]; then
echo "Not enough tags to determine previous tag."
echo "UPDATE_README=false" >> $GITHUB_ENV
prev_tag=""
else
prev_tag=$(echo "$tags" | awk '{print $2}')
if [ -z "$prev_tag" ]; then
echo "Error: Could not determine previous tag." >&2
exit 1
fi
echo "Previous tag is $prev_tag"
echo "UPDATE_README=true" >> $GITHUB_ENV
fi
echo "PREV_TAG=$prev_tag" >> $GITHUB_ENV
- name: Get current tag
id: curr-tag
run: echo "CURR_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Get branch for release
id: branch
run: echo "BRANCH=main" >> $GITHUB_ENV
- name: Update version numbers
if: env.PREV_TAG != ''
env:
GITHUB_WORKSPACE: ${{ github.workspace }}
PREV_TAG: ${{ env.PREV_TAG }}
CURR_TAG: ${{ env.CURR_TAG }}
run: python .github/scripts/UpdateVersionNumber.py $GITHUB_WORKSPACE $PREV_TAG $CURR_TAG
- name: Configure Git
run: |
git config --global user.name 'version-updater[bot]'
git config --global user.email '[email protected]'
- name: Commit changes if any
run: |
git add .
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
git commit -m "Update version from ${{ env.PREV_TAG }} to ${{ env.CURR_TAG }}"
fi
- name: Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GH_TOKEN }}
branch: ${{ env.BRANCH }}
- name: Pull latest changes
run: git pull origin ${{ env.BRANCH }}
- name: Checkout repository
uses: actions/checkout@v2
with:
token: ${{ secrets.GH_TOKEN }}
- name: Get README content
id: get_readme
run: |
readme_content=$(cat README.md)
echo "README content: $readme_content"
echo "::set-output name=content::$readme_content"
- name: Convert repository name to lowercase
id: set-repo-name
run: echo "REPO_NAME=$(echo ${{ github.repository }} | awk -F/ '{print tolower($2)}')" >> $GITHUB_ENV
- name: Set DockerHub repository
id: set-dockerhub-repo
run: echo "DOCKERHUB_REPO=${{ secrets.DOCKERHUB_ORGNAME }}/$(echo ${{ github.repository }} | awk -F/ '{print tolower($2)}')" >> $GITHUB_ENV
- name: Update DockerHub README
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKERHUB_LOGINNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ env.DOCKERHUB_REPO }}
readme-filepath: README.md