Android Release #8
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: Android Release | |
permissions: | |
contents: write | |
on: | |
workflow_dispatch: | |
inputs: | |
increment_major: | |
description: 'Increment Major Version by?' | |
required: true | |
default: 0 | |
type: number | |
increment_minor: | |
description: 'Increment Minor Version by?' | |
required: true | |
default: 0 | |
type: number | |
increment_patch: | |
description: 'Increment Patch Version by?' | |
required: true | |
default: 0 | |
type: number | |
changes_in_release: | |
description: 'Changes in release' | |
required: true | |
default: 'Minor changes' | |
type: string | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Important: get all tags! | |
- name: Get Latest Tag | |
run: | | |
latest_tag=$(git describe --tags --abbrev=0) | |
echo "LATEST_TAG=${latest_tag}" >> $GITHUB_ENV | |
- name: Generate Version | |
run: | | |
# Extract version components | |
version_base="${LATEST_TAG#v}" | |
major=$(echo $version_base | cut -d. -f1) | |
minor=$(echo $version_base | cut -d. -f2) | |
patch=$(echo $version_base | cut -d. -f3) | |
# Increment versions by the specified input values | |
new_major=$((major + ${{ github.event.inputs.increment_major }})) | |
new_minor=$((minor + ${{ github.event.inputs.increment_minor }})) | |
new_patch=$((patch + ${{ github.event.inputs.increment_patch }})) | |
# Construct the new version string | |
new_version="$new_major.$new_minor.$new_patch" | |
# Calculate the version code (e.g., 1.0.5 -> 10005) | |
version_code=$((new_major * 10000 + new_minor * 100 + new_patch)) | |
# Set environment variables | |
echo "NEW_VERSION_NAME=${new_version}" >> $GITHUB_ENV | |
echo "NEW_VERSION_CODE=${version_code}" >> $GITHUB_ENV | |
- name: Update build.gradle with new version code and version name | |
run: | | |
# Update versionCode and versionName in build.gradle | |
sed -i "s/versionCode [0-9]\+/versionCode ${NEW_VERSION_CODE}/" app/build.gradle | |
sed -i "s/versionName \"[^\"]*\"/versionName \"${NEW_VERSION_NAME}\"/" app/build.gradle | |
- name: Print Version | |
run: | | |
echo "Version Name: $NEW_VERSION_NAME" | |
echo "Version Code: $NEW_VERSION_CODE" | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: "temurin" | |
java-version: 21 | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v4 | |
- name: Build with Gradle | |
run: | | |
chmod +x ./gradlew | |
./gradlew assembleRelease | |
tree app/build/outputs/apk/release | |
- uses: qlenlen/[email protected] | |
name: Sign app APK | |
id: sign_app | |
with: | |
releaseDirectory: app/build/outputs/apk/release | |
signingKeyBase64: ${{ secrets.KEYSTORE }} | |
alias: ${{ secrets.KEY_ALIAS }} | |
keyStorePassword: ${{ secrets.KEYSTORE_PASSWORD }} | |
keyPassword: ${{ secrets.KEY_PASSWORD }} | |
env: | |
BUILD_TOOLS_VERSION: "35.0.0" | |
- name: Commit the changes | |
run: | | |
# Configure git user | |
git config user.name "github-actions" | |
git config user.email "[email protected]" | |
# Add modified build.gradle file | |
git add app/build.gradle | |
# Commit the changes | |
git commit -m "Update versionName and versionCode to ${NEW_VERSION_NAME} and ${NEW_VERSION_CODE}" | |
# Push changes to the current branch | |
git push https://github-actions:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} HEAD:${GITHUB_REF#refs/heads/} | |
- name: Rename APK | |
run: | | |
ls -al app/build/outputs/apk/release | |
echo "Signed APK: ${{steps.sign_app.outputs.signedReleaseFile}}" | |
cp ${{steps.sign_app.outputs.signedReleaseFile}} KernelFlasher.apk | |
- name: Upload APK | |
uses: actions/[email protected] | |
with: | |
name: KernelFlasher | |
path: KernelFlasher.apk | |
- name: Upload release | |
uses: ncipollo/[email protected] | |
with: | |
allowUpdates: true | |
removeArtifacts: true | |
draft: true | |
name: ${{ env.NEW_VERSION_NAME }} | |
tag: "v${{ env.NEW_VERSION_NAME }}" | |
body: | | |
Note: KernelFlasher + allow-errors | |
Changes in this Release: | |
${{ github.event.inputs.changes_in_release }} | |
artifacts: "*.apk" |