|
4 | 4 | workflow_dispatch: # Ermöglicht manuelle Ausführung des Workflows |
5 | 5 |
|
6 | 6 | jobs: |
| 7 | + detect-changes: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + outputs: |
| 10 | + app_changed: ${{ steps.changes.outputs.app }} |
| 11 | + humanoperator_changed: ${{ steps.changes.outputs.humanoperator }} |
| 12 | + shared_changed: ${{ steps.changes.outputs.shared }} |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 2 # Letzten 2 Commits holen für Diff |
| 18 | + |
| 19 | + - name: Detect changed files |
| 20 | + id: changes |
| 21 | + run: | |
| 22 | + # Geänderte Dateien im letzten Commit ermitteln |
| 23 | + CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "") |
| 24 | + |
| 25 | + # Falls kein vorheriger Commit existiert (erster Commit), alles bauen |
| 26 | + if [ -z "$CHANGED_FILES" ]; then |
| 27 | + echo "app=true" >> $GITHUB_OUTPUT |
| 28 | + echo "humanoperator=true" >> $GITHUB_OUTPUT |
| 29 | + echo "shared=true" >> $GITHUB_OUTPUT |
| 30 | + echo "No previous commit found - building all modules" |
| 31 | + exit 0 |
| 32 | + fi |
| 33 | + |
| 34 | + echo "Changed files:" |
| 35 | + echo "$CHANGED_FILES" |
| 36 | + |
| 37 | + # Prüfen ob shared/root files geändert wurden (build.gradle, settings.gradle, etc.) |
| 38 | + SHARED_CHANGED=false |
| 39 | + if echo "$CHANGED_FILES" | grep -qE '^(build\.gradle|settings\.gradle|gradle\.properties|gradle/|buildSrc/)'; then |
| 40 | + SHARED_CHANGED=true |
| 41 | + fi |
| 42 | + |
| 43 | + # Prüfen ob app/ Dateien geändert wurden |
| 44 | + APP_CHANGED=false |
| 45 | + if echo "$CHANGED_FILES" | grep -q '^app/'; then |
| 46 | + APP_CHANGED=true |
| 47 | + fi |
| 48 | + |
| 49 | + # Prüfen ob humanoperator/ Dateien geändert wurden |
| 50 | + HUMANOPERATOR_CHANGED=false |
| 51 | + if echo "$CHANGED_FILES" | grep -q '^humanoperator/'; then |
| 52 | + HUMANOPERATOR_CHANGED=true |
| 53 | + fi |
| 54 | + |
| 55 | + echo "app=$APP_CHANGED" >> $GITHUB_OUTPUT |
| 56 | + echo "humanoperator=$HUMANOPERATOR_CHANGED" >> $GITHUB_OUTPUT |
| 57 | + echo "shared=$SHARED_CHANGED" >> $GITHUB_OUTPUT |
| 58 | + |
| 59 | + echo "Results: app=$APP_CHANGED, humanoperator=$HUMANOPERATOR_CHANGED, shared=$SHARED_CHANGED" |
| 60 | +
|
7 | 61 | build: |
| 62 | + needs: detect-changes |
8 | 63 | runs-on: ubuntu-latest |
| 64 | + env: |
| 65 | + BUILD_APP: ${{ needs.detect-changes.outputs.app_changed == 'true' || needs.detect-changes.outputs.shared_changed == 'true' }} |
| 66 | + BUILD_HUMANOPERATOR: ${{ needs.detect-changes.outputs.humanoperator_changed == 'true' || needs.detect-changes.outputs.shared_changed == 'true' }} |
9 | 67 |
|
10 | 68 | steps: |
11 | 69 | - name: Checkout code |
@@ -38,19 +96,31 @@ jobs: |
38 | 96 | run: chmod +x gradlew |
39 | 97 |
|
40 | 98 | - name: Build app module (debug) |
| 99 | + if: env.BUILD_APP == 'true' |
41 | 100 | run: ./gradlew :app:assembleDebug |
42 | 101 |
|
43 | 102 | - name: Build humanoperator module (debug) |
| 103 | + if: env.BUILD_HUMANOPERATOR == 'true' |
44 | 104 | run: ./gradlew :humanoperator:assembleDebug |
45 | 105 |
|
46 | 106 | - name: Upload app APK |
| 107 | + if: env.BUILD_APP == 'true' |
47 | 108 | uses: actions/upload-artifact@v4 |
48 | 109 | with: |
49 | 110 | name: app-debug |
50 | 111 | path: app/build/outputs/apk/debug/app-debug.apk |
51 | 112 |
|
52 | 113 | - name: Upload humanoperator APK |
| 114 | + if: env.BUILD_HUMANOPERATOR == 'true' |
53 | 115 | uses: actions/upload-artifact@v4 |
54 | 116 | with: |
55 | 117 | name: humanoperator-debug |
56 | 118 | path: humanoperator/build/outputs/apk/debug/humanoperator-debug.apk |
| 119 | + |
| 120 | + - name: Build summary |
| 121 | + run: | |
| 122 | + echo "### Build Summary" >> $GITHUB_STEP_SUMMARY |
| 123 | + echo "| Module | Built |" >> $GITHUB_STEP_SUMMARY |
| 124 | + echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo "| app | ${{ env.BUILD_APP }} |" >> $GITHUB_STEP_SUMMARY |
| 126 | + echo "| humanoperator | ${{ env.BUILD_HUMANOPERATOR }} |" >> $GITHUB_STEP_SUMMARY |
0 commit comments