feat: deploy APK to Gitea releases instead of local storage
All checks were successful
Build & Deploy APK / build (push) Successful in 1m44s
All checks were successful
Build & Deploy APK / build (push) Successful in 1m44s
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,29 +39,43 @@ jobs:
|
||||
echo "Using Gradle: $GRADLE_BIN"
|
||||
"$GRADLE_BIN" assembleRelease --no-daemon
|
||||
|
||||
- name: Deploy APK & update version
|
||||
- name: Deploy APK to Gitea release
|
||||
shell: bash
|
||||
run: |
|
||||
STORAGE="/home/user/itstransport/backend/storage/app/android"
|
||||
GITEA="http://192.168.5.10:3000"
|
||||
REPO="admin/itstransport-android"
|
||||
TOKEN="${{ secrets.GITHUB_TOKEN }}"
|
||||
|
||||
VERSION_NAME=$(grep 'versionName' app/build.gradle.kts | head -1 | sed 's/.*"\(.*\)".*/\1/')
|
||||
VERSION_CODE=$(grep 'versionCode' app/build.gradle.kts | head -1 | sed 's/[^0-9]*//g')
|
||||
COMMIT_MSG=$(git log -1 --pretty=%s)
|
||||
|
||||
APK=$(find app/build/outputs/apk/release -name "*.apk" | head -1)
|
||||
test -n "$APK" || { echo "ERROR: No APK found"; exit 1; }
|
||||
|
||||
cp "$APK" "$STORAGE/app-release.apk"
|
||||
TAG="v${VERSION_NAME}-${VERSION_CODE}"
|
||||
echo "Deploying $TAG — $(du -h "$APK" | cut -f1)"
|
||||
|
||||
COMMIT_MSG=$(git log -1 --pretty=%s | sed 's/"/\\"/g')
|
||||
python3 -c "
|
||||
import json
|
||||
data = {
|
||||
'versionName': '$VERSION_NAME',
|
||||
'versionCode': int('$VERSION_CODE'),
|
||||
'releaseNotes': \"$COMMIT_MSG\"
|
||||
}
|
||||
with open('$STORAGE/version.json', 'w') as f:
|
||||
json.dump(data, f, indent=4, ensure_ascii=False)
|
||||
f.write('\n')
|
||||
"
|
||||
# Delete existing release with same tag (if re-building same version)
|
||||
EXISTING=$(curl -s -H "Authorization: token $TOKEN" "$GITEA/api/v1/repos/$REPO/releases/tags/$TAG" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null)
|
||||
if [ -n "$EXISTING" ]; then
|
||||
curl -s -X DELETE -H "Authorization: token $TOKEN" "$GITEA/api/v1/repos/$REPO/releases/$EXISTING"
|
||||
echo "Deleted existing release $EXISTING"
|
||||
fi
|
||||
|
||||
echo "Deployed v${VERSION_NAME} (code ${VERSION_CODE}) — $(du -h "$STORAGE/app-release.apk" | cut -f1)"
|
||||
# Create release
|
||||
RELEASE_ID=$(curl -s -X POST -H "Authorization: token $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
"$GITEA/api/v1/repos/$REPO/releases" \
|
||||
-d "{\"tag_name\":\"$TAG\",\"name\":\"v$VERSION_NAME\",\"body\":\"$COMMIT_MSG\",\"draft\":false,\"prerelease\":false}" \
|
||||
| python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
|
||||
|
||||
echo "Created release ID: $RELEASE_ID"
|
||||
|
||||
# Upload APK as release asset
|
||||
curl -s -X POST -H "Authorization: token $TOKEN" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
"$GITEA/api/v1/repos/$REPO/releases/$RELEASE_ID/assets?name=itstransport.apk" \
|
||||
--data-binary @"$APK"
|
||||
|
||||
echo "APK uploaded to release $TAG"
|
||||
|
||||
Reference in New Issue
Block a user