129 lines
3.9 KiB
YAML
129 lines
3.9 KiB
YAML
name: Build APK
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: cimg/android:2024.01
|
|
|
|
steps:
|
|
- name: Install Node.js
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y curl
|
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
|
sudo apt-get install -y nodejs
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Generate Gradle Wrapper
|
|
run: gradle wrapper
|
|
|
|
- name: Grant execute permission
|
|
run: chmod +x ./gradlew
|
|
|
|
- name: Build APK
|
|
run: ./gradlew assembleRelease
|
|
|
|
- name: Locate APK
|
|
id: locate_apk
|
|
run: |
|
|
set -e
|
|
APK_PATH=$(ls app/build/outputs/apk/release/*.apk | head -n1 || true)
|
|
if [ -z "$APK_PATH" ]; then
|
|
echo "No APK found in app/build/outputs/apk/release" >&2
|
|
exit 1
|
|
fi
|
|
echo "APK_PATH=$APK_PATH" >> $GITHUB_ENV
|
|
echo "Found $APK_PATH"
|
|
|
|
# Note: uploading artifacts with actions/upload-artifact@v4 is not supported
|
|
# on some self-hosted/enterprise runners (GHES). We skip storing artifacts
|
|
# via that action and instead upload the APK directly to the Gitea release
|
|
# in the steps below.
|
|
|
|
- name: Create Gitea release
|
|
id: create_release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GIT_TOKEN }}
|
|
GITEA_SERVER: ${{ secrets.GIT_SERVER }}
|
|
run: |
|
|
set -e
|
|
|
|
API_BASE="${GITEA_SERVER}/api/v1"
|
|
|
|
# Gitea Actions są kompatybilne z GITHUB_ envs
|
|
OWNER="${{ github.repository_owner }}"
|
|
REPO_NAME=$(echo "${{ github.repository }}" | cut -d/ -f2)
|
|
TAG="${{ github.ref_name }}"
|
|
|
|
echo "URL: $API_BASE/repos/$OWNER/$REPO_NAME/releases"
|
|
echo "OWNER=$OWNER"
|
|
echo "REPO_NAME=$REPO_NAME"
|
|
echo "TAG=$TAG"
|
|
|
|
if [ -z "$TAG" ]; then
|
|
echo "Error: TAG (ref_name) is empty. Ensure you pushed a tag."
|
|
exit 1
|
|
fi
|
|
|
|
CREATE_RESPONSE=$(curl -s \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-X POST \
|
|
-d "{
|
|
\"tag_name\": \"$TAG\",
|
|
\"name\": \"$TAG\",
|
|
\"body\": \"Automated release for $TAG\",
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}" \
|
|
"$API_BASE/repos/$OWNER/$REPO_NAME/releases")
|
|
|
|
echo "$CREATE_RESPONSE"
|
|
|
|
RELEASE_ID=$(echo "$CREATE_RESPONSE" \
|
|
| grep -o '"id":[0-9]*' \
|
|
| head -n1 \
|
|
| cut -d: -f2)
|
|
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "Failed to create release"
|
|
exit 1
|
|
fi
|
|
|
|
echo "RELEASE_ID=$RELEASE_ID" >> $GITEA_ENV
|
|
- name: Upload APK to Gitea release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GIT_TOKEN }}
|
|
GITEA_SERVER: ${{ secrets.GIT_SERVER }}
|
|
run: |
|
|
set -e
|
|
API_BASE=${GITEA_SERVER:+$GITEA_SERVER/api/v1}
|
|
API_BASE=${API_BASE:-https://gitea.com/api/v1}
|
|
REMOTE_URL=$(git config --get remote.origin.url || true)
|
|
REPO_FULL=$(echo "$REMOTE_URL" | sed -E 's#.*[:/](.+/.+)\.git$#\1#')
|
|
OWNER=$(echo "$REPO_FULL" | cut -d/ -f1)
|
|
REPO_NAME=$(echo "$REPO_FULL" | cut -d/ -f2)
|
|
APK_PATH=${APK_PATH:-$APK_PATH}
|
|
if [ -z "$APK_PATH" ]; then
|
|
echo "APK_PATH not set" >&2
|
|
exit 1
|
|
fi
|
|
RELEASE_ID=${RELEASE_ID}
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "RELEASE_ID not set" >&2
|
|
exit 1
|
|
fi
|
|
|
|
UPLOAD_URL="$API_BASE/repos/$OWNER/$REPO_NAME/releases/$RELEASE_ID/assets?name=$(basename $APK_PATH)"
|
|
echo "Uploading $APK_PATH to $UPLOAD_URL"
|
|
|
|
curl --fail -H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/octet-stream" \
|
|
--data-binary @"$APK_PATH" "$UPLOAD_URL"
|