Tag and build release #13
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: Tag and build release | |
env: | |
# The name of the main module repository | |
main_project_module: app | |
# The name in the Play Store | |
playstore_name: Soundscape | |
on: | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
environment: development | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.PAT_TOKEN }} | |
- name: Extract existing version code from build.gradle | |
id: current-version | |
run: | | |
# Get existing version code from build.gradle | |
version_code=$(grep "versionCode" app/build.gradle.kts | awk '{print $3}' | tr -d '\n') | |
version_name=$(grep "versionName =" app/build.gradle.kts | awk '{print $3}' | tr -d '\"\"') | |
major_version=$(echo $version_name | awk -F \. {'print $1'}) | |
minor_version=$(echo $version_name | awk -F \. {'print $2'}) | |
build_version=$(echo $version_name | awk -F \. {'print $3'}) | |
# Increment existing version code and build version by 1 | |
version_code=$((version_code + 1)) | |
build_version=$((build_version + 1)) | |
# The major and minor versions can be bumped manually by editing | |
# app/build.gradle.kts. When doing this, reset the build version | |
# to zero. | |
# Set output variables for later use | |
echo "VERSION_CODE=$version_code" >> $GITHUB_OUTPUT | |
echo "VERSION_NAME=$major_version.$minor_version.$build_version" >> $GITHUB_OUTPUT | |
- name: Increase version code and change version name | |
env: | |
VERSION_CODE: ${{ steps.current-version.outputs.VERSION_CODE }} | |
VERSION_NAME: ${{ steps.current-version.outputs.VERSION_NAME }} | |
run: | | |
# Update build.gradle with new version code and name | |
echo "$VERSION_CODE - $env.VERSION_NAME" | |
sed -i "s/versionCode = [0-9]\+/versionCode = $VERSION_CODE/g" app/build.gradle.kts | |
sed -i "s/versionName = \"[^\"]*\"/versionName = \"$VERSION_NAME\"/g" app/build.gradle.kts | |
- name: Bump version from "${{ steps.current-version.outputs.VERSION_NAME }}" | |
env: | |
VERSION_CODE: ${{ steps.current-version.outputs.VERSION_CODE }} | |
VERSION_NAME: ${{ steps.current-version.outputs.VERSION_NAME }} | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: "Bump version to ${{ env.VERSION_NAME }}, version code ${{ env.VERSION_CODE }}" | |
tagging_message: "soundscape-${{ env.VERSION_NAME }}" | |
# Set version | |
- name: Set 'git describe --tags' as version | |
id: get-version | |
run: echo "VERSION=$(git describe --tags)" >> $GITHUB_OUTPUT | |
- name: Decode Google services | |
env: | |
ENCODED_STRING: ${{ secrets.GOOGLE_SERVICES }} | |
GOOGLE_SERVICES_PATH: ${{ secrets.GOOGLE_SERVICES_PATH }} | |
run: | | |
echo $ENCODED_STRING > google-services-b64.txt | |
base64 -d google-services-b64.txt > ${{ env.main_project_module }}/$GOOGLE_SERVICES_PATH | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Set Up JDK | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'zulu' # See 'Supported distributions' for available options | |
java-version: '17' | |
- name: Run lint over the repo | |
run: ./gradlew lint | |
# Setup release build keys | |
- name: Decode Keystore | |
env: | |
ENCODED_STRING: ${{ secrets.SIGNING_KEY_STORE_BASE64 }} | |
SIGNING_KEY_STORE_PATH: ${{ secrets.SIGNING_KEY_STORE_PATH }} | |
run: | | |
echo $ENCODED_STRING > keystore-b64.txt | |
base64 -d keystore-b64.txt > ${{ env.main_project_module }}/$SIGNING_KEY_STORE_PATH | |
# Run Tests Build | |
- name: Run gradle tests | |
run: ./gradlew test | |
# Run Build Project | |
- name: Build gradle project | |
env: | |
SIGNING_KEY_STORE_PATH: ${{ secrets.SIGNING_KEY_STORE_PATH }} | |
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} | |
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }} | |
run: | | |
./gradlew build | |
# Create APK Debug | |
- name: Build apk debug project (APK) | |
run: | | |
./gradlew assembleDebug | |
# Create APK Release | |
- name: Build apk release project (APK) | |
env: | |
SIGNING_KEY_STORE_PATH: ${{ secrets.SIGNING_KEY_STORE_PATH }} | |
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} | |
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }} | |
run: ./gradlew assemble | |
# Create Bundle AAB Release | |
# Noted for main module build [main_project_module]:bundleRelease | |
- name: Build app bundle release (AAB) | |
env: | |
SIGNING_KEY_STORE_PATH: ${{ secrets.SIGNING_KEY_STORE_PATH }} | |
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} | |
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }} | |
run: ./gradlew ${{ env.main_project_module }}:bundleRelease | |
# Upload Artifact Build | |
# Noted For Output [main_project_module]/build/outputs/apk/debug/ | |
- name: Upload APK Debug | |
uses: actions/upload-artifact@v4 | |
with: | |
name: debug-apk | |
path: ${{ env.main_project_module }}/build/outputs/apk/debug/ | |
# Noted For Output [main_project_module]/build/outputs/apk/release/ | |
- name: Upload APK Release | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release-apk | |
path: | | |
${{ env.main_project_module }}/build/outputs/apk/release/ | |
${{ env.main_project_module }}/build/outputs/mapping/release/ | |
# Noted For Output [main_project_module]/build/outputs/bundle/release/ | |
- name: Upload AAB (App Bundle) Release | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release-aab | |
path: | | |
${{ env.main_project_module }}/build/outputs/bundle/release/ | |
${{ env.main_project_module }}/build/outputs/mapping/release/ | |
# Generate android instrumentation tests APK | |
- name: Assemble Android Instrumentation Tests | |
run: ./gradlew assembleDebugAndroidTest | |
- name: Upload Android Test APK | |
uses: actions/upload-artifact@v4 | |
with: | |
name: debug-androidTest | |
path: ${{ env.main_project_module }}/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk | |
firebase: | |
name: Run UI tests with Firebase Test Lab | |
needs: build | |
environment: development | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Download app APK | |
uses: actions/download-artifact@v4 | |
with: | |
name: debug-apk | |
- name: Download Android test APK | |
uses: actions/download-artifact@v4 | |
with: | |
name: debug-androidTest | |
- name: Auth | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCLOUD_CREDENTIALS_JSON }} | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: Set current project | |
run: gcloud config set project ${{ secrets.FIREBASE_PROJECT_ID }} | |
- name: Run Instrumentation Tests in Firebase Test Lab | |
run: gcloud firebase test android run --type instrumentation --use-orchestrator --app app-debug.apk --test app-debug-androidTest.apk --device model=shiba,version=34,locale=en,orientation=portrait | |
- name: Run Robo test in Firebase Test Lab | |
run: gcloud firebase test android run --type robo --app=app-debug.apk --timeout=300s --device model=shiba,version=34,locale=en,orientation=portrait |