Skip to content

Android Build and Release on Tag #441

Android Build and Release on Tag

Android Build and Release on Tag #441

name: Android Build and Release on Tag
on:
create:
jobs:
linux-build-and-release:
if: github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/release/')
runs-on: ubuntu-latest
steps:
- name: Decode Keystore
id: decode_keystore
uses: timheuer/[email protected]
with:
fileName: 'release.jks'
encodedString: ${{ secrets.KEYSTORE }}
- uses: actions/checkout@v4
- name: Set timezone
run: echo "TZ=Europe/London" >> $GITHUB_ENV
- name: set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Gradle build
run: ./gradlew bundleRelease assembleRelease --no-daemon
env:
CI: 'true'
KEYSTORE_LOCATION: ${{ steps.decode_keystore.outputs.filePath }}
CI_ANDROID_KEYSTORE_ALIAS: ${{ secrets.BITRISEIO_ANDROID_KEYSTORE_ALIAS }}
CI_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD: ${{ secrets.BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD }}
CI_ANDROID_KEYSTORE_PASSWORD: ${{ secrets.BITRISEIO_ANDROID_KEYSTORE_PASSWORD }}
- name: Extract Version Number
run: echo "version=${GITHUB_REF#refs/tags/release/}" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_RELEASES }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ env.version }}
draft: false
prerelease: false
body: "Description of the release for version ${{ env.version }}"
commitish: ${{ github.sha }}
- name: Upload Release Asset Mapping
if: ${{ vars.EXPORT_MAPPING == 'true' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_RELEASES }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./composeApp/build/outputs/mapping/release/mapping.txt
asset_name: mapping-${{ env.version }}.txt
asset_content_type: text/plain
- name: Find APK file
run: |
apk_path=$(find ./composeApp/build/outputs/apk/release -name "OctoMeter-*.apk" | head -n 1)
echo "apk_path=$apk_path" >> $GITHUB_ENV
- name: Upload Release Asset APK
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_RELEASES }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.apk_path }}
asset_name: OctoMeter-${{ env.version }}.apk
asset_content_type: application/vnd.android.package-archive
- name: Find AAB file
run: |
aab_path=$(find ./composeApp/build/outputs/bundle/release -name "OctoMeter-*.aab" | head -n 1)
echo "aab_path=$aab_path" >> $GITHUB_ENV
- name: Upload Release Asset AAB
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_RELEASES }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.aab_path }}
asset_name: OctoMeter-${{ env.version }}.aab
asset_content_type: application/vnd.android.package-archive
windows-build-and-release:
needs: linux-build-and-release
if: github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/release/')
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Get the Release ID
id: get_release
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_RELEASES }}
with:
script: |
const { GITHUB_REF } = process.env;
const tag = GITHUB_REF.split('/').pop();
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
const release = releases.find(rel => rel.tag_name === `release/${tag}`);
if (!release) {
throw new Error(`Release not found for tag ${tag}`);
}
core.setOutput('release_id', release.id);
result-encoding: string
- name: set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
cache: gradle
- name: Prepare RoomDB actual declaration
run: .\gradlew :composeApp:kspCommonMainKotlinMetadata
env:
CI: 'false'
- name: Build and Package Project
run: .\gradlew packageReleaseDistributionForCurrentOS
env:
CI: 'false'
- name: Extract Version Number
shell: pwsh
run: |
Write-Host "Extracting version from $env:GITHUB_REF"
$version = $env:GITHUB_REF -replace 'refs/tags/release/', ''
echo "version=$version" >> $env:GITHUB_ENV
Write-Host "Extracted version: $version"
- name: Find MSI file
shell: pwsh
run: |
$msi_path = (Get-ChildItem -Path .\composeApp\build\compose\binaries\main-release\msi -Filter "OctoMeter-*.msi" | Select-Object -First 1).FullName
echo "msi_path=$msi_path" >> $env:GITHUB_ENV
- name: Upload MSI Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_RELEASES }}
with:
upload_url: https://uploads.github.com/repos/${{ github.repository }}/releases/${{ steps.get_release.outputs.release_id }}/assets{?name,label}
asset_path: ${{ env.msi_path }}
asset_name: OctoMeter-${{ env.version }}.msi
asset_content_type: application/x-msi
- name: Find EXE file
shell: pwsh
run: |
$exe_path = (Get-ChildItem -Path .\composeApp\build\compose\binaries\main-release\exe -Filter "OctoMeter-*.exe" | Select-Object -First 1).FullName
echo "exe_path=$exe_path" >> $env:GITHUB_ENV
- name: Upload EXE Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_RELEASES }}
with:
upload_url: https://uploads.github.com/repos/${{ github.repository }}/releases/${{ steps.get_release.outputs.release_id }}/assets{?name,label}
asset_path: ${{ env.exe_path }}
asset_name: OctoMeter-${{ env.version }}.exe
asset_content_type: application/vnd.microsoft.portable-executable