diff --git a/.gitea/workflows/build-windows-cross-linux.yml b/.gitea/workflows/build-windows-cross-linux.yml index 395aeef..b4e9aee 100644 --- a/.gitea/workflows/build-windows-cross-linux.yml +++ b/.gitea/workflows/build-windows-cross-linux.yml @@ -130,6 +130,8 @@ jobs: 7z l dist-windows-cross/chengnan-windows-x86_64-cross.zip | grep 'platforms/' - name: Upload package to Gitea Packages + env: + PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }} run: | set -euo pipefail PACKAGE_NAME="chengnan-windows-x86_64-cross" @@ -137,14 +139,24 @@ jobs: VERSION="${VERSION:0:10}" OWNER="${GITHUB_REPOSITORY%%/*}" API_BASE="${GITHUB_SERVER_URL:-https://git.luochen570.cn}/api/packages/${OWNER}/generic/chengnan/${VERSION}" - TOKEN="${GITEA_TOKEN:-${GITHUB_TOKEN:-}}" + TOKEN="${PACKAGE_TOKEN:-${GITHUB_TOKEN:-}}" test -n "$TOKEN" - curl --fail --show-error --silent --location \ - --header "Authorization: token ${TOKEN}" \ - --upload-file "dist-windows-cross/${PACKAGE_NAME}.zip" \ - "${API_BASE}/${PACKAGE_NAME}.zip" - curl --fail --show-error --silent --location \ - --header "Authorization: token ${TOKEN}" \ - --upload-file "dist-windows-cross/${PACKAGE_NAME}.zip.sha256" \ - "${API_BASE}/${PACKAGE_NAME}.zip.sha256" + upload_file() { + local src="$1" + local url="$2" + local status + status="$(curl --show-error --silent --location \ + --header "Authorization: token ${TOKEN}" \ + --upload-file "$src" \ + --write-out '%{http_code}' \ + --output /tmp/gitea-upload-response.txt \ + "$url")" + if [ "$status" != "201" ] && [ "$status" != "200" ]; then + echo "Upload failed with HTTP ${status}: ${url}" >&2 + cat /tmp/gitea-upload-response.txt >&2 + exit 1 + fi + } + upload_file "dist-windows-cross/${PACKAGE_NAME}.zip" "${API_BASE}/${PACKAGE_NAME}.zip" + upload_file "dist-windows-cross/${PACKAGE_NAME}.zip.sha256" "${API_BASE}/${PACKAGE_NAME}.zip.sha256" echo "Package uploaded to: ${API_BASE}/"