Skip to content

Build APK

Build APK #53

Workflow file for this run

name: Build APK
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
on:
workflow_dispatch:
inputs:
url:
description: 'Website URL'
required: true
default: 'https://deckk.it'
type: string
app_name:
description: 'App Name'
required: true
default: 'deckk.it'
type: string
package_name:
description: 'Package Name'
required: true
default: 'com.deckk.it'
type: string
favicon_url:
description: 'Favicon URL (optional)'
required: false
default: 'https://deckk.it/images/favicon.svg'
type: string
bump_type:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
build_type:
description: 'Build Type'
required: true
default: 'release'
type: choice
options:
- release
- debug
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get latest version
id: version
run: |
git fetch --tags
LATEST_TAG=$(git tag --list 'v*' --sort=-v:refname | head -1 | sed 's/^v//')
VERSION=${LATEST_TAG:-0.0.0}
echo "Latest version: $VERSION"
IFS='.' read -ra PARTS <<< "$VERSION"
MAJOR=${PARTS[0]:-0}
MINOR=${PARTS[1]:-0}
PATCH=${PARTS[2]:-0}
BUMP_TYPE="${{ github.event.inputs.bump_type }}"
if [ "$BUMP_TYPE" = "major" ]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [ "$BUMP_TYPE" = "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
else
PATCH=$((PATCH + 1))
fi
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
VERSION_CODE=$((MAJOR * 1000 + MINOR * 100 + PATCH))
echo "New version: $NEW_VERSION, VERSION_CODE: $VERSION_CODE"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up keystore
run: |
if [ "${{ github.event.inputs.build_type }}" = "release" ]; then
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > keystore.jks
else
touch keystore.jks
fi
- name: Build Docker image (release)
if: ${{ github.event.inputs.build_type == 'release' }}
uses: docker/build-push-action@v5
with:
context: .
push: false
load: true
tags: webview-builder
build-args: |
WEBSITE_URL=${{ github.event.inputs.url }}
APP_NAME=${{ github.event.inputs.app_name }}
PACKAGE_NAME=${{ github.event.inputs.package_name }}
FAVICON_URL=${{ github.event.inputs.favicon_url }}
BUILD_TYPE=${{ github.event.inputs.build_type }}
VERSION=${{ steps.version.outputs.version }}
VERSION_CODE=${{ steps.version.outputs.version_code }}
KEYSTORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS=${{ secrets.KEY_ALIAS }}
KEY_PASSWORD=${{ secrets.KEY_PASSWORD }}
env:
WEBSITE_URL: ${{ github.event.inputs.url }}
APP_NAME: ${{ github.event.inputs.app_name }}
PACKAGE_NAME: ${{ github.event.inputs.package_name }}
FAVICON_URL: ${{ github.event.inputs.favicon_url }}
VERSION: ${{ steps.version.outputs.version }}
VERSION_CODE: ${{ steps.version.outputs.version_code }}
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
- name: Build Docker image (debug)
if: ${{ github.event.inputs.build_type == 'debug' }}
uses: docker/build-push-action@v5
with:
context: .
push: false
load: true
tags: webview-builder
build-args: |
WEBSITE_URL=${{ github.event.inputs.url }}
APP_NAME=${{ github.event.inputs.app_name }}
PACKAGE_NAME=${{ github.event.inputs.package_name }}
FAVICON_URL=${{ github.event.inputs.favicon_url }}
BUILD_TYPE=${{ github.event.inputs.build_type }}
VERSION=${{ steps.version.outputs.version }}
VERSION_CODE=${{ steps.version.outputs.version_code }}
env:
WEBSITE_URL: ${{ github.event.inputs.url }}
APP_NAME: ${{ github.event.inputs.app_name }}
PACKAGE_NAME: ${{ github.event.inputs.package_name }}
FAVICON_URL: ${{ github.event.inputs.favicon_url }}
VERSION: ${{ steps.version.outputs.version }}
VERSION_CODE: ${{ steps.version.outputs.version_code }}
- name: Extract APK from container
run: |
CONTAINER_ID=$(docker run -d webview-builder)
echo "Container started: $CONTAINER_ID"
sleep 5
APK_PATH=$(docker exec "$CONTAINER_ID" find /project -name "*.apk" | head -1)
echo "Found APK at: $APK_PATH"
docker cp "$CONTAINER_ID:$APK_PATH" ./temp.apk
docker rm -f "$CONTAINER_ID"
VERSION=${{ steps.version.outputs.version }}
mv temp.apk ${{ github.event.inputs.app_name }}-${VERSION}.apk
- name: Verify APK exists
run: |
if [ ! -f "${{ github.event.inputs.app_name }}-${{ steps.version.outputs.version }}.apk" ]; then
echo "Error: APK file not found"
exit 1
fi
ls -lh ${{ github.event.inputs.app_name }}-${{ steps.version.outputs.version }}.apk
- name: Create GitHub Release
if: ${{ github.event.inputs.build_type == 'release' }}
uses: softprops/action-gh-release@v2
with:
name: ${{ github.event.inputs.app_name }} v${{ steps.version.outputs.version }}
tag_name: v${{ steps.version.outputs.version }}
draft: false
prerelease: false
generate_release_notes: true
files: ${{ github.event.inputs.app_name }}-${{ steps.version.outputs.version }}.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Tag release
if: ${{ github.event.inputs.build_type == 'release' }}
run: |
git tag -d v${{ steps.version.outputs.version }} 2>/dev/null || true
git tag v${{ steps.version.outputs.version }}
git push origin v${{ steps.version.outputs.version }}
- name: Cleanup secrets
if: always()
run: |
rm -f keystore.jks