Skip to content

Update android.yml

Update android.yml #6

Workflow file for this run

name: Android Build and Release
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build release APK
run: ./gradlew assembleRelease
- name: Upload APK as artifact
uses: actions/upload-artifact@v2
with:
name: app-release.apk
path: app/build/outputs/apk/release/app-release.apk
- name: Get app version
id: app_version
run: |
version=$(grep 'versionName "' app/build.gradle | awk -F'"' '{print $2}')
echo "::set-output name=version::$version"
- name: Create Release
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
release_name="Release v${{ steps.app_version.outputs.version }}"
tag_name="v${{ steps.app_version.outputs.version }}"
response=$(curl -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"$tag_name\",\"name\":\"$release_name\",\"draft\":false,\"prerelease\":false}" \
https://api.github.com/repos/${{ github.repository }}/releases)
upload_url=$(echo $response | jq -r '.upload_url')
echo "::set-output name=upload_url::$upload_url"
- name: Upload Release Asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
upload_url=${{ steps.create_release.outputs.upload_url }}
asset_path=./app/build/outputs/apk/release/app-release.apk
asset_name=app-v${{ steps.app_version.outputs.version }}.apk
curl -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/vnd.android.package-archive" \
--data-binary "@$asset_path" \
"$upload_url?name=$asset_name"