Tag and build release #193
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: 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@v6 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.PAT_TOKEN }} | |
| - name: Setup offline maps for tests | |
| run: | | |
| pwd | |
| wget --no-verbose --show-progress --progress=dot:giga https://pub-0a3501283b024ab3bbfbb6d1e217f5d0.r2.dev/street-metadata/bristol-gb.pmtiles -O ${{ env.main_project_module }}/src/test/res/org/scottishtecharmy/soundscape/bristol-gb.pmtiles | |
| wget --no-verbose --show-progress --progress=dot:giga https://pub-0a3501283b024ab3bbfbb6d1e217f5d0.r2.dev/street-metadata/glasgow-gb.pmtiles -O ${{ env.main_project_module }}/src/test/res/org/scottishtecharmy/soundscape/glasgow-gb.pmtiles | |
| wget --no-verbose --show-progress --progress=dot:giga https://pub-0a3501283b024ab3bbfbb6d1e217f5d0.r2.dev/street-metadata/liverpool-gb.pmtiles -O ${{ env.main_project_module }}/src/test/res/org/scottishtecharmy/soundscape/liverpool-gb.pmtiles | |
| wget --no-verbose --show-progress --progress=dot:giga https://pub-0a3501283b024ab3bbfbb6d1e217f5d0.r2.dev/manifest.geojson.gz -O ${{ env.main_project_module }}/src/test/res/org/scottishtecharmy/soundscape/manifest.geojson.gz | |
| - 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@v7 | |
| 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: Setup tile and search providers | |
| env: | |
| TILE_PROVIDER_API_KEY: ${{ secrets.TILE_PROVIDER_API_KEY }} | |
| TILE_PROVIDER_URL: ${{ secrets.TILE_PROVIDER_URL }} | |
| SEARCH_PROVIDER_API_KEY: ${{ secrets.SEARCH_PROVIDER_API_KEY }} | |
| SEARCH_PROVIDER_URL: ${{ secrets.SEARCH_PROVIDER_URL }} | |
| EXTRACT_PROVIDER_URL: ${{ secrets.EXTRACT_PROVIDER_URL }} | |
| run: | | |
| echo tileProviderUrl="$TILE_PROVIDER_URL" > local.properties | |
| echo tileProviderApiKey="$TILE_PROVIDER_API_KEY" >> local.properties | |
| echo searchProviderUrl="$SEARCH_PROVIDER_URL" >> local.properties | |
| echo searchProviderApiKey="$SEARCH_PROVIDER_API_KEY" >> local.properties | |
| echo extractProviderUrl="$EXTRACT_PROVIDER_URL" >> local.properties | |
| - 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@v5 | |
| - name: Set Up JDK | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'zulu' # See 'Supported distributions' for available options | |
| java-version: '19' | |
| - 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 | |
| # | |
| # This is fragile with small changes causing it to run out of memory. Comment out until Google fixes it | |
| # | |
| # - name: Generate test screenshots | |
| # run: | | |
| # ./gradlew updateDebugScreenshotTest | |
| # ./categorise.sh app/src/screenshotTestDebug/reference/org/scottishtecharmy/soundscape/ThemeTestClass/ | |
| # cd app/src/screenshotTestDebug/reference/org/scottishtecharmy/soundscape/ThemeTestClass/ | |
| # zip -r screenshots.zip . | |
| # | |
| # - name: Upload screenshots | |
| # uses: actions/upload-artifact@v6 | |
| # with: | |
| # name: test-screenshots | |
| # path: app/src/screenshotTestDebug/reference/org/scottishtecharmy/soundscape/ThemeTestClass/screenshots.zip | |
| - name: Enable KVM | |
| run: | | |
| echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | |
| sudo udevadm control --reload-rules | |
| sudo udevadm trigger --name-match=kvm | |
| - name: Build instrumentation tests to generate screenshots for documentation | |
| id: documentation-screenshot-tests | |
| uses: reactivecircus/android-emulator-runner@v2 | |
| continue-on-error: true | |
| with: | |
| api-level: 34 | |
| target: default | |
| arch: x86_64 | |
| profile: pixel_7 | |
| script: | | |
| mkdir -p docs/documentationScreens | |
| adb logcat -c # clear logs | |
| adb shell settings put global policy_control immersive.status=* # Disable status bar at top of screen | |
| touch app/emulator.log # create log file | |
| chmod 777 app/emulator.log # allow writing to log file | |
| adb logcat >> app/emulator.log & # pipe all logcat messages into log file as a background process | |
| # Run only the DocumentationScreens tests | |
| ./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=org.scottishtecharmy.soundscape.DocumentationScreens | |
| # And then get the resulting screenshots from the emulator | |
| adb pull /storage/emulated/0/Android/data/org.scottishtecharmy.soundscape/files/Pictures/screenshots/homeScreen.png docs/documentationScreens/homeScreen.png | |
| adb pull /storage/emulated/0/Android/data/org.scottishtecharmy.soundscape/files/Pictures/screenshots/homeScreenWithRoute.png docs/documentationScreens/homeScreenWithRoute.png | |
| adb pull /storage/emulated/0/Android/data/org.scottishtecharmy.soundscape/files/Pictures/screenshots/routeDetails.png docs/documentationScreens/routeDetails.png | |
| adb pull /storage/emulated/0/Android/data/org.scottishtecharmy.soundscape/files/Pictures/screenshots/routeEdit.png docs/documentationScreens/routeEdit.png | |
| adb pull /storage/emulated/0/Android/data/org.scottishtecharmy.soundscape/files/Documents/help docs/users/ | |
| mv docs/users/help/* docs/users/ | |
| - name: ImageMagick Action to trim off status and navigation bars from screenshots | |
| uses: jruipinto/ImageMagick-action@v1 | |
| with: | |
| command: mogrify -path docs/documentationScreens -crop 1080x2130+0+140 docs/documentationScreens/*.* | |
| - name: Commit new screenshots | |
| uses: stefanzweifel/git-auto-commit-action@v7 | |
| with: | |
| commit_message: "New documentation screenshots" | |
| file_pattern: 'docs/documentationScreens/*.png docs/users/help-*.md' | |
| # 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 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/releaseTest/ | |
| - name: Upload APK ReleaseTest | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: releaseTest-apk | |
| path: | | |
| ${{ env.main_project_module }}/build/outputs/apk/releaseTest/ | |
| # Noted For Output [main_project_module]/build/outputs/apk/release/ | |
| - name: Upload APK Release | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: release-apk | |
| path: | | |
| ${{ env.main_project_module }}/build/outputs/apk/release/ | |
| # Noted For Output [main_project_module]/build/outputs/bundle/release/ | |
| - name: Upload AAB (App Bundle) Release | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: release-aab | |
| path: | | |
| ${{ env.main_project_module }}/build/outputs/bundle/release/ | |
| ${{ env.main_project_module }}/build/outputs/mapping/release/ | |
| firebase: | |
| name: Run UI tests with Firebase Test Lab | |
| needs: build | |
| environment: development | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download app releaseTest APK | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: releaseTest-apk | |
| - name: Auth | |
| uses: google-github-actions/auth@v3 | |
| with: | |
| credentials_json: ${{ secrets.GCLOUD_CREDENTIALS_JSON }} | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v3 | |
| - name: Set current project | |
| run: gcloud config set project ${{ secrets.FIREBASE_PROJECT_ID }} | |
| - name: Run Robo test in Firebase Test Lab | |
| run: gcloud firebase test android run --type robo --app=app-releaseTest.apk --timeout=300s --device model=shiba,version=34,locale=en,orientation=portrait |