102 lines
4.3 KiB
YAML
102 lines
4.3 KiB
YAML
name: build-elsword-ge
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "0 4 * * *"
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
build-release:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout repository
|
|
run: |
|
|
git init .
|
|
git config --global --add safe.directory "$PWD"
|
|
git remote add origin "${{ gitea.server_url }}/${{ gitea.repository }}.git"
|
|
git -c http.extraHeader="Authorization: token ${{ secrets.GITEA_TOKEN }}" fetch --depth 1 origin "${{ gitea.sha }}"
|
|
git checkout --detach FETCH_HEAD
|
|
|
|
- name: Build Elsword Proton-GE 10-34 tool
|
|
run: |
|
|
nix develop -c ./build.sh --no-install
|
|
|
|
- name: Create or update Gitea release
|
|
env:
|
|
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
|
GITEA_REPOSITORY: ${{ gitea.repository }}
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
GITEA_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
nix develop -c bash -lc '
|
|
set -euo pipefail
|
|
set -a
|
|
. dist/package-info.env
|
|
set +a
|
|
|
|
RELEASE_API="${GITEA_SERVER_URL}/api/v1/repos/${GITEA_REPOSITORY}/releases"
|
|
RELEASE_TAG_URL="$(python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe=\"\"))" "$RELEASE_TAG")"
|
|
ARCHIVE_URL_NAME="$(python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe=\"\"))" "$ARCHIVE_FILE")"
|
|
|
|
HTTP_CODE="$(curl -s -o /tmp/release.json -w "%{http_code}" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${RELEASE_API}/tags/${RELEASE_TAG_URL}")"
|
|
|
|
if [ "$HTTP_CODE" = "200" ]; then
|
|
RELEASE_ID="$(python3 -c "import json; print(json.load(open(\"/tmp/release.json\"))[\"id\"])" )"
|
|
elif [ "$HTTP_CODE" = "404" ]; then
|
|
python3 -c "import json, pathlib, os; pathlib.Path(\"/tmp/release-create.json\").write_text(json.dumps({
|
|
\"tag_name\": os.environ[\"RELEASE_TAG\"],
|
|
\"target_commitish\": os.environ[\"GITEA_SHA\"],
|
|
\"name\": os.environ[\"RELEASE_TAG\"],
|
|
\"body\": pathlib.Path(\"dist/release-notes.md\").read_text(),
|
|
\"draft\": False,
|
|
\"prerelease\": False,
|
|
}))"
|
|
curl --fail-with-body \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
--data-binary @/tmp/release-create.json \
|
|
"${RELEASE_API}" > /tmp/release.json
|
|
RELEASE_ID="$(python3 -c "import json; print(json.load(open(\"/tmp/release.json\"))[\"id\"])" )"
|
|
else
|
|
cat /tmp/release.json
|
|
exit 1
|
|
fi
|
|
|
|
python3 -c "import json, pathlib, os; pathlib.Path(\"/tmp/release-update.json\").write_text(json.dumps({
|
|
\"tag_name\": os.environ[\"RELEASE_TAG\"],
|
|
\"target_commitish\": os.environ[\"GITEA_SHA\"],
|
|
\"name\": os.environ[\"RELEASE_TAG\"],
|
|
\"body\": pathlib.Path(\"dist/release-notes.md\").read_text(),
|
|
\"draft\": False,
|
|
\"prerelease\": False,
|
|
}))"
|
|
curl --fail-with-body \
|
|
-X PATCH \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
--data-binary @/tmp/release-update.json \
|
|
"${RELEASE_API}/${RELEASE_ID}" > /tmp/release.json
|
|
|
|
curl --fail-with-body \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${RELEASE_API}/${RELEASE_ID}/assets" > /tmp/assets.json
|
|
|
|
EXISTING_ASSET_ID="$(python3 -c "import json, os; data=json.load(open(\"/tmp/assets.json\")); target=os.environ[\"ARCHIVE_FILE\"]; print(next((str(item[\"id\"]) for item in data if item.get(\"name\") == target), \"\"))")"
|
|
if [ -n "$EXISTING_ASSET_ID" ]; then
|
|
curl --fail-with-body \
|
|
-X DELETE \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${RELEASE_API}/${RELEASE_ID}/assets/${EXISTING_ASSET_ID}"
|
|
fi
|
|
|
|
curl --fail-with-body \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
--data-binary @"dist/${ARCHIVE_FILE}" \
|
|
"${RELEASE_API}/${RELEASE_ID}/assets?name=${ARCHIVE_URL_NAME}"
|
|
'
|