Fix build action.
Build and Release OpenMQTTGateway Firmware / Build Firmware & Publish Gitea Release (push) Successful in 15m16s
Build and Release OpenMQTTGateway Firmware / Build Firmware & Publish Gitea Release (push) Successful in 15m16s
This commit is contained in:
1 parent
b1e2301ea1
commit
02a8732318
1 file changed
+12
-6
@@ -59,7 +59,7 @@ jobs:
|
||||
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
|
||||
TAG_NAME="${GITHUB_REF_NAME}"
|
||||
else
|
||||
BASE_VERSION="$(git describe --tags --abbrev=0 2>/dev/null || echo v1.7.0)"
|
||||
BASE_VERSION="$(git describe --tags --abbrev=0 --exclude '*-b*' 2>/dev/null || echo v1.7.0)"
|
||||
TAG_NAME="${BASE_VERSION}-b${GITHUB_RUN_NUMBER}-${SHORT_SHA}"
|
||||
fi
|
||||
|
||||
@@ -91,11 +91,13 @@ jobs:
|
||||
- name: Create Gitea Release and Publish Package
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITEA_PKG_TOKEN: ${{ secrets.GITEATOKEN }}
|
||||
PIO_ENV: ${{ steps.prep.outputs.pio_env }}
|
||||
TAG_NAME: ${{ steps.prep.outputs.tag_name }}
|
||||
SHORT_SHA: ${{ steps.prep.outputs.short_sha }}
|
||||
run: |
|
||||
python3 - << 'EOF'
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
@@ -105,7 +107,9 @@ jobs:
|
||||
server_url = os.environ["GITHUB_SERVER_URL"].rstrip("/")
|
||||
repo = os.environ["GITHUB_REPOSITORY"]
|
||||
owner, repo_name = repo.split("/", 1)
|
||||
actor = os.environ.get("GITHUB_ACTOR") or owner
|
||||
token = os.environ["GITEA_TOKEN"]
|
||||
pkg_token = os.environ.get("GITEA_PKG_TOKEN") or token
|
||||
tag_name = os.environ["TAG_NAME"]
|
||||
sha = os.environ["GITHUB_SHA"]
|
||||
short_sha = os.environ["SHORT_SHA"]
|
||||
@@ -156,8 +160,10 @@ jobs:
|
||||
print(f"Created release ID {release_id} for tag {tag_name}")
|
||||
|
||||
# Upload firmware binary to Release and Gitea Package Registry
|
||||
# Note: Gitea's Generic Package Registry upload router is at /api/packages/ (not /api/v1/packages/)
|
||||
package_name = f"{repo_name}-{pio_env}"
|
||||
pkg_base = f"{server_url}/api/v1/packages/{owner}/generic/{package_name}/{tag_name}"
|
||||
pkg_base = f"{server_url}/api/packages/{owner}/generic/{package_name}/{tag_name}"
|
||||
basic_auth = base64.b64encode(f"{actor}:{pkg_token}".encode("utf-8")).decode("ascii")
|
||||
|
||||
for filename in sorted(os.listdir("dist")):
|
||||
if filename in existing_assets:
|
||||
@@ -170,7 +176,7 @@ jobs:
|
||||
filepath = os.path.join("dist", filename)
|
||||
print(f"Uploading {filename} to Release...")
|
||||
subprocess.run([
|
||||
"curl", "--fail", "-sS", "-X", "POST",
|
||||
"curl", "--fail", "-sS", "-o", "/dev/null", "-X", "POST",
|
||||
"-H", f"Authorization: token {token}",
|
||||
"-F", f"attachment=@{filepath}",
|
||||
f"{api_base}/releases/{release_id}/assets?name={filename}"
|
||||
@@ -182,7 +188,7 @@ jobs:
|
||||
try:
|
||||
del_pkg_req = urllib.request.Request(
|
||||
pkg_file_url,
|
||||
headers={"Authorization": f"token {token}"},
|
||||
headers={"Authorization": f"Basic {basic_auth}"},
|
||||
method="DELETE",
|
||||
)
|
||||
urllib.request.urlopen(del_pkg_req).close()
|
||||
@@ -191,8 +197,8 @@ jobs:
|
||||
raise
|
||||
print(f"Publishing {filename} to Gitea Package {package_name}/{tag_name}...")
|
||||
subprocess.run([
|
||||
"curl", "--fail", "-sS", "-X", "PUT",
|
||||
"-H", f"Authorization: token {token}",
|
||||
"curl", "--fail", "-sS", "-o", "/dev/null", "-X", "PUT",
|
||||
"--user", f"{actor}:{pkg_token}",
|
||||
"--upload-file", filepath,
|
||||
pkg_file_url,
|
||||
], check=True)
|
||||
|
||||
Reference in new issue
Block a user