Skip to content

Commit

Permalink
Added automatic releases on GitHub with easily downloadable APK-files
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Jul 20, 2023
1 parent 272b676 commit ae95be0
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 126 deletions.
69 changes: 11 additions & 58 deletions .github/workflows/android_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,28 @@ jobs:
java-version: '11'
distribution: 'temurin'

- name: delete unwanted langs
- name: prepare for build
shell: bash
run: ci/delete-unwanted-langs

- name: gradle build
uses: gradle/gradle-build-action@v2
with:
arguments: build :app:lint check
run: ./prepare_for_build.sh
env:
SERVICEACCOUNTJSON: ${{ secrets.SERVICEACCOUNTJSON }}
KEYSTOREPASSWORD: ${{ secrets.KEYSTOREPASSWORD }}
KEYSTORE: ${{ secrets.KEYSTORE }}
KEYPASSWORD: ${{ secrets.KEYPASSWORD }}
KEYALIAS: ${{ secrets.KEYALIAS }}

- name: add APK to artifacts
uses: actions/upload-artifact@v3
- name: bump version if not release
shell: bash
run: ci/run-if-not-release fastlane bump_version_code

- name: gradle build
uses: gradle/gradle-build-action@v2
with:
name: apk
path: app/build/outputs/apk/debugMini/app-debugMini.apk
retention-days: 7 # we're not publishing the app: nobody needs this apk
arguments: build app:bundlePlay :app:lint check

- name: validate deploy
shell: bash
run: ci/run-if-not-release ./deploy_playstore.sh --dry-run
env:
SERVICEACCOUNTJSON: ${{ secrets.SERVICEACCOUNTJSON }}
KEYSTOREPASSWORD: ${{ secrets.KEYSTOREPASSWORD }}
KEYSTORE: ${{ secrets.KEYSTORE }}
KEYPASSWORD: ${{ secrets.KEYPASSWORD }}
KEYALIAS: ${{ secrets.KEYALIAS }}
run: ci/run-if-not-release ./deploy_playstore_fast.sh --dry-run

# Runs emulator tests
# connected_check:
Expand Down Expand Up @@ -130,42 +122,3 @@ jobs:
# logcat-dump.txt
# app/build/reports/androidTests/**

# this job deploys to playstore
deploy:
needs:
- build
#- connected_check

runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: perform the checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'
fetch-depth: 0

# Verify the SHA-sum
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: setup JDK
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: delete unwanted langs
shell: bash
run: ci/delete-unwanted-langs

- name: deploy to play store
shell: bash
run: ci/run-if-release ./deploy_playstore.sh
env:
SERVICEACCOUNTJSON: ${{ secrets.SERVICEACCOUNTJSON }}
KEYSTOREPASSWORD: ${{ secrets.KEYSTOREPASSWORD }}
KEYSTORE: ${{ secrets.KEYSTORE }}
KEYPASSWORD: ${{ secrets.KEYPASSWORD }}
KEYALIAS: ${{ secrets.KEYALIAS }}
8 changes: 1 addition & 7 deletions .github/workflows/android_pr_build.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
name: PR Checks

on:
push:
branches:
- '*'
- '!master'
# PRs are in gitlab for now
#pull_request:
# branches: [ "master" ]
pull_request:

jobs:
# this job builds and uploads the apk
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release

on:
push:
tags:
- '*'

jobs:
release-build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: perform the checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'
fetch-depth: 0

- name: version
run: echo "::set-output name=versioncode::$(grep "versionCode" app/build.gradle.kts | sed "s|\s*versionCode = \([0-9]\+\)|\\1|")"
id: version

# Verify the SHA-sum
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: setup JDK
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: prepare for build
shell: bash
run: ./prepare_for_build.sh
env:
SERVICEACCOUNTJSON: ${{ secrets.SERVICEACCOUNTJSON }}
KEYSTOREPASSWORD: ${{ secrets.KEYSTOREPASSWORD }}
KEYSTORE: ${{ secrets.KEYSTORE }}
KEYPASSWORD: ${{ secrets.KEYPASSWORD }}
KEYALIAS: ${{ secrets.KEYALIAS }}

