Skip to content

Commit 7b09993

Browse files
fix: serialize apk branch publishing to prevent race condition
1 parent d775b51 commit 7b09993

1 file changed

Lines changed: 126 additions & 130 deletions

File tree

.github/workflows/push-event.yml

Lines changed: 126 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -111,47 +111,6 @@ jobs:
111111
name: AAB Generated
112112
path: build/app/outputs/bundle
113113

114-
- name: Upload APK/AAB to apk branch
115-
if: ${{ github.repository == 'fossasia/pslab-app' }}
116-
run: |
117-
git config --global user.name "github-actions[bot]"
118-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
119-
120-
git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk
121-
cd apk
122-
123-
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
124-
125-
echo "Removing previous files from branch"
126-
127-
rm -rf pslab-$branch*
128-
129-
ls
130-
131-
echo "Copying new build files"
132-
133-
find ../build/app/outputs/flutter-apk -type f \( -name '*release.apk' -o -name '*release.aab' \) -exec cp -v {} . \;
134-
find ../build/app/outputs/bundle -type f \( -name '*release.apk' -o -name '*release.aab' \) -exec cp -v {} . \;
135-
136-
ls
137-
138-
echo "Renaming new build files"
139-
140-
for file in app*; do
141-
mv $file pslab-$branch-${file#*-}
142-
done
143-
144-
ls
145-
146-
echo "Pushing to apk branch"
147-
148-
git checkout --orphan temporary
149-
git add --all .
150-
git commit -am "[Auto] Update APK/AABs from $branch ($(date +%Y-%m-%d.%H:%M:%S))"
151-
git branch -D apk
152-
git branch -m apk
153-
git push --force origin apk
154-
155114
- name: Update app in Open Testing track
156115
if: ${{ github.repository == 'fossasia/pslab-app' }}
157116
run: |
@@ -285,30 +244,16 @@ jobs:
285244
if: ${{ github.repository == 'fossasia/pslab-app' }}
286245
shell: bash
287246
run: |
288-
git config --global user.name "github-actions[bot]"
289-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
290-
291-
git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk
292-
cd apk
247+
# Upload Windows installer as artifact instead of pushing to apk branch
248+
# This will be collected by the publish-apk job
249+
mkdir -p artifacts/windows
250+
cp -v build/windows/x64/installer/Release/*.exe artifacts/windows/
293251
294-
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
295-
296-
echo "Removing previous files from branch"
297-
298-
rm -rf *.exe
299-
300-
echo "Copying new build files"
301-
302-
cp -v ../build/windows/x64/installer/Release/*.exe .
303-
304-
echo "Pushing to apk branch"
305-
306-
git checkout --orphan temporary
307-
git add --all .
308-
git commit -am "[Auto] Update Windows Installer from $branch ($(date +%Y-%m-%d.%H:%M:%S))"
309-
git branch -D apk
310-
git branch -m apk
311-
git push --force origin apk
252+
- name: Upload Windows Artifact
253+
uses: actions/upload-artifact@v4
254+
with:
255+
name: Windows Installer
256+
path: artifacts/windows
312257

313258
linux:
314259
name: Linux Flutter Build
@@ -326,32 +271,17 @@ jobs:
326271
- name: Upload packages to apk branch
327272
if: ${{ github.repository == 'fossasia/pslab-app' }}
328273
run: |
329-
git config --global user.name "github-actions[bot]"
330-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
331-
332-
git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk
333-
cd apk
274+
# Upload Linux packages as artifact instead of pushing to apk branch
275+
# This will be collected by the publish-apk job
276+
mkdir -p artifacts/linux
277+
cp -v *.deb artifacts/linux/
278+
cp -v *.rpm artifacts/linux/
334279
335-
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
336-
337-
echo "Removing previous files from branch"
338-
339-
find . -maxdepth 1 -type f -name '*.deb' ! -name '*arm64*' -delete
340-
find . -maxdepth 1 -type f -name '*.rpm' ! -name '*aarch64*' -delete
341-
342-
echo "Copying new build files"
343-
344-
cp -v ../*.deb .
345-
cp -v ../*.rpm .
346-
347-
echo "Pushing to apk branch"
348-
349-
git checkout --orphan temporary
350-
git add --all .
351-
git commit -am "[Auto] Update Linux Packages from $branch ($(date +%Y-%m-%d.%H:%M:%S))"
352-
git branch -D apk
353-
git branch -m apk
354-
git push --force origin apk
280+
- name: Upload Linux Artifact
281+
uses: actions/upload-artifact@v4
282+
with:
283+
name: Linux Packages
284+
path: artifacts/linux
355285

356286
linux-arm64:
357287
name: Linux ARM64 Flutter Build
@@ -369,31 +299,17 @@ jobs:
369299
- name: Upload packages to apk branch
370300
if: ${{ github.repository == 'fossasia/pslab-app' }}
371301
run: |
372-
git config --global user.name "github-actions[bot]"
373-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
374-
375-
git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk
376-
cd apk
302+
# Upload Linux ARM64 packages as artifact instead of pushing to apk branch
303+
# This will be collected by the publish-apk job
304+
mkdir -p artifacts/linux-arm64
305+
cp -v *.deb artifacts/linux-arm64/
306+
cp -v *.rpm artifacts/linux-arm64/
377307
378-
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
379-
380-
echo "Removing previous files from branch"
381-
382-
rm -rf *arm64*.deb *aarch64*.rpm
383-
384-
echo "Copying new build files"
385-
386-
cp -v ../*.deb .
387-
cp -v ../*.rpm .
388-
389-
echo "Pushing to apk branch"
390-
391-
git checkout --orphan temporary
392-
git add --all .
393-
git commit -am "[Auto] Update Linux ARM64 Packages from $branch ($(date +%Y-%m-%d.%H:%M:%S))"
394-
git branch -D apk
395-
git branch -m apk
396-
git push --force origin apk
308+
- name: Upload Linux ARM64 Artifact
309+
uses: actions/upload-artifact@v4
310+
with:
311+
name: Linux ARM64 Packages
312+
path: artifacts/linux-arm64
397313

398314
macos:
399315
name: macOS Flutter Build
@@ -411,27 +327,107 @@ jobs:
411327
- name: Upload dmg to apk branch
412328
if: ${{ github.repository == 'fossasia/pslab-app' }}
413329
run: |
414-
git config --global user.name "github-actions[bot]"
415-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
416-
417-
git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk
418-
cd apk
330+
# Upload macOS DMG as artifact instead of pushing to apk branch
331+
# This will be collected by the publish-apk job
332+
mkdir -p artifacts/macos
333+
cp -v ../*.dmg artifacts/macos/
419334
420-
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
421-
422-
echo "Removing previous files from branch"
335+
- name: Upload macOS Artifact
336+
uses: actions/upload-artifact@v4
337+
with:
338+
name: macOS DMG
339+
path: artifacts/macos
423340

424-
rm -rf *.dmg
341+
publish-apk:
342+
name: Publish to APK Branch
343+
needs: [android, windows, linux, linux-arm64, macos]
344+
runs-on: ubuntu-latest
345+
if: ${{ github.repository == 'fossasia/pslab-app' }}
346+
steps:
347+
- name: Checkout repository
348+
uses: actions/checkout@v4
425349

426-
echo "Copying new build files"
350+
- name: Download all build artifacts
351+
uses: actions/download-artifact@v4
352+
with:
353+
path: downloaded-artifacts
354+
pattern: '*'
355+
merge-multiple: false
427356

428-
cp -v ../*.dmg .
357+
- name: Checkout apk branch
358+
run: |
359+
git config --global user.name "github-actions[bot]"
360+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
361+
git fetch origin apk
362+
git checkout apk
429363
430-
echo "Pushing to apk branch"
364+
- name: Prepare apk branch contents
365+
run: |
366+
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
367+
echo "Branch: $branch"
368+
369+
# Remove old files for this branch
370+
echo "Removing previous builds from branch: $branch"
371+
rm -rf pslab-$branch* || true
372+
rm -rf windows/* || true
373+
rm -rf linux/* || true
374+
rm -rf linux-arm64/* || true
375+
rm -rf macos/* || true
376+
377+
# Create directories
378+
mkdir -p windows linux linux-arm64 macos
379+
380+
# Copy Android APK/AAB files
381+
if [ -d "downloaded-artifacts/APK Generated" ]; then
382+
echo "Copying Android APK files..."
383+
find downloaded-artifacts/APK Generated -type f -name '*release.apk' -exec cp -v {} . \;
384+
fi
385+
if [ -d "downloaded-artifacts/AAB Generated" ]; then
386+
echo "Copying Android AAB files..."
387+
find downloaded-artifacts/AAB Generated -type f -name '*release.aab' -exec cp -v {} . \;
388+
fi
389+
390+
# Rename Android files
391+
for file in app*.apk app*.aab; do
392+
if [ -f "$file" ]; then
393+
mv "$file" "pslab-$branch-${file#*-}"
394+
fi
395+
done
396+
397+
# Copy Windows installer
398+
if [ -d "downloaded-artifacts/Windows Installer" ]; then
399+
echo "Copying Windows installer..."
400+
cp -v downloaded-artifacts/Windows Installer/*.exe windows/
401+
fi
402+
403+
# Copy Linux packages
404+
if [ -d "downloaded-artifacts/Linux Packages" ]; then
405+
echo "Copying Linux packages..."
406+
cp -v downloaded-artifacts/Linux Packages/*.deb linux/
407+
cp -v downloaded-artifacts/Linux Packages/*.rpm linux/
408+
fi
409+
410+
# Copy Linux ARM64 packages
411+
if [ -d "downloaded-artifacts/Linux ARM64 Packages" ]; then
412+
echo "Copying Linux ARM64 packages..."
413+
cp -v downloaded-artifacts/Linux ARM64 Packages/*.deb linux-arm64/
414+
cp -v downloaded-artifacts/Linux ARM64 Packages/*.rpm linux-arm64/
415+
fi
416+
417+
# Copy macOS DMG
418+
if [ -d "downloaded-artifacts/macOS DMG" ]; then
419+
echo "Copying macOS DMG..."
420+
cp -v downloaded-artifacts/macOS DMG/*.dmg macos/
421+
fi
422+
423+
# Show what we're committing
424+
echo "Final apk branch contents:"
425+
ls -la
426+
find . -type f -name "*" | head -20
431427
432-
git checkout --orphan temporary
428+
- name: Commit and push apk branch
429+
run: |
430+
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
433431
git add --all .
434-
git commit -am "[Auto] Update macOS DMG from $branch ($(date +%Y-%m-%d.%H:%M:%S))"
435-
git branch -D apk
436-
git branch -m apk
437-
git push --force origin apk
432+
git commit -am "[Auto] Update all builds from $branch ($(date +%Y-%m-%d.%H:%M:%S))"
433+
git push origin apk

0 commit comments

Comments
 (0)