Skip to content

Commit

Permalink
opt: Optimize github actions workflow execution logic (1/2)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingqiqi5211 committed May 19, 2024
1 parent 1981921 commit 4cdf686
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 75 deletions.
66 changes: 0 additions & 66 deletions .github/workflows/android_pr.yml

This file was deleted.

159 changes: 159 additions & 0 deletions .github/workflows/ci_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: CI Build

on:
pull_request:
types: [opened, synchronize]
paths-ignore:
- ".github/**"
- "!.github/workflows/**"
- ".idea/"
- "doc/*"
- "*.md"
- "app/src/assets/**"
- ".github/workflows/crowdin.yml"
- "crowdin.yml"
push:
branches: [main]
paths-ignore:
- ".github/**"
- "!.github/workflows/**"
- ".idea/"
- "doc/*"
- "*.md"
- "app/src/assets/**"
- "crowdin.yml"
workflow_dispatch:

jobs:
build_debug_package:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
name: Build Debug Package
steps:
- name: Checkout Git Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle

- name: Build with Gradle (Debug)
shell: bash
run: ./gradlew assembleDebug

- name: Find APKs
run: |
echo "APK_FILE_DEBUG=$(find app/build/outputs/apk/debug -name '*.apk')" >> $GITHUB_ENV
- name: Show APKs SHA256
if: success()
run: |
echo "### Build Success" >> $GITHUB_STEP_SUMMARY
echo "|Artifact|SHA256|" >> $GITHUB_STEP_SUMMARY
echo "|:--------:|:----------|" >> $GITHUB_STEP_SUMMARY
canary=$(sha256sum "${{ env.APK_FILE_DEBUG }}")
echo "SHA256=$debug" >> $GITHUB_ENV
echo "|Debug|$debug" >> $GITHUB_STEP_SUMMARY
build_canary_package:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
name: Build Canary Package
steps:
- name: Checkout Git Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle

- name: Create Sign File
run: |
touch signing.properties
echo storePassword=${{ secrets.KEY_STORE_PASSWORD }} >> signing.properties
echo keyAlias=${{ secrets.ALIAS }} >> signing.properties
echo keyPassword='${{ secrets.KEY_STORE_PASSWORD }}' >> signing.properties
echo storeFile=key.jks >> signing.properties
echo ${{ secrets.SIGNING_KEY }} | base64 --decode > ../key.jks
- name: Build with Gradle (Canary)
shell: bash
run: ./gradlew assembleCanary

- name: Find APKs
run: |
echo "APK_FILE_CANARY=$(find app/build/outputs/apk/canary -name '*.apk')" >> $GITHUB_ENV
- name: Show APKs SHA256
if: success()
run: |
echo "### Build Success" >> $GITHUB_STEP_SUMMARY
echo "|Artifact|SHA256|" >> $GITHUB_STEP_SUMMARY
echo "|:--------:|:----------|" >> $GITHUB_STEP_SUMMARY
canary=$(sha256sum "${{ env.APK_FILE_CANARY }}")
echo "SHA256=$canary" >> $GITHUB_ENV
echo "|Canary|$canary" >> $GITHUB_STEP_SUMMARY
push_to_debug_group:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
name: Push to Debug Group
steps:
- name: Checkout Git Repository
uses: actions/checkout@v4

- name: Post to Debug Group
shell: bash
env:
GROUP_DEBUG_ID: ${{ secrets.GROUP_DEBUG_ID }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
DEBUG: ${{ env.APK_FILE_DEBUG }}
COMMIT_MESSAGE: |+
New push to GitHub
by `${{ github.triggering_actor }}`
run: |
ESCAPED=$(python3 -c 'import json,os,urllib.parse; print(urllib.parse.quote(json.dumps(os.environ["COMMIT_MESSAGE"])))')
cd ${{ github.workspace }}
curl -v "https://api.telegram.org/bot${BOT_TOKEN}/sendMediaGroup?chat_id=${GROUP_DEBUG_ID}&media=%5B%7B%22type%22:%22document%22,%20%22media%22:%22attach://debug%22,%22parse_mode%22:%22MarkdownV2%22,%22caption%22:${ESCAPED}%7D%5D" -F debug="@${DEBUG}"
push_to_canary_channel:
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && ${{ github.ref == 'refs/heads/main' && github.ref_type != 'tag' && contains(github.event.head_commit.message, '[skip post]') == false && contains(github.event.head_commit.message, 's#') == false }}
runs-on: ubuntu-latest
name: Push to Canary Channel
steps:
- name: Checkout Git Repository
uses: actions/checkout@v4

- name: Upload Canary APK
uses: actions/upload-artifact@v4
with:
name: HyperCeiler Canary
path: ${{ env.APK_FILE_CANARY }}

- name: Post to Canary Channel
env:
CHANNEL_ID: ${{ secrets.CHANNEL_ID }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
CANARY: ${{ env.APK_FILE_CANARY }}
COMMIT_MESSAGE: |+
New push to GitHub
```
${{ github.event.head_commit.message }}
```by `${{ github.event.head_commit.author.name }}`
See commit detail [here](${{ github.event.head_commit.url }})
run: |
ESCAPED=$(python3 -c 'import json,os,urllib.parse; print(urllib.parse.quote(json.dumps(os.environ["COMMIT_MESSAGE"])))')
cd ${{ github.workspace }}
curl -v "https://api.telegram.org/bot${BOT_TOKEN}/sendMediaGroup?chat_id=${CHANNEL_ID}&media=%5B%7B%22type%22:%22document%22,%20%22media%22:%22attach://canary%22,%22parse_mode%22:%22MarkdownV2%22,%22caption%22:${ESCAPED}%7D%5D" -F canary="@${CANARY}"
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Android Main CI

name: Release Build
# 待修改
on:
push:
branches: [ "main" ]
branches: [ "main2" ]
paths-ignore:
- ".github/**"
- "!.github/workflows/**"
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ android {
compileSdk = 34

defaultConfig {
applicationId = "com.sevtinge.hyperceiler"
applicationId = namespace
minSdk = 33
targetSdk = 34
versionCode = 145
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/xml/camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
android:defaultValue="false" />

<PreferenceCategory android:title="@string/shot">

<SwitchPreference
android:title="@string/camera_shot_hand_gesture"
android:key="prefs_key_camera_shot_hand_gesture"
Expand Down Expand Up @@ -46,7 +45,6 @@
</PreferenceCategory>

<PreferenceCategory android:title="@string/record">

<SwitchPreference
android:title="@string/camera_record_60fps"
android:summary="@string/camera_record_60fps_desc"
Expand Down Expand Up @@ -93,7 +91,6 @@
</PreferenceCategory>

<PreferenceCategory android:title="@string/camera_pro">

<SwitchPreference
android:title="@string/camera_pro_raw"
android:key="prefs_key_camera_pro_raw"
Expand All @@ -107,7 +104,6 @@
</PreferenceCategory>

<PreferenceCategory android:title="@string/feature">

<SwitchPreference
android:title="@string/camera_features_unlock_aiwatermark"
android:key="prefs_key_camera_features_unlock_aiwatermark"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx3072m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
Expand Down

0 comments on commit 4cdf686

Please sign in to comment.