fix: apk branch race condition#3144
Conversation
There was a problem hiding this comment.
Sorry @Irfan-del-droid, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Build StatusBuild successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/23708229326/artifacts/6165557675. Screenshots |
There was a problem hiding this comment.
Pull request overview
Updates the project’s CI workflow intended to avoid apk branch update race conditions, and also introduces new (placeholder) Gas/Dust sensor screens wired into the app’s navigation.
Changes:
- Refactors
.github/workflows/push-event.ymlto publish build outputs to theapkbranch from a singlepublish-apkjob using uploaded artifacts. - Adds new
GasSensorScreenandDustSensorScreenand registers routes for them. - Enables Gas/Dust sensor entries in the instruments list UI.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
lib/view/instruments_screen.dart |
Adds Gas/Dust sensor entries to the instruments list (UI scope change). |
lib/view/gas_sensor_screen.dart |
New placeholder Gas Sensor screen (not implemented message). |
lib/view/dust_sensor_screen.dart |
New placeholder Dust Sensor screen (not implemented message). |
lib/main.dart |
Registers new routes for Gas/Dust sensor screens. |
.github/workflows/push-event.yml |
Reworks apk branch publishing flow to collect artifacts and push once. |
| publish-apk: | ||
| name: Publish to APK Branch | ||
| needs: [android, windows, linux, linux-arm64, macos] | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.repository == 'fossasia/pslab-app' }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| echo "Copying new build files" | ||
| - name: Download all build artifacts | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| path: downloaded-artifacts | ||
| pattern: '*' | ||
| merge-multiple: false | ||
|
|
||
| cp -v ../*.dmg . | ||
| - name: Checkout apk branch | ||
| run: | | ||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git fetch origin apk | ||
| git checkout apk | ||
|
|
||
| echo "Pushing to apk branch" | ||
| - name: Prepare apk branch contents | ||
| run: | | ||
| branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | ||
| echo "Branch: $branch" | ||
|
|
||
| # Remove old files for this branch | ||
| echo "Removing previous builds from branch: $branch" | ||
| rm -rf pslab-$branch* || true | ||
| rm -rf windows/* || true | ||
| rm -rf linux/* || true | ||
| rm -rf linux-arm64/* || true | ||
| rm -rf macos/* || true | ||
|
|
||
| # Create directories | ||
| mkdir -p windows linux linux-arm64 macos | ||
|
|
||
| # Copy Android APK/AAB files | ||
| if [ -d "downloaded-artifacts/APK Generated" ]; then | ||
| echo "Copying Android APK files..." | ||
| find downloaded-artifacts/APK Generated -type f -name '*release.apk' -exec cp -v {} . \; | ||
| fi | ||
| if [ -d "downloaded-artifacts/AAB Generated" ]; then | ||
| echo "Copying Android AAB files..." | ||
| find downloaded-artifacts/AAB Generated -type f -name '*release.aab' -exec cp -v {} . \; | ||
| fi | ||
|
|
||
| # Rename Android files | ||
| for file in app*.apk app*.aab; do | ||
| if [ -f "$file" ]; then | ||
| mv "$file" "pslab-$branch-${file#*-}" | ||
| fi | ||
| done | ||
|
|
||
| # Copy Windows installer | ||
| if [ -d "downloaded-artifacts/Windows Installer" ]; then | ||
| echo "Copying Windows installer..." | ||
| cp -v downloaded-artifacts/Windows Installer/*.exe windows/ | ||
| fi | ||
|
|
||
| # Copy Linux packages | ||
| if [ -d "downloaded-artifacts/Linux Packages" ]; then | ||
| echo "Copying Linux packages..." | ||
| cp -v downloaded-artifacts/Linux Packages/*.deb linux/ | ||
| cp -v downloaded-artifacts/Linux Packages/*.rpm linux/ | ||
| fi | ||
|
|
||
| # Copy Linux ARM64 packages | ||
| if [ -d "downloaded-artifacts/Linux ARM64 Packages" ]; then | ||
| echo "Copying Linux ARM64 packages..." | ||
| cp -v downloaded-artifacts/Linux ARM64 Packages/*.deb linux-arm64/ | ||
| cp -v downloaded-artifacts/Linux ARM64 Packages/*.rpm linux-arm64/ | ||
| fi | ||
|
|
||
| # Copy macOS DMG | ||
| if [ -d "downloaded-artifacts/macOS DMG" ]; then | ||
| echo "Copying macOS DMG..." | ||
| cp -v downloaded-artifacts/macOS DMG/*.dmg macos/ | ||
| fi | ||
|
|
||
| # Show what we're committing | ||
| echo "Final apk branch contents:" | ||
| ls -la | ||
| find . -type f -name "*" | head -20 | ||
|
|
||
| git checkout --orphan temporary | ||
| - name: Commit and push apk branch | ||
| run: | | ||
| branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | ||
| git add --all . | ||
| git commit -am "[Auto] Update macOS DMG from $branch ($(date +%Y-%m-%d.%H:%M:%S))" | ||
| git branch -D apk | ||
| git branch -m apk | ||
| git push --force origin apk | ||
| git commit -am "[Auto] Update all builds from $branch ($(date +%Y-%m-%d.%H:%M:%S))" | ||
| git push origin apk |
There was a problem hiding this comment.
git push origin apk can fail with a non-fast-forward error if another workflow run updates the apk branch between this job’s checkout and push (e.g., two pushes to flutter close together). To make this reliable, add a workflow/job-level concurrency group for apk publishing and/or use a pull/rebase/force-with-lease strategy appropriate for this branch.
| # Copy Android APK/AAB files | ||
| if [ -d "downloaded-artifacts/APK Generated" ]; then | ||
| echo "Copying Android APK files..." | ||
| find downloaded-artifacts/APK Generated -type f -name '*release.apk' -exec cp -v {} . \; | ||
| fi | ||
| if [ -d "downloaded-artifacts/AAB Generated" ]; then | ||
| echo "Copying Android AAB files..." | ||
| find downloaded-artifacts/AAB Generated -type f -name '*release.aab' -exec cp -v {} . \; | ||
| fi | ||
|
|
||
| # Rename Android files | ||
| for file in app*.apk app*.aab; do | ||
| if [ -f "$file" ]; then | ||
| mv "$file" "pslab-$branch-${file#*-}" | ||
| fi | ||
| done | ||
|
|
||
| # Copy Windows installer | ||
| if [ -d "downloaded-artifacts/Windows Installer" ]; then | ||
| echo "Copying Windows installer..." | ||
| cp -v downloaded-artifacts/Windows Installer/*.exe windows/ | ||
| fi |
There was a problem hiding this comment.
The publish script uses artifact directory names containing spaces without quoting/escaping them (e.g. find downloaded-artifacts/APK Generated ... and cp -v downloaded-artifacts/Windows Installer/*.exe ...). In bash, this splits the path and will make find/cp fail. Quote (or escape) these paths consistently when used as command arguments.
| git checkout --orphan temporary | ||
| - name: Commit and push apk branch | ||
| run: | | ||
| branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} |
There was a problem hiding this comment.
actions/download-artifact downloads into downloaded-artifacts/, but that directory is never removed/ignored before git add --all .. As written, the workflow will likely commit the entire downloaded-artifacts directory into the apk branch (duplicating files and bloating the branch). Remove downloaded-artifacts (or exclude it from git add) before committing.
| branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | |
| branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | |
| # Remove downloaded artifact directory so it is not committed | |
| rm -rf downloaded-artifacts |
| - name: Upload installer to apk branch | ||
| if: ${{ github.repository == 'fossasia/pslab-app' }} | ||
| shell: bash | ||
| run: | | ||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk | ||
| cd apk | ||
| # Upload Windows installer as artifact instead of pushing to apk branch | ||
| # This will be collected by the publish-apk job | ||
| mkdir -p artifacts/windows | ||
| cp -v build/windows/x64/installer/Release/*.exe artifacts/windows/ | ||
|
|
||
| branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | ||
|
|
||
| echo "Removing previous files from branch" | ||
|
|
||
| rm -rf *.exe | ||
|
|
||
| echo "Copying new build files" | ||
|
|
||
| cp -v ../build/windows/x64/installer/Release/*.exe . | ||
|
|
||
| echo "Pushing to apk branch" | ||
|
|
||
| git checkout --orphan temporary | ||
| git add --all . | ||
| git commit -am "[Auto] Update Windows Installer from $branch ($(date +%Y-%m-%d.%H:%M:%S))" | ||
| git branch -D apk | ||
| git branch -m apk | ||
| git push --force origin apk | ||
| - name: Upload Windows Artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: Windows Installer | ||
| path: artifacts/windows |
There was a problem hiding this comment.
The Windows composite action already uploads an artifact (windows-installer). This workflow step additionally copies the installer to artifacts/windows and uploads another artifact (Windows Installer), which is redundant and increases storage/download time. Prefer reusing the artifact produced by the composite action or adjust the composite action to stop uploading if this workflow is meant to own artifact publishing.
| - name: Upload packages to apk branch | ||
| if: ${{ github.repository == 'fossasia/pslab-app' }} | ||
| run: | | ||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk | ||
| cd apk | ||
| # Upload Linux packages as artifact instead of pushing to apk branch | ||
| # This will be collected by the publish-apk job | ||
| mkdir -p artifacts/linux | ||
| cp -v *.deb artifacts/linux/ | ||
| cp -v *.rpm artifacts/linux/ | ||
|
|
||
| branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | ||
|
|
||
| echo "Removing previous files from branch" | ||
|
|
||
| find . -maxdepth 1 -type f -name '*.deb' ! -name '*arm64*' -delete | ||
| find . -maxdepth 1 -type f -name '*.rpm' ! -name '*aarch64*' -delete | ||
|
|
||
| echo "Copying new build files" | ||
|
|
||
| cp -v ../*.deb . | ||
| cp -v ../*.rpm . | ||
|
|
||
| echo "Pushing to apk branch" | ||
|
|
||
| git checkout --orphan temporary | ||
| git add --all . | ||
| git commit -am "[Auto] Update Linux Packages from $branch ($(date +%Y-%m-%d.%H:%M:%S))" | ||
| git branch -D apk | ||
| git branch -m apk | ||
| git push --force origin apk | ||
| - name: Upload Linux Artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: Linux Packages | ||
| path: artifacts/linux |
There was a problem hiding this comment.
The Linux composite action already uploads linux-packages (*.deb/*.rpm). This workflow adds an extra copy-to-artifacts/linux + second upload (Linux Packages), which is redundant and makes the publish job more complex (multiple similarly-named artifacts). Consider using the composite action artifact directly or consolidating to a single upload location/name.
| - name: Upload packages to apk branch | ||
| if: ${{ github.repository == 'fossasia/pslab-app' }} | ||
| run: | | ||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk | ||
| cd apk | ||
| # Upload Linux ARM64 packages as artifact instead of pushing to apk branch | ||
| # This will be collected by the publish-apk job | ||
| mkdir -p artifacts/linux-arm64 | ||
| cp -v *.deb artifacts/linux-arm64/ | ||
| cp -v *.rpm artifacts/linux-arm64/ | ||
|
|
||
| branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | ||
|
|
||
| echo "Removing previous files from branch" | ||
|
|
||
| rm -rf *arm64*.deb *aarch64*.rpm | ||
|
|
||
| echo "Copying new build files" | ||
|
|
||
| cp -v ../*.deb . | ||
| cp -v ../*.rpm . | ||
|
|
||
| echo "Pushing to apk branch" | ||
|
|
||
| git checkout --orphan temporary | ||
| git add --all . | ||
| git commit -am "[Auto] Update Linux ARM64 Packages from $branch ($(date +%Y-%m-%d.%H:%M:%S))" | ||
| git branch -D apk | ||
| git branch -m apk | ||
| git push --force origin apk | ||
| - name: Upload Linux ARM64 Artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: Linux ARM64 Packages | ||
| path: artifacts/linux-arm64 |
There was a problem hiding this comment.
The Linux ARM64 composite action already uploads linux-packages-arm64 (*.deb/*.rpm). This workflow step creates and uploads a second artifact (Linux ARM64 Packages) from copied files, which is redundant and increases artifact download size/time. Prefer using the existing composite action artifact or standardize on a single artifact name/source.
| // Instruments below are not yet implemented. | ||
| //_InstrumentData(appLocalizations.gasSensor, appLocalizations.gasSensorDesc, '/gassensor'), | ||
| //_InstrumentData(appLocalizations.dustSensor, appLocalizations.dustSensorDesc, '/dustsensor'), | ||
| _InstrumentData(appLocalizations.gasSensor, | ||
| appLocalizations.gasSensorDesc, '/gasSensor'), | ||
| _InstrumentData(appLocalizations.dustSensor, | ||
| appLocalizations.dustSensorDesc, '/dustSensor'), |
There was a problem hiding this comment.
PR metadata/title describes only a GitHub Actions workflow fix for the apk branch, but this change also enables new instrument entries (Gas/Dust) in the app UI. Either split these UI changes into a separate PR or update the PR description/title so reviewers understand the scope change.
| // Instruments below are not yet implemented. | ||
| //_InstrumentData(appLocalizations.gasSensor, appLocalizations.gasSensorDesc, '/gassensor'), | ||
| //_InstrumentData(appLocalizations.dustSensor, appLocalizations.dustSensorDesc, '/dustsensor'), | ||
| _InstrumentData(appLocalizations.gasSensor, | ||
| appLocalizations.gasSensorDesc, '/gasSensor'), | ||
| _InstrumentData(appLocalizations.dustSensor, | ||
| appLocalizations.dustSensorDesc, '/dustSensor'), | ||
| _InstrumentData(appLocalizations.soundMeter, | ||
| appLocalizations.soundMeterDesc, '/soundmeter'), |
There was a problem hiding this comment.
The comment // Instruments below are not yet implemented. is misleading now that it includes soundMeter, which has an implemented route/screen. Consider moving the comment to only cover truly unimplemented entries or removing it to avoid confusion.
| # Upload macOS DMG as artifact instead of pushing to apk branch | ||
| # This will be collected by the publish-apk job | ||
| mkdir -p artifacts/macos | ||
| cp -v ../*.dmg artifacts/macos/ |
There was a problem hiding this comment.
This cp -v ../*.dmg artifacts/macos/ path looks incorrect now that the job no longer cds into a cloned apk/ directory. The macOS composite action generates the DMG in the workspace root (e.g., pslab-<version>+<code>.dmg), so ../*.dmg will likely not match and will fail the job. Copy from the correct location (workspace root) or use the artifact produced by the macOS composite action instead.
| cp -v ../*.dmg artifacts/macos/ | |
| cp -v *.dmg artifacts/macos/ |
| - name: Upload dmg to apk branch | ||
| if: ${{ github.repository == 'fossasia/pslab-app' }} | ||
| run: | | ||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk | ||
| cd apk | ||
| # Upload macOS DMG as artifact instead of pushing to apk branch | ||
| # This will be collected by the publish-apk job | ||
| mkdir -p artifacts/macos | ||
| cp -v ../*.dmg artifacts/macos/ | ||
|
|
||
| branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | ||
|
|
||
| echo "Removing previous files from branch" | ||
| - name: Upload macOS Artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: macOS DMG | ||
| path: artifacts/macos |
There was a problem hiding this comment.
The macOS composite action already uploads the DMG as an artifact (macos-app). This workflow also copies to artifacts/macos and uploads a second artifact (macOS DMG), which is redundant and can easily drift (and currently appears to use the wrong DMG source path). Prefer reusing the composite action’s artifact or consolidating to one canonical artifact.
CloudyPadmal
left a comment
There was a problem hiding this comment.
Hello @Irfan-del-droid , thank you for the PR. It would be great if you could separate the dart files into a different PR, as they are not related to the issue you try to address in the PR.
|
Closed due to inactivity. |







-1_instruments_screen.png?raw=true)
-2_nav_drawer.png?raw=true)
-3_accelerometer.png?raw=true)
-4_power_source.png?raw=true)
-5_multimeter.png?raw=true)
-6_wave_generator.png?raw=true)
-7_oscilloscope.png?raw=true)
🔧 Changes Made
Modified File
.github/workflows/push-event.ymlKey Changes:
Removed Direct Push from Build Jobs
Added Artifact Upload Steps
actions/upload-artifact@v4New
publish-apkJobneeds: [android, windows, linux, linux-arm64, macos])actions/download-artifact@v4apkbranch fresh🎯 Benefits
✅ No Race Conditions: Single job controls apk branch updates
✅ Complete State: All artifacts present in one commit
✅ Auditable: Clear history of what changed when
✅ Maintainable: Separation of concerns (build vs. publish)
✅ Efficient: No redundant git clone operations
✅ Safe: Preserves artifacts from all platforms
🧪 Testing
The workflow will be tested automatically on next push to flutter branch:
📝 Notes
🔗 Related Issues