Fix: Build and Publish workflow (#1831) #1579
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
# GitHub Actions workflow for continuous integration of Mobile-Wallet project | |
# Runs on master and dev branches to ensure code quality and build stability | |
name: Mobile-Wallet CI[Master/Dev] | |
# Trigger conditions for the workflow | |
on: | |
push: | |
branches: [ dev ] # Runs on pushes to dev branch | |
pull_request: # Runs on all pull requests | |
# Concurrency settings to prevent multiple simultaneous workflow runs | |
concurrency: | |
group: build-${{ github.ref }} | |
cancel-in-progress: true # Cancels previous runs if a new one is triggered | |
jobs: | |
# Initial setup job to prepare the environment | |
setup: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 # Checkout repository code | |
- uses: actions/setup-java@v4 # Setup Java environment | |
with: | |
distribution: 'zulu' | |
java-version: 17 | |
- uses: gradle/actions/setup-gradle@v4 # Setup Gradle build tool | |
# Cache Gradle dependencies and build outputs to speed up future builds | |
- name: Cache Gradle and build outputs | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
build | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: ${{ runner.os }}-gradle- | |
# Code quality checks job | |
checks: | |
needs: setup # Depends on setup job completion | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
# Define different types of checks to run in parallel | |
check: [ build_logic, spotless, detekt ] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'zulu' | |
java-version: 17 | |
# Run different checks based on matrix value | |
- name: Run ${{ matrix.check }} | |
id: run_check | |
run: | | |
if [ "${{ matrix.check }}" = "build_logic" ]; then | |
./gradlew check -p build-logic # Check build logic | |
elif [ "${{ matrix.check }}" = "spotless" ]; then | |
./gradlew spotlessCheck --no-configuration-cache --no-daemon # Check code formatting | |
elif [ "${{ matrix.check }}" = "detekt" ]; then | |
./gradlew detekt # Run static code analysis | |
fi | |
# Upload detekt analysis reports as artifacts | |
- name: Upload Detekt Reports | |
if: ${{ matrix.check == 'detekt' && steps.run_check.outcome == 'success' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: detekt-reports | |
path: | | |
**/build/reports/detekt/detekt.md | |
# Dependency verification and management job | |
dependency_guard: | |
needs: setup | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'zulu' | |
java-version: 17 | |
# Verify dependencies against baseline | |
- name: Check Dependency Guard | |
id: dependencyguard_verify | |
continue-on-error: true | |
run: ./gradlew :mifospay-android:dependencyGuard | |
# Prevent baseline updates on fork PRs | |
- name: Prevent updating Dependency Guard baselines if this is a fork | |
id: checkfork_dependencyguard | |
if: steps.dependencyguard_verify.outcome == 'failure' && github.event.pull_request.head.repo.full_name != github.repository | |
run: | | |
echo "::error::Dependency Guard failed, please update baselines with: ./gradlew dependencyGuardBaseline" && exit 1 | |
# Generate new dependency baselines if verification fails | |
- name: Generate new Dependency Guard baselines if verification failed and it's a PR | |
id: dependencyguard_baseline | |
if: steps.dependencyguard_verify.outcome == 'failure' && github.event_name == 'pull_request' | |
run: | | |
./gradlew :mifospay-android:dependencyGuardBaseline | |
# Automatically commit new baselines if generated | |
- name: Push new Dependency Guard baselines if available | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
if: steps.dependencyguard_baseline.outcome == 'success' | |
with: | |
file_pattern: '**/dependencies/*.txt' | |
disable_globbing: true | |
commit_message: "🤖 Updates baselines for Dependency Guard" | |
# Android app build job | |
build: | |
needs: [ checks, dependency_guard ] # Requires successful checks and dependency verification | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'zulu' | |
java-version: 17 | |
# Build debug APK for demo flavor | |
- name: Build APKs | |
run: ./gradlew :mifospay-android:assembleDemoDebug | |
# Upload built APKs as artifacts | |
- name: Upload APKs | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Android APKs | |
path: '**/build/outputs/apk/**/*.apk' | |
# Desktop application build job for multiple platforms | |
build_desktop_app: | |
needs: [ checks, dependency_guard ] | |
strategy: | |
matrix: | |
# Build for Windows, Linux, and MacOS | |
os: | |
- windows-latest | |
- ubuntu-latest | |
- macos-latest | |
runs-on: ${{ matrix.os }} | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'zulu' | |
java-version: 17 | |
# Build desktop application for current OS | |
- name: Build Desktop App | |
run: ./gradlew packageDistributionForCurrentOS | |
# Upload Windows executables and installers | |
- name: Upload Windows Apps | |
if: matrix.os == 'windows-latest' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Windows-Apps | |
path: | | |
./mifospay-desktop/build/compose/binaries/main/exe/*.exe | |
./mifospay-desktop/build/compose/binaries/main/msi/*.msi | |
# Upload Linux package | |
- name: Upload Linux App | |
if: matrix.os == 'ubuntu-latest' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Linux-App | |
path: './mifospay-desktop/build/compose/binaries/main/deb/*.deb' | |
# Upload MacOS package | |
- name: Upload MacOS App | |
if: matrix.os == 'macos-latest' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: MacOS-App | |
path: './mifospay-desktop/build/compose/binaries/main/dmg/*.dmg' |