Remote Dispatch Build Preview App #44
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: Remote Dispatch Build Preview App | |
on: | |
# Dispatch or Manual triggers | |
workflow_dispatch: | |
inputs: | |
git-ref: | |
description: Git Ref to build ('master' for preview build, any other for develop build) | |
required: false | |
dry-run: | |
description: Creates a draft release (any value would create a draft) | |
required: false | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.inputs.git-ref }} | |
cancel-in-progress: true | |
jobs: | |
prepare-build: | |
if: github.event.inputs.git-ref != '' | |
runs-on: ubuntu-latest | |
outputs: | |
COMMIT_COUNT: ${{ steps.current_commit.outputs.COMMIT_COUNT }} | |
CURRENT_SHA: ${{ steps.current_commit.outputs.CURRENT_SHA }} | |
PREV_RELEASE_SHA: ${{ steps.previous_commit.outputs.PREV_RELEASE_SHA }} | |
COMMIT_LOGS: ${{ steps.commit_logs.outputs.COMMIT_LOGS }} | |
TAG_PREFIX: ${{ steps.prepare_env.outputs.TAG_PREFIX }} | |
ARTIFACTS_PREFIX: ${{ steps.prepare_env.outputs.ARTIFACTS_PREFIX }} | |
BUILD_TYPE_NAME: ${{ steps.prepare_env.outputs.BUILD_TYPE_NAME }} | |
CHANGELOG: ${{ steps.set_changelog.outputs.CHANGELOG }} | |
steps: | |
- name: Clone Repository (${{ github.event.inputs.git-ref }}) | |
uses: actions/checkout@v4 | |
with: | |
repository: 'komikku-app/komikku' | |
fetch-depth: 0 | |
ref: ${{ github.event.inputs.git-ref }} | |
- name: Validate Gradle Wrapper | |
uses: gradle/actions/wrapper-validation@v3 | |
- name: Get previous release | |
id: last_release | |
uses: InsonusK/get-latest-release@7a9ff16c8c6b7ead5d71c0f1cc61f2703170eade # v1.1.0 | |
with: | |
myToken: ${{ github.token }} | |
exclude_types: "draft|prerelease" | |
view_top: 1 | |
- name: Curren commit | |
id: current_commit | |
run: | | |
set -e | |
commit_count=$(git rev-list --count HEAD) | |
echo "COMMIT_COUNT=$commit_count" | |
echo "COMMIT_COUNT=$commit_count" >> $GITHUB_OUTPUT | |
current_sha=$(git rev-parse --short HEAD) | |
echo "CURRENT_SHA=$current_sha" | |
echo "CURRENT_SHA=$current_sha" >> $GITHUB_OUTPUT | |
- name: Previous commit | |
id: previous_commit | |
run: | | |
set -e | |
prev_commit_count=$(echo "${{ steps.last_release.outputs.tag_name }}" | sed -e "s/^r//") | |
echo "prev_commit_count=$prev_commit_count" | |
echo "expr ${{ steps.current_commit.outputs.COMMIT_COUNT }} - $prev_commit_count" | |
echo "$(expr ${{ steps.current_commit.outputs.COMMIT_COUNT }} - ${prev_commit_count})" | |
echo "$(expr ${{ steps.current_commit.outputs.COMMIT_COUNT }} - $prev_commit_count)" | |
commit_count_diff="$(expr ${{ steps.current_commit.outputs.COMMIT_COUNT }} - $prev_commit_count)" | |
echo "commit_count_diff=$commit_count_diff" | |
prev_release_sha=$(git rev-parse --short HEAD~$commit_count_diff) | |
echo "PREV_RELEASE_SHA=$prev_release_sha" | |
echo "PREV_RELEASE_SHA=$prev_release_sha" >> $GITHUB_OUTPUT | |
- name: Commit logs | |
id: commit_logs | |
run: | | |
set -e | |
echo "COMMIT_LOGS<<{delimiter} | |
$(curl -H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/komikku-app/komikku/compare/${{ steps.previous_commit.outputs.PREV_RELEASE_SHA }}...${{ steps.current_commit.outputs.CURRENT_SHA }}" \ | |
| jq '[.commits[]|{message:(.commit.message | split("\n")), username:.author.login}]' \ | |
| jq -r '.[]|"- \(.message | first) (@\(.username))"') | |
{delimiter}" >> $GITHUB_OUTPUT | |
- name: Prepare env | |
id: prepare_env | |
run: | | |
set -e | |
if [ "${{ github.event.inputs.git-ref }}" = "master" ]; then | |
tag_prefix=r | |
artifacts_prefix=standard/preview/app-standard | |
built_type_name=Preview | |
else | |
tag_prefix=d | |
artifacts_prefix=dev/preview/app-dev | |
build_type_name=Develop | |
fi | |
echo "TAG_PREFIX=$tag_prefix" >> $GITHUB_OUTPUT | |
echo "ARTIFACTS_PREFIX=$artifacts_prefix" >> $GITHUB_OUTPUT | |
echo "BUILD_TYPE_NAME=$build_type_name" >> $GITHUB_OUTPUT | |
- name: Set CHANGELOG | |
id: set_changelog | |
if: github.event.inputs.git-ref != 'master' | |
run: | | |
changelog="$(git log ${{ steps.prepare_env.outputs.PREV_RELEASE_SHA }}..${{ steps.prepare_env.outputs.CURRENT_SHA }} --pretty=format:'{{changelogtext}}%s (@%an){{!changelogtext}}')" | |
changelog="${changelog//$'%'/%25}" | |
changelog="${changelog//$'\n'/}" | |
changelog="${changelog//$'\r'/}" | |
changelog="${changelog//$'<'/}" | |
changelog="${changelog//$'>'/}" | |
changelog="${changelog//$'&'/}" | |
changelog="$(echo $changelog | sed -e 's/{{changelogtext}}/<changelogtext>/g')" | |
changelog="$(echo $changelog | sed -e 's/{{!changelogtext}}/<\/changelogtext>/g')" | |
changelog="<?xml version=\"1.0\" encoding=\"utf-8\"?><changelog bulletedList=\"true\"><changelogversion versionName=\"${{ github.run_number }}\" changeDate=\"\">$changelog</changelogversion></changelog>" | |
echo "CHANGELOG=$changelog" >> $GITHUB_OUTPUT | |
build-app: | |
runs-on: ubuntu-latest | |
needs: prepare-build | |
steps: | |
- name: Clone Repository (${{ github.event.inputs.git-ref }} - ${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}) | |
uses: actions/checkout@v4 | |
with: | |
repository: 'komikku-app/komikku' | |
fetch-depth: 0 | |
ref: ${{ github.event.inputs.git-ref }} | |
- name: Set up gradle | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Setup Android SDK | |
run: | | |
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "build-tools;29.0.3" | |
- name: Set up JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: temurin | |
- name: Write changelog_debug.xml | |
uses: DamianReeves/[email protected] | |
if: github.event.inputs.git-ref != 'master' | |
with: | |
path: app/src/main/res/raw/changelog_debug.xml | |
contents: "${{ needs.prepare-build.outputs.CHANGELOG }}" | |
write-mode: overwrite | |
- name: Write google-services.json | |
uses: DamianReeves/[email protected] | |
if: github.event.inputs.git-ref == 'master' | |
with: | |
path: app/google-services.json | |
contents: ${{ secrets.GOOGLE_SERVICES_JSON }} | |
write-mode: overwrite | |
- name: Write client_secrets.json | |
uses: DamianReeves/[email protected] | |
if: github.event.inputs.git-ref == 'master' | |
with: | |
path: app/src/main/assets/client_secrets.json | |
contents: ${{ secrets.GOOGLE_CLIENT_SECRETS_JSON }} | |
write-mode: overwrite | |
# - name: Build app and run unit tests | |
# uses: gradle/gradle-command-action@v2 | |
# with: | |
# arguments: detekt assembleStandardPreview testStandardPreviewUnitTest | |
- name: Build Preview APK | |
run: ./gradlew assembleStandardPreview testStandardPreviewUnitTest --stacktrace | |
if: github.event.inputs.git-ref == 'master' | |
- name: Build Development APK | |
run: ./gradlew assembleDevPreview testDevPreviewUnitTest --stacktrace | |
if: github.event.inputs.git-ref != 'master' | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
path: "**/*.apk" | |
retention-days: 1 | |
release-app: | |
runs-on: ubuntu-latest | |
needs: | |
- prepare-build | |
- build-app | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
merge-multiple: true | |
- name: Setup Android SDK | |
run: | | |
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "build-tools;29.0.3" | |
- name: Sign APK | |
uses: r0adkll/sign-android-release@349ebdef58775b1e0d8099458af0816dc79b6407 # v1 | |
if: github.event.inputs.git-ref == 'master' | |
with: | |
releaseDirectory: app/build/outputs/apk/standard/preview | |
signingKeyBase64: ${{ secrets.SIGNING_KEY }} | |
alias: ${{ secrets.ALIAS }} | |
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }} | |
keyPassword: ${{ secrets.KEY_PASSWORD }} | |
- name: Sign Development APK | |
uses: r0adkll/sign-android-release@349ebdef58775b1e0d8099458af0816dc79b6407 # v1 | |
if: github.event.inputs.git-ref != 'master' | |
with: | |
releaseDirectory: app/build/outputs/apk/dev/preview | |
signingKeyBase64: ${{ secrets.SIGNING_KEY }} | |
alias: ${{ secrets.ALIAS }} | |
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }} | |
keyPassword: ${{ secrets.KEY_PASSWORD }} | |
- name: Get SHA & clean up build artifacts | |
id: get_sha | |
run: | | |
set -e | |
mv app/build/outputs/apk/${{ needs.prepare-build.outputs.ARTIFACTS_PREFIX }}-universal-preview-signed.apk Komikku-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
sha=`sha256sum Komikku-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | awk '{ print $1 }'` | |
echo "APK_UNIVERSAL_SHA=$sha" >> $GITHUB_OUTPUT | |
mv app/build/outputs/apk/${{ needs.prepare-build.outputs.ARTIFACTS_PREFIX }}-arm64-v8a-preview-signed.apk Komikku-arm64-v8a-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
sha=`sha256sum Komikku-arm64-v8a-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | awk '{ print $1 }'` | |
echo "APK_ARM64_V8A_SHA=$sha" >> $GITHUB_OUTPUT | |
mv app/build/outputs/apk/${{ needs.prepare-build.outputs.ARTIFACTS_PREFIX }}-armeabi-v7a-preview-signed.apk Komikku-armeabi-v7a-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
sha=`sha256sum Komikku-armeabi-v7a-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | awk '{ print $1 }'` | |
echo "APK_ARMEABI_V7A_SHA=$sha" >> $GITHUB_OUTPUT | |
mv app/build/outputs/apk/${{ needs.prepare-build.outputs.ARTIFACTS_PREFIX }}-x86-preview-signed.apk Komikku-x86-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
sha=`sha256sum Komikku-x86-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | awk '{ print $1 }'` | |
echo "APK_X86_SHA=$sha" >> $GITHUB_OUTPUT | |
mv app/build/outputs/apk/${{ needs.prepare-build.outputs.ARTIFACTS_PREFIX }}-x86_64-preview-signed.apk Komikku-x86_64-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
sha=`sha256sum Komikku-x86_64-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | awk '{ print $1 }'` | |
echo "APK_X86_64_SHA=$sha" >> $GITHUB_OUTPUT | |
- name: Create release | |
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4 | |
with: | |
tag_name: ${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }} | |
name: Komikku ${{ needs.prepare-build.outputs.BUILD_TYPE_NAME }} ${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }} | |
body: | | |
### Commits | |
https://github.com/komikku-app/komikku/compare/${{ needs.prepare-build.outputs.PREV_RELEASE_SHA }}...${{ needs.prepare-build.outputs.CURRENT_SHA }} | |
${{ needs.prepare-build.outputs.COMMIT_LOGS }} | |
--- | |
### Checksums | |
| Variant | SHA-256 | | |
| ------- | ------- | | |
| Universal | ${{ steps.get_sha.outputs.APK_UNIVERSAL_SHA }} | | |
| arm64-v8a | ${{ steps.get_sha.outputs.APK_ARM64_V8A_SHA }} | | |
| armeabi-v7a | ${{ steps.get_sha.outputs.APK_ARMEABI_V7A_SHA }} | | |
| x86 | ${{ steps.get_sha.outputs.APK_X86_SHA }} | | |
| x86_64 | ${{ steps.get_sha.outputs.APK_X86_64_SHA }} | | |
## If you are unsure which apk to download then go with Komikku-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
files: | | |
Komikku-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
Komikku-arm64-v8a-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
Komikku-armeabi-v7a-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
Komikku-x86-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
Komikku-x86_64-${{ needs.prepare-build.outputs.TAG_PREFIX }}${{ needs.prepare-build.outputs.COMMIT_COUNT }}.apk | |
draft: ${{ github.event.inputs.dry-run != '' || github.event.inputs.git-ref == 'master'}} | |
prerelease: ${{ github.event.inputs.git-ref != 'master'}} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
cleaning-repo: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Prune old releases | |
uses: dev-drprasad/delete-older-releases@0bf4e6748f08135170c2294f877ba7d9b633b028 # v0.3.3 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
keep_latest: 28 | |
delete_tags: true |