Skip to content

fix: apk branch race condition#3144

Closed
Irfan-del-droid wants to merge 3 commits into
fossasia:flutterfrom
Irfan-del-droid:fix/apk-branch-race-condition
Closed

fix: apk branch race condition#3144
Irfan-del-droid wants to merge 3 commits into
fossasia:flutterfrom
Irfan-del-droid:fix/apk-branch-race-condition

Conversation

@Irfan-del-droid

Copy link
Copy Markdown

🔧 Changes Made

Modified File
.github/workflows/push-event.yml

Key Changes:

  1. Removed Direct Push from Build Jobs

    • Android job: Removed "Upload APK/AAB to apk branch" step
    • Windows job: Removed direct git push logic
    • Linux job: Removed direct git push logic
    • Linux ARM64 job: Removed direct git push logic
    • macOS job: Removed direct git push logic
  2. Added Artifact Upload Steps

    • All build jobs now upload artifacts using actions/upload-artifact@v4
    • Artifacts are named consistently for easy identification
    • No git operations in build jobs
  3. New publish-apk Job

    • Runs AFTER all build jobs complete (needs: [android, windows, linux, linux-arm64, macos])
    • Downloads ALL artifacts using actions/download-artifact@v4
    • Checks out apk branch fresh
    • Organizes artifacts by platform
    • Commits and pushes ONCE

🎯 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:

  • All build jobs will run in parallel (unchanged behavior)
  • Each job uploads artifacts (new behavior)
  • Final publish-apk job collects all artifacts (new behavior)
  • Single atomic update to apk branch (fixed behavior)

📝 Notes

  • This fix addresses the Copilot review concern from PR chore: add upload of ARM64 build to apk branch #3113
  • The solution follows GitHub Actions best practices for multi-platform builds
  • No changes to app logic, build processes, or other workflows
  • Focused solely on fixing the workflow race condition

🔗 Related Issues

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions

Copy link
Copy Markdown
Contributor

Build Status

Build successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/23708229326/artifacts/6165557675.

Screenshots

Android Screenshots
iPhone Screenshots
iPad Screenshots

@marcnause marcnause changed the title Fix/apk branch race condition Fix: apk branch race condition Mar 29, 2026
@marcnause marcnause requested a review from Copilot March 29, 2026 14:33
@marcnause marcnause changed the title Fix: apk branch race condition fix: apk branch race condition Mar 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.yml to publish build outputs to the apk branch from a single publish-apk job using uploaded artifacts.
  • Adds new GasSensorScreen and DustSensorScreen and 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.

Comment on lines +341 to +433
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

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +380 to +401
# 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

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
git checkout --orphan temporary
- name: Commit and push apk branch
run: |
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines 243 to +256
- 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

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 271 to +284
- 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

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 299 to +312
- 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

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 116 to +120
// 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'),

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 116 to 122
// 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'),

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
# 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/

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
cp -v ../*.dmg artifacts/macos/
cp -v *.dmg artifacts/macos/

Copilot uses AI. Check for mistakes.
Comment on lines 327 to +339
- 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

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

@CloudyPadmal CloudyPadmal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@marcnause

Copy link
Copy Markdown
Contributor

Closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Content of apk branch is possibly overwritten

4 participants