Weblate Translation Build Check #3
This file contains hidden or 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: Weblate Translation Build Check | |
| on: | |
| pull_request_review: | |
| types: [submitted] | |
| pull_request: | |
| types: [ready_for_review] | |
| branches: [main] | |
| workflow_dispatch: # Allows owner to manually trigger (owners cannot approve their own PRs) | |
| inputs: | |
| pr_number: | |
| description: 'PR number to post result comment on' | |
| required: false | |
| jobs: | |
| build: | |
| name: Build & Test Translation PR | |
| runs-on: ubuntu-latest | |
| # Only for Weblate PRs, only after approval, ready-for-review, or manual dispatch | |
| if: > | |
| github.event_name == 'workflow_dispatch' || | |
| ( | |
| github.event.pull_request.head.ref == 'weblate-translations' && | |
| ( | |
| (github.event_name == 'pull_request_review' && github.event.review.state == 'approved') || | |
| (github.event_name == 'pull_request' && github.event.action == 'ready_for_review') | |
| ) | |
| ) | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: weblate-translations | |
| - name: Setup Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - name: Gradle Cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - name: Verify strings.xml validity | |
| run: | | |
| echo "π Checking XML validity of all translation files..." | |
| python3 - <<'EOF' | |
| import xml.etree.ElementTree as ET | |
| import glob, sys | |
| files = glob.glob('android/app/src/main/res/values-*/strings.xml') | |
| errors = 0 | |
| for f in sorted(files): | |
| try: | |
| ET.parse(f) | |
| print(f' β {f}') | |
| except ET.ParseError as e: | |
| print(f' β {f} β Invalid XML: {e}') | |
| errors += 1 | |
| if errors > 0: | |
| print(f'β {errors} file(s) have XML errors') | |
| sys.exit(1) | |
| print('β All translation files are valid XML') | |
| EOF | |
| - name: Build Debug APK | |
| run: | | |
| cd android | |
| ./gradlew assembleStandardDebug assembleFdroidDebug --no-daemon --stacktrace | |
| - name: Run Unit Tests | |
| run: | | |
| cd android | |
| ./gradlew test --no-daemon --stacktrace | |
| - name: Verify build result | |
| run: | | |
| if [ -f "android/app/build/outputs/apk/standard/debug/app-standard-debug.apk" ]; then | |
| echo "β Standard Debug APK built successfully" | |
| else | |
| echo "β Standard Debug APK build failed" | |
| exit 1 | |
| fi | |
| if [ -f "android/app/build/outputs/apk/fdroid/debug/app-fdroid-debug.apk" ]; then | |
| echo "β F-Droid Debug APK built successfully" | |
| else | |
| echo "β F-Droid Debug APK build failed" | |
| exit 1 | |
| fi | |
| - name: Post PR comment | |
| uses: actions/github-script@v7 | |
| if: success() | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `## β Translation Build successful! | |
| The translation PR was built and tested successfully. | |
| **Next step:** Perform squash-merge. | |
| > Don't forget to update \`locales_config.xml\` if a new language was added.` | |
| }) |