Created
August 1, 2024 16:20
-
-
Save vinayakg/9d14e64f3a776a5f6b568267fa918bfb to your computer and use it in GitHub Desktop.
Github Action for Android
This file contains 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: Android CI/CD | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: "11" | |
distribution: "adopt" | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew assembleRelease | |
- name: Sign APK | |
uses: r0adkll/sign-android-release@v1 | |
with: | |
releaseDirectory: app/build/outputs/apk/release | |
signingKeyBase64: ${{ secrets.SIGNING_KEY }} | |
alias: ${{ secrets.ALIAS }} | |
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }} | |
keyPassword: ${{ secrets.KEY_PASSWORD }} | |
- name: Upload APK | |
uses: actions/upload-artifact@v3 | |
with: | |
name: app-release | |
path: app/build/outputs/apk/release/app-release-signed.apk | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.event_name != 'pull_request' | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Download APK artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: app-release | |
- name: Get version | |
id: package_version | |
run: echo ::set-output name=version::$(grep versionName app/build.gradle | awk '{print $2}' | tr -d \") | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.package_version.outputs.version }} | |
release_name: Release v${{ steps.package_version.outputs.version }} | |
draft: false | |
prerelease: false | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./app-release-signed.apk | |
asset_name: app-release-${{ steps.package_version.outputs.version }}.apk | |
asset_content_type: application/vnd.android.package-archive | |
- name: Upload to Google Play | |
uses: r0adkll/upload-google-play@v1 | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
with: | |
serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }} | |
packageName: com.yourcompany.yourapp | |
releaseFiles: app-release-signed.apk | |
track: production | |
- name: Get APK download URL | |
id: get_download_url | |
run: echo "::set-output name=url::https://github.com/${{ github.repository }}/releases/download/v${{ steps.package_version.outputs.version }}/app-release-${{ steps.package_version.outputs.version }}.apk" | |
- name: Send notification | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: ${{ job.status }} | |
text: New APK available at ${{ steps.get_download_url.outputs.url }} | |
webhook_url: ${{ secrets.SLACK_WEBHOOK }} | |
if: always() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment