This commit is contained in:
@@ -4,6 +4,8 @@ on:
|
||||
push:
|
||||
branches-ignore:
|
||||
- artifacts
|
||||
tags:
|
||||
- "v*"
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
@@ -30,6 +32,63 @@ jobs:
|
||||
- name: Build
|
||||
run: ./gradlew build --no-daemon
|
||||
|
||||
- name: Create Gitea release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
shell: bash
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
tag="${GITHUB_REF_NAME}"
|
||||
api="${GITHUB_SERVER_URL}/api/v1"
|
||||
release_name="WorldHandler ${tag}"
|
||||
jar="$(find build/libs -maxdepth 1 -name '*neoforge*.jar' -print -quit)"
|
||||
|
||||
if [ -z "${jar}" ]; then
|
||||
echo "No NeoForge jar found in build/libs" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
release_json="$(mktemp)"
|
||||
if ! curl -fsS \
|
||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H "Accept: application/json" \
|
||||
"${api}/repos/${GITHUB_REPOSITORY}/releases/tags/${tag}" \
|
||||
-o "${release_json}"; then
|
||||
export tag release_name GITHUB_SHA
|
||||
python3 -c 'import json, os; print(json.dumps({"tag_name": os.environ["tag"], "target_commitish": os.environ["GITHUB_SHA"], "name": os.environ["release_name"], "body": "NeoForge 21.1.225 build for Minecraft 1.21.1.", "draft": False, "prerelease": False}))' > "${release_json}"
|
||||
curl -fsS \
|
||||
-X POST \
|
||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @"${release_json}" \
|
||||
"${api}/repos/${GITHUB_REPOSITORY}/releases" \
|
||||
-o "${release_json}"
|
||||
fi
|
||||
|
||||
release_id="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["id"])' "${release_json}")"
|
||||
asset_name="$(basename "${jar}")"
|
||||
|
||||
python3 -c 'import json, sys; release = json.load(open(sys.argv[1])); asset_name = sys.argv[2]; [print(asset["id"]) for asset in release.get("assets", []) if asset.get("name") == asset_name]' "${release_json}" "${asset_name}" > assets-to-delete.txt
|
||||
|
||||
while read -r asset_id; do
|
||||
[ -z "${asset_id}" ] && continue
|
||||
curl -fsS \
|
||||
-X DELETE \
|
||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
"${api}/repos/${GITHUB_REPOSITORY}/releases/${release_id}/assets/${asset_id}"
|
||||
done < assets-to-delete.txt
|
||||
|
||||
curl -fsS \
|
||||
-X POST \
|
||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Content-Type: application/java-archive" \
|
||||
--data-binary @"${jar}" \
|
||||
"${api}/repos/${GITHUB_REPOSITORY}/releases/${release_id}/assets?name=${asset_name}"
|
||||
|
||||
- name: Publish jar to artifacts branch
|
||||
if: github.event_name != 'pull_request'
|
||||
shell: bash
|
||||
|
||||
Reference in New Issue
Block a user