Build WebView App #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build WebView App | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| app_name: | |
| description: 'App Name (e.g., My Cool App)' | |
| required: true | |
| type: string | |
| website_url: | |
| description: 'Website URL (e.g., https://example.com)' | |
| required: true | |
| type: string | |
| app_icon_url: | |
| description: 'App Icon URL (direct link to PNG/JPG image, 512x512 recommended)' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| name: Build WebView APK | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Validate Inputs | |
| run: | | |
| if [ -z "${{ inputs.app_name }}" ]; then | |
| echo "Error: App name is required" | |
| exit 1 | |
| fi | |
| if [ -z "${{ inputs.website_url }}" ]; then | |
| echo "Error: Website URL is required" | |
| exit 1 | |
| fi | |
| if [ -z "${{ inputs.app_icon_url }}" ]; then | |
| echo "Error: App Icon URL is required" | |
| exit 1 | |
| fi | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - name: Download and Process App Icon | |
| run: | | |
| # Download the icon | |
| curl -L -o icon_original.png "${{ inputs.app_icon_url }}" | |
| # Install ImageMagick for image processing | |
| sudo apt-get update && sudo apt-get install -y imagemagick | |
| # Create icons for different densities | |
| convert icon_original.png -resize 48x48 app/src/main/res/mipmap-mdpi/ic_launcher.png | |
| convert icon_original.png -resize 72x72 app/src/main/res/mipmap-hdpi/ic_launcher.png | |
| convert icon_original.png -resize 96x96 app/src/main/res/mipmap-xhdpi/ic_launcher.png | |
| convert icon_original.png -resize 144x144 app/src/main/res/mipmap-xxhdpi/ic_launcher.png | |
| convert icon_original.png -resize 192x192 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png | |
| - name: Configure App Settings | |
| run: | | |
| # Create the app configuration file | |
| echo "APP_NAME=${{ inputs.app_name }}" > app/app.properties | |
| echo "WEBSITE_URL=${{ inputs.website_url }}" >> app/app.properties | |
| # Update AndroidManifest.xml with app name | |
| sed -i 's/android:label="[^"]*"/android:label="${{ inputs.app_name }}"/g' app/src/main/AndroidManifest.xml | |
| - name: Create settings.gradle | |
| run: | | |
| # Sanitize app name for project name (remove special chars, replace spaces) | |
| SANITIZED_NAME=$(echo "${{ inputs.app_name }}" | tr ' ' '_' | tr -cd '[:alnum:]_') | |
| echo "pluginManagement {" > settings.gradle | |
| echo " repositories {" >> settings.gradle | |
| echo " google()" >> settings.gradle | |
| echo " mavenCentral()" >> settings.gradle | |
| echo " gradlePluginPortal()" >> settings.gradle | |
| echo " }" >> settings.gradle | |
| echo "}" >> settings.gradle | |
| echo "dependencyResolutionManagement {" >> settings.gradle | |
| echo " repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)" >> settings.gradle | |
| echo " repositories {" >> settings.gradle | |
| echo " google()" >> settings.gradle | |
| echo " mavenCentral()" >> settings.gradle | |
| echo " }" >> settings.gradle | |
| echo "}" >> settings.gradle | |
| echo "rootProject.name = '${SANITIZED_NAME}'" >> settings.gradle | |
| echo "include ':app'" >> settings.gradle | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v3 | |
| with: | |
| gradle-version: '8.4' | |
| - name: Build Debug APK | |
| run: | | |
| export APP_NAME="${{ inputs.app_name }}" | |
| export WEBSITE_URL="${{ inputs.website_url }}" | |
| # Generate unique package suffix from app name | |
| PACKAGE_SUFFIX=$(echo "${{ inputs.app_name }}" | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:]' | head -c 20) | |
| export PACKAGE_SUFFIX="${PACKAGE_SUFFIX}" | |
| gradle :app:assembleDebug --no-daemon | |
| - name: Prepare Release | |
| id: prepare_release | |
| run: | | |
| # Create a sanitized tag name from app name | |
| # Replace spaces with dashes, remove special characters, convert to lowercase | |
| TAG_NAME=$(echo "${{ inputs.app_name }}" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr -cd '[:alnum:]-' | head -c 50) | |
| # Add timestamp to make tag unique | |
| TIMESTAMP=$(date +%Y%m%d-%H%M%S) | |
| TAG_NAME="${TAG_NAME}-${TIMESTAMP}" | |
| echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT | |
| echo "release_name=${{ inputs.app_name }}" >> $GITHUB_OUTPUT | |
| # Rename APK to match app name | |
| SAFE_NAME=$(echo "${{ inputs.app_name }}" | tr ' ' '_' | tr -cd '[:alnum:]_') | |
| cp app/build/outputs/apk/debug/app-debug.apk "${SAFE_NAME}.apk" | |
| echo "apk_path=${SAFE_NAME}.apk" >> $GITHUB_OUTPUT | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.prepare_release.outputs.tag_name }} | |
| name: ${{ steps.prepare_release.outputs.release_name }} | |
| body: | | |
| **App Name:** ${{ inputs.app_name }} | |
| **Website URL:** ${{ inputs.website_url }} | |
| **Logo URL:** ${{ inputs.app_icon_url }} | |
| files: ${{ steps.prepare_release.outputs.apk_path }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |