Files
5chan/.github/workflows/ci.yml
T
Tommaso CasaburiandGitHub b2946e8b2e fix(ci): publish coverage badge from badges branch (#1091)
* fix(ci): publish coverage badge from badges branch

* fix(ci): address badge review findings
2026-03-17 16:10:55 +08:00

457 lines
13 KiB
YAML

name: CI
on:
push:
branches: [development, master]
pull_request:
branches: [development, master]
workflow_dispatch:
env:
HUSKY: '0'
permissions:
contents: read
jobs:
quality:
name: Quality + Smoke
runs-on: ubuntu-22.04
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js v22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'yarn'
- name: Install dependencies
run: |
for i in 1 2 3; do
echo "yarn install attempt $i"
yarn install --frozen-lockfile --ignore-engines --network-timeout 100000 --network-concurrency 1 && break
sleep 5
[ "$i" = "3" ] && exit 1
done
- name: Run Vitest
run: yarn test --run
- name: Collect coverage
run: yarn test:coverage
- name: Write coverage badge payload
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: node scripts/write-coverage-badge.mjs
- name: Upload coverage badge
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: coverage-badge
path: badges/coverage.json
if-no-files-found: error
- name: Lint
run: yarn lint
- name: Type check
run: yarn type-check
- name: Build React app
run: yarn build
env:
CI: ''
- name: Build preload script
run: yarn build:preload
- name: Verify build outputs
run: |
ls -la build/ || exit 1
ls -la build/electron/preload.cjs || exit 1
ls -la build/index.html || exit 1
- name: Verify forge config
run: node -e "import('./forge.config.js').then(c => console.log('Config loaded, makers:', c.default.makers?.length || 0)).catch(e => { console.error(e); process.exit(1); })"
- name: Run React Doctor
run: yarn doctor
- name: Install Chromium for smoke tests
run: npx playwright install --with-deps chromium
- name: Smoke test built web app
run: node scripts/smoke-web-app.js --start-preview
- name: Upload coverage summary
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-summary
path: coverage/coverage-summary.json
if-no-files-found: warn
publish-coverage-badge:
name: Publish Coverage Badge
runs-on: ubuntu-22.04
needs: quality
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
permissions:
contents: write
env:
COVERAGE_BADGE_BRANCH: badges
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download coverage badge
uses: actions/download-artifact@v4
with:
name: coverage-badge
path: ${{ runner.temp }}/coverage-badge
- name: Publish coverage badge branch
env:
BADGE_SOURCE_PATH: ${{ runner.temp }}/coverage-badge/coverage.json
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git ls-remote --exit-code --heads origin "${COVERAGE_BADGE_BRANCH}"; then
git fetch origin "${COVERAGE_BADGE_BRANCH}:${COVERAGE_BADGE_BRANCH}"
git switch "${COVERAGE_BADGE_BRANCH}"
else
git switch --orphan "${COVERAGE_BADGE_BRANCH}"
git rm -rf --ignore-unmatch .
find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
fi
mkdir -p badges
cp "${BADGE_SOURCE_PATH}" badges/coverage.json
git add badges/coverage.json
if git diff --cached --quiet; then
echo "Coverage badge is already up to date."
exit 0
fi
git commit -m "chore(ci): update coverage badge"
for attempt in 1 2 3; do
if git push --force-with-lease origin "HEAD:${COVERAGE_BADGE_BRANCH}"; then
exit 0
fi
if [ "${attempt}" -eq 3 ]; then
echo "Failed to publish coverage badge after ${attempt} attempts."
exit 1
fi
echo "Push failed on attempt ${attempt}; syncing with origin/${COVERAGE_BADGE_BRANCH} before retrying..."
git fetch origin "${COVERAGE_BADGE_BRANCH}" || true
if git show-ref --verify --quiet "refs/remotes/origin/${COVERAGE_BADGE_BRANCH}"; then
git rebase "origin/${COVERAGE_BADGE_BRANCH}"
fi
sleep $((attempt * 2))
done
android-build:
name: Android Build
runs-on: ubuntu-22.04
needs: quality
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Java 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Setup Node.js v22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'yarn'
- name: Install dependencies
run: |
for i in 1 2 3; do
echo "yarn install attempt $i"
yarn install --frozen-lockfile --ignore-engines --network-timeout 100000 --network-concurrency 1 && break
sleep 5
[ "$i" = "3" ] && exit 1
done
- name: Build React app
run: yarn build
env:
CI: ''
- name: Sync Capacitor Android project
run: npx cap sync android
- name: Run Android unit tests and assemble debug APK
run: cd android && ./gradlew testDebugUnitTest assembleDebug --stacktrace
package-linux:
name: Package Linux (Ubuntu)
runs-on: ubuntu-22.04
needs: quality
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js v22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'yarn'
- name: Cache electron binaries
uses: actions/cache@v4
with:
path: ~/.cache/electron
key: ${{ runner.os }}-electron-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-electron-v2-
- name: Install dependencies
run: |
for i in 1 2 3; do
echo "yarn install attempt $i"
yarn install --frozen-lockfile --ignore-engines --network-timeout 100000 --network-concurrency 1 && break
sleep 5
[ "$i" = "3" ] && exit 1
done
- name: Build React app
run: yarn build
env:
CI: ''
- name: Build preload script
run: yarn build:preload
- name: Verify build outputs
run: |
ls -la build/ || exit 1
ls -la build/electron/preload.cjs || exit 1
ls -la build/index.html || exit 1
- name: Package Electron app
timeout-minutes: 30
run: |
set -o pipefail
yarn electron-forge package 2>&1 | tee forge-output.log
ls -la out/
- name: Verify executable
run: |
ls -la out/
EXE=$(node scripts/find-forge-executable.js)
echo "Found executable: $EXE"
test -f "$EXE" && test -x "$EXE" && echo "Executable is valid"
package-mac-intel:
name: Package Mac (Intel)
runs-on: macos-15-intel
needs: quality
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js v22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'yarn'
- name: Install setuptools for native modules
run: pip3 install --break-system-packages setuptools || pip3 install --user setuptools || true
- name: Cache electron binaries
uses: actions/cache@v4
with:
path: ~/Library/Caches/electron
key: ${{ runner.os }}-electron-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-electron-v2-
- name: Install dependencies
run: |
for i in 1 2 3; do
echo "yarn install attempt $i"
yarn install --frozen-lockfile --ignore-engines --network-timeout 100000 --network-concurrency 1 && break
sleep 5
[ "$i" = "3" ] && exit 1
done
- name: Build React app
run: yarn build
env:
CI: ''
- name: Build preload script
run: yarn build:preload
- name: Verify build outputs
run: |
ls -la build/ || exit 1
ls -la build/electron/preload.cjs || exit 1
ls -la build/index.html || exit 1
- name: Package Electron app
timeout-minutes: 30
run: |
set -o pipefail
yarn electron-forge package 2>&1 | tee forge-output.log
ls -la out/
- name: Verify executable
run: |
ls -la out/
EXE=$(node scripts/find-forge-executable.js)
echo "Found executable: $EXE"
test -f "$EXE" && test -x "$EXE" && echo "Executable is valid"
package-mac-arm:
name: Package Mac (Apple Silicon)
runs-on: macos-latest
needs: quality
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js v22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'yarn'
- name: Install setuptools for native modules
run: pip3 install --break-system-packages setuptools || pip3 install --user setuptools || true
- name: Cache electron binaries
uses: actions/cache@v4
with:
path: ~/Library/Caches/electron
key: ${{ runner.os }}-electron-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-electron-v2-
- name: Install dependencies
run: |
for i in 1 2 3; do
echo "yarn install attempt $i"
yarn install --frozen-lockfile --ignore-engines --network-timeout 100000 --network-concurrency 1 && break
sleep 5
[ "$i" = "3" ] && exit 1
done
- name: Build React app
run: yarn build
env:
CI: ''
- name: Build preload script
run: yarn build:preload
- name: Verify build outputs
run: |
ls -la build/ || exit 1
ls -la build/electron/preload.cjs || exit 1
ls -la build/index.html || exit 1
- name: Package Electron app
timeout-minutes: 30
run: |
set -o pipefail
yarn electron-forge package 2>&1 | tee forge-output.log
ls -la out/
- name: Verify executable
run: |
ls -la out/
EXE=$(node scripts/find-forge-executable.js)
echo "Found executable: $EXE"
test -f "$EXE" && test -x "$EXE" && echo "Executable is valid"
package-windows:
name: Package Windows
runs-on: windows-2022
needs: quality
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js v22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'yarn'
- name: Cache electron binaries
uses: actions/cache@v4
with:
path: ~/AppData/Local/electron/Cache
key: ${{ runner.os }}-electron-v2-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-electron-v2-
- name: Install dependencies
shell: bash
run: |
for i in 1 2 3; do
echo "yarn install attempt $i"
yarn install --frozen-lockfile --ignore-engines --network-timeout 100000 --network-concurrency 1 && break
sleep 5
[ "$i" = "3" ] && exit 1
done
- name: Build React app
shell: bash
run: yarn build
env:
CI: ''
- name: Build preload script
shell: bash
run: yarn build:preload
- name: Verify build outputs
shell: bash
run: |
ls -la build/ || exit 1
ls -la build/electron/preload.cjs || exit 1
ls -la build/index.html || exit 1
- name: Package Electron app
shell: bash
timeout-minutes: 30
run: |
set -o pipefail
yarn electron-forge package 2>&1 | tee forge-output.log
ls -la out/
- name: Verify executable
shell: bash
run: |
ls -la out/
EXE=$(node scripts/find-forge-executable.js)
echo "Found executable: $EXE"
test -f "$EXE" && test -x "$EXE" && echo "Executable is valid"