- name: gradle build
uses: gradle/gradle-build-action@v2
with:
arguments: build :app:lint check app:bundlePlay

- name: deploy to play store
shell: bash
run: ci/run-if-release ./deploy_playstore_fast.sh

- name: release
uses: softprops/action-gh-release@v1
#if: startsWith(github.ref, 'refs/tags/')
with:
draft: false
#tag_name: 2.4.20
body_path: fastlane/metadata/android/en-US/changelogs/${{ steps.version.outputs.versioncode }}.txt
fail_on_unmatched_files: true
files: |
app/build/outputs/apk/debugMini/app-debugMini.apk
app/build/outputs/apk/release/app-release.apk
app/build/outputs/apk/play/app-play.apk
58 changes: 0 additions & 58 deletions deploy_playstore.sh

This file was deleted.

27 changes: 27 additions & 0 deletions deploy_playstore_fast.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash -eu

LATEST_TAG="$(git describe --tags "$(git rev-list --tags --max-count=1)")"
CURRENT_VERSION="$(git describe --tags)"

if [[ "${1:-}" == "--dry-run" ]] && [[ "${LATEST_TAG}" == "${CURRENT_VERSION}" ]]; then
# CI runs master and tag pipelines concurrently and fastlane will conflict if run concurrently
echo "${CURRENT_VERSION} is a tag but --dry-run was specified - not doing anything"
elif [[ "${1:-}" == "--dry-run" ]] || [[ "${LATEST_TAG}" != "${CURRENT_VERSION}" ]]; then
echo "${CURRENT_VERSION} is not tag - validating deployment"
if [[ "${CURRENT_VERSION}" =~ ^[0-9.]*$ ]]; then
echo "${CURRENT_VERSION} is a production release"
fastlane validate_deploy track:production
else
echo "${CURRENT_VERSION} is a beta release"
fastlane validate_deploy track:beta
fi
else
echo "${CURRENT_VERSION} is a tag - deploying to store!"
if [[ "${CURRENT_VERSION}" =~ ^[0-9.]*$ ]]; then
echo "${CURRENT_VERSION} is a production release"
fastlane deploy track:production
else
echo "${CURRENT_VERSION} is a beta release"
fastlane deploy track:beta
fi
fi
5 changes: 2 additions & 3 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ platform :android do

desc "Build and deploy a new version to the Google Play"
lane :build_and_deploy do |options|
# Keep same version for changelog
#bump_version_code
# Never change version for releases
build_play_bundle
deploy(options)
end

desc "Build and valdidate deployment of a new version to the Google Play"
desc "Build and validate deployment of a new version to the Google Play"
lane :build_and_validate do |options|
# Validation should never fail so bump version
bump_version_code
Expand Down
30 changes: 30 additions & 0 deletions prepare_for_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash -eu

if [ -n "${SERVICEACCOUNTJSON:-}" ]; then
cat > app/creds.b64 <<EOF
${SERVICEACCOUNTJSON}
EOF
fi

base64 --ignore-garbage --decode app/creds.b64 > app/creds.json

sed -i "s|/home/jonas/.ssh/service.json|$(pwd)/app/creds.json|" fastlane/Appfile

if [ -n "${KEYSTORE:-}" ]; then
cat > keystore.b64 <<EOF
${KEYSTORE}
EOF

base64 --ignore-garbage --decode keystore.b64 > keystore

cat >> gradle.properties <<EOF
STORE_FILE=$(pwd)/keystore
STORE_PASSWORD=${KEYSTOREPASSWORD}
KEY_ALIAS=${KEYALIAS}
KEY_PASSWORD=${KEYPASSWORD}
EOF

fi

# Delete unsupported google play store languages
ci/delete-unwanted-langs

0 comments on commit ae95be0

Please sign in to comment.