Production Builds #2
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: Production Builds | |
on: | |
workflow_dispatch: | |
inputs: | |
repo: | |
type: string | |
description: 'Repository' | |
required: true | |
default: 'nightscout/AndroidAPS' | |
ref: | |
type: string | |
description: 'Ref / Branch' | |
required: true | |
default: 'master' | |
keyStoreContent: | |
type: string | |
description: 'Base64 encoded keystore file' | |
required: true | |
keyStorePassword: | |
type: string | |
description: 'Keystore password' | |
required: true | |
keyPassword: | |
type: string | |
description: 'Key password' | |
required: true | |
keyAlias: | |
type: string | |
description: 'Key alias' | |
required: true | |
uploadAsArtifact: | |
type: boolean | |
description: 'Upload as artifact' | |
googleDriveAccessToken: | |
type: string | |
description: 'Google Drive access token' | |
dropboxAccessToken: | |
type: string | |
description: 'Dropbox access token' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: ${{ inputs.repo }} | |
ref: ${{ inputs.ref }} | |
- name: set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: 'gradle' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew app:assembleFullRelease | |
- name: Setup build tool version variable | |
shell: bash | |
run: | | |
BUILD_TOOL_VERSION=$(ls /usr/local/lib/android/sdk/build-tools/ | tail -n 1) | |
echo "BUILD_TOOL_VERSION=$BUILD_TOOL_VERSION" >> $GITHUB_ENV | |
echo Last build tool version is: $BUILD_TOOL_VERSION | |
- name: Sign APK | |
uses: r0adkll/sign-android-release@v1 | |
id: sign_app | |
with: | |
releaseDirectory: app/build/outputs/apk/full/release | |
signingKeyBase64: ${{ inputs.keyStoreContent }} | |
keyStorePassword: ${{ inputs.keyStorePassword }} | |
alias: ${{ inputs.keyAlias }} | |
keyPassword: ${{ inputs.keyPassword }} | |
env: | |
# override default build-tools version (29.0.3) -- optional | |
# BUILD_TOOLS_VERSION: "35.0.2" | |
BUILD_TOOLS_VERSION: ${{ env.BUILD_TOOL_VERSION }} | |
- name: Rename file | |
id: rename_file | |
run: | | |
AAPS_VERSION=$(grep 'const val appVersion' buildSrc/src/main/kotlin/Versions.kt | awk -F'"' '{print $2}' ) | |
echo "AAPS version: $AAPS_VERSION" | |
echo "AAPS_VERSION=$AAPS_VERSION" >> $GITHUB_ENV | |
SOURCE_FILE=${{steps.sign_app.outputs.signedReleaseFile}} | |
TARGET_FILE="app/build/outputs/apk/full/release/AndroidAPS-${AAPS_VERSION}.apk" | |
echo "AAPS apk file: $TARGET_FILE" | |
echo "AAPS_APK_FILE=$TARGET_FILE" >> $GITHUB_ENV | |
if [ -f "$SOURCE_FILE" ]; then | |
# cp "$SOURCE_FILE" "$TARGET_FILE" | |
echo "File has been copied to: $TARGET_FILE" | |
else | |
echo "Original file not found: $SOURCE_FILE" | |
exit 1 | |
fi | |
- name: Upload APK | |
uses: actions/upload-artifact@v4 | |
if: | |
with: | |
name: 'App-Build-${{ github.run_number }}' | |
path: ${{steps.sign_app.outputs.signedReleaseFile}} | |
# path: app/build/outputs/apk/full/release/app-full-release-unsigned-signed.apk | |
retention-days: 1 | |
- name: Upload to Dropbox | |
shell: bash | |
if: ${{ inputs.dropboxAccessToken != '' }} | |
run: | | |
curl -X POST https://content.dropboxapi.com/2/files/upload \ | |
--header "Authorization: Bearer ${{ inputs.dropboxAccessToken }}" \ | |
--header "Dropbox-API-Arg: {\"path\":\"AndroidAPS-${{ steps.rename_file.AAPS_VERSION }}.apk\"}" \ | |
--header "Content-Type: application/octet-stream" \ | |
--data-binary @${{steps.sign_app.outputs.signedReleaseFile}} | |
- name: Upload to Google Drive | |
shell: bash | |
if: ${{ inputs.googleDriveAccessToken != '' }} | |
run: | | |
curl -X POST -L \ | |
--header "Authorization: Bearer ${{ inputs.googleDriveAccessToken }}" \ | |
-F "metadata={ \ | |
\"name\":\"AndroidAPS-${{ steps.rename_file.AAPS_VERSION }}.apk\" \ | |
};type=application/json;charset=UTF-8" \ | |
-F "file=@${{steps.sign_app.outputs.signedReleaseFile}}" \ | |
"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart" |