From 782b2dd82ed02f48277424413d988ad2dc9cea39 Mon Sep 17 00:00:00 2001 From: spdis Date: Wed, 26 Nov 2025 21:58:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86=E4=B8=80=E4=B8=8Bym?= =?UTF-8?q?l=E8=BF=9B=E8=A1=8C=E6=9E=84=E5=BB=BA=E5=92=8C=E5=8F=91?= =?UTF-8?q?=E5=B8=83[ci][0.2.3]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yml | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index c27e201..46add65 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -76,22 +76,18 @@ jobs: echo "$ART" > "$GITHUB_WORKSPACE/.artifact_name" - name: Upload to Alist run: | - python3 - << 'PY' - import os,requests,sys - base=os.environ['ALIST_URL'].rstrip('/') - user=os.environ['ALIST_USER'] - pwd=os.environ['ALIST_PASSWORD'] - ws=os.environ['GITHUB_WORKSPACE'] - art=open(os.path.join(ws,'.artifact_name'),'r',encoding='utf-8').read().strip() - fp=os.path.join(ws,art) - r=requests.post(base+'/api/auth/login',json={'username':user,'password':pwd}) - tok=(r.json().get('data') or {}).get('token') - if not tok: sys.exit(1) - requests.post(base+'/api/fs/mkdir',json={'path':'/ci'},headers={'Authorization':tok}) - files={'file':(art,open(fp,'rb'),'application/x-tar')} - s=requests.put(base+'/api/fs/form',data={'path':'/ci'},files=files,headers={'Authorization':tok}) - sys.exit(0 if s.status_code<400 else 1) - PY + ART=$(cat "$GITHUB_WORKSPACE/.artifact_name") + BASE="${ALIST_URL%/}" + LOGIN_RESP=$(curl -sS -X POST "$BASE/api/auth/login" -H "Content-Type: application/json" -d "{\"username\":\"$ALIST_USER\",\"password\":\"$ALIST_PASSWORD\"}") + TOKEN=$(echo "$LOGIN_RESP" | sed -n 's/.*"token":"\([^"]*\)".*/\1/p') + if [ -z "$TOKEN" ]; then TOKEN=$(echo "$LOGIN_RESP" | sed -n 's/.*"auth":"\([^"]*\)".*/\1/p'); fi + if [ -z "$TOKEN" ]; then exit 1; fi + curl -sS -X POST "$BASE/api/fs/mkdir" -H "Authorization: $TOKEN" -H "Content-Type: application/json" -d "{\"path\":\"/ci\"}" >/dev/null 2>&1 || true + UPLOAD_STATUS=$(curl -sS -w "%{http_code}" -o /dev/null -X PUT "$BASE/api/fs/form" -H "Authorization: $TOKEN" -F "path=/ci" -F "file=@$GITHUB_WORKSPACE/$ART;type=application/x-tar") + if [ "$UPLOAD_STATUS" -ge 400 ]; then + UPLOAD_STATUS=$(curl -sS -w "%{http_code}" -o /dev/null -X PUT "$BASE/api/fs/form" -H "Authorization: Bearer $TOKEN" -F "path=/ci" -F "file=@$GITHUB_WORKSPACE/$ART;type=application/x-tar") + fi + test "$UPLOAD_STATUS" -lt 400 - name: Create release with download link if: env.GITEA_TOKEN != '' run: | @@ -99,6 +95,6 @@ jobs: BRANCH=${GITHUB_REF#refs/heads/} TAG="$VERSION" NAME="$VERSION" - DL="$ALIST_URL/ci/$ART" + DL="${ALIST_URL%/}/ci/$ART" JSON=$(printf '{"tag_name":"%s","target_commitish":"%s","name":"%s","body":"%s"}' "$TAG" "$BRANCH" "$NAME" "$DL") curl -sS -X POST "$GITEA_SERVER/api/v1/repos/$GITEA_REPO/releases" -H "Content-Type: application/json" -H "Authorization: token $GITEA_TOKEN" -d "$JSON"