87 lines
3.1 KiB
YAML
87 lines
3.1 KiB
YAML
name: Build APK
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: docker-compose
|
|
|
|
steps:
|
|
- name: Checkout source code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup keystore and environment
|
|
run: |
|
|
# Keystore is binary, so it must be base64. Strip any whitespace/newlines first.
|
|
echo "${{ secrets.KEYSTORE_BASE64 }}" | tr -d '[:space:]' | base64 -d > app/key.jks
|
|
# Write the .env directly from plain secrets (no base64 dotenv to get wrong).
|
|
{
|
|
echo "KEYSTORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }}"
|
|
echo "KEY_ALIAS=${{ secrets.KEY_ALIAS }}"
|
|
echo "KEY_PASSWORD=${{ secrets.KEY_PASSWORD }}"
|
|
} > .build/release/.env
|
|
|
|
- name: Build APK
|
|
working-directory: .build/release
|
|
run: docker compose run --rm release
|
|
|
|
- name: Rename APK
|
|
run: |
|
|
APP_NAME="${{ gitea.repository }}"
|
|
APP_NAME="${APP_NAME//\//-}"
|
|
SHA="${{ gitea.sha }}"
|
|
SHORT="${SHA:0:7}"
|
|
find .build/release/release/ -maxdepth 1 -name "*.apk" | head -1 | xargs -I{} mv {} ".build/release/release/${APP_NAME}-${SHORT}.apk"
|
|
|
|
- name: Publish to rolling "dev" release
|
|
env:
|
|
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
|
GITEA_REPOSITORY: ${{ gitea.repository }}
|
|
GITEA_TOKEN: ${{ secrets.PAT_GITEA }}
|
|
SHA: ${{ gitea.sha }}
|
|
run: |
|
|
set -e
|
|
APP_NAME="${{ gitea.repository }}"
|
|
APP_NAME="${APP_NAME//\//-}"
|
|
SHORT="${SHA:0:7}"
|
|
TAG="dev"
|
|
ASSET_PATH=".build/release/release/${APP_NAME}-${SHORT}.apk"
|
|
API_URL="${GITEA_SERVER_URL}/api/v1/repos/${GITEA_REPOSITORY}"
|
|
AUTH="Authorization: token ${GITEA_TOKEN}"
|
|
|
|
# Remove the previous rolling release and its tag so "dev" always points at this commit.
|
|
OLD_ID=$(curl -s -H "$AUTH" "${API_URL}/releases/tags/${TAG}" | jq -r '.id // empty')
|
|
if [ -n "$OLD_ID" ]; then
|
|
curl -s -X DELETE -H "$AUTH" "${API_URL}/releases/${OLD_ID}" || true
|
|
fi
|
|
curl -s -X DELETE -H "$AUTH" "${API_URL}/tags/${TAG}" || true
|
|
|
|
RELEASE_RESPONSE=$(curl -s -X POST "${API_URL}/releases" \
|
|
-H "$AUTH" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"${TAG}\",
|
|
\"target_commitish\": \"${SHA}\",
|
|
\"name\": \"Latest dev build\",
|
|
\"body\": \"Automatic build of ${SHORT}.\",
|
|
\"prerelease\": true
|
|
}")
|
|
|
|
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id')
|
|
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
|
echo "Failed to create release:"
|
|
echo "$RELEASE_RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
ASSET_NAME=$(basename "$ASSET_PATH")
|
|
curl -s -X POST "${API_URL}/releases/${RELEASE_ID}/assets?name=${ASSET_NAME}" \
|
|
-H "$AUTH" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary "@${ASSET_PATH}"
|
|
|
|
echo "Published ${ASSET_NAME} to the '${TAG}' release."
|