Update android-build.yml #11
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 | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
release: | |
types: [created] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Decode Keystore | |
run: echo "${{ secrets.SIGNING_KEYSTORE }}" | base64 -d > signing.jks | |
- name: Cache Gradle dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', 'gradle/wrapper/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Get Current Version | |
id: get_version | |
run: | | |
VERSION=$(grep versionName app/build.gradle | awk -F'"' '{print $2}') | |
echo "::set-output name=current_version::$VERSION" | |
VERSION_CODE=$(grep versionCode app/build.gradle | awk '{print $2}') | |
echo "::set-output name=current_version_code::$VERSION_CODE" | |
- name: Increment Version | |
id: increment_version | |
shell: bash | |
run: | | |
CURRENT_VERSION="${{ steps.get_version.outputs.current_version }}" | |
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION" | |
patch=$((patch + 1)) | |
NEW_VERSION="v$major.$minor.$patch" | |
echo "::set-output name=new_version::$NEW_VERSION" | |
VERSION_CODE=$(( ${{ steps.get_version.outputs.current_version_code }} + 1 )) | |
echo "::set-output name=version_code::$VERSION_CODE" | |
- name: Update Version Code and Version Name in Gradle | |
run: | | |
sed -i "s/versionCode [0-9]\+/versionCode ${{ steps.increment_version.outputs.version_code }}/g" app/build.gradle | |
sed -i "s/versionName \"[0-9.]\+\"/versionName \"${{ steps.increment_version.outputs.new_version }}\"/g" app/build.gradle | |
- name: Run Lint | |
run: ./gradlew lint | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@v2 | |
with: | |
gradle-version: wrapper | |
arguments: assembleRelease | |
- name: Signed APK Builder | |
uses: TeamNecta/build-signed-apk@v2.1 | |
with: | |
java_version: 17 | |
keystore_b64: ${{ secrets.SIGNING_KEYSTORE }} | |
keystore_password: ${{ secrets.SIGNING_KEY_STORE_PASSWORD }} | |
key_alias: ${{ secrets.SIGNING_KEY_ALIAS }} | |
key_password: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: release-apk | |
path: app/build/outputs/apk/release/*.apk | |
- name: Check if Build Number is Multiple of 5 | |
id: check_multiple_of_5 | |
shell: bash | |
run: | | |
BUILD_NUMBER="${{ steps.increment_version.outputs.version_code }}" | |
if (( BUILD_NUMBER % 5 == 0 )); then | |
echo "::set-output name=is_multiple::true" | |
else | |
echo "::set-output name=is_multiple::false" | |
fi | |
- name: Create GitHub Pre-Release | |
if: steps.check_multiple_of_5.outputs.is_multiple == 'true' | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.increment_version.outputs.new_version }} | |
release_name: Pre-Release ${{ steps.increment_version.outputs.new_version }} | |
draft: false | |
prerelease: true | |
- name: Upload Release Asset | |
if: steps.check_multiple_of_5.outputs.is_multiple == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: app/build/outputs/apk/release/*.apk | |
asset_name: app-release.apk | |
asset_content_type: application/vnd.android.package-archive |