Files
bedolaga-cabinet/.github/workflows/sync-and-build.yml

159 lines
6.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Sync upstream & build custom cabinet static
# Подтягивает апстрим BEDOLAGA-DEV/bedolaga-cabinet поверх нашего форка,
# накатывает локальный патч (см. src/pages/Subscription.tsx), собирает
# фронтенд и публикует статику как GitHub Release-ассет.
# Если апстрим правил тот же кусок, что и наш патч — merge упадёт с
# конфликтом, и это НАМЕРЕННО: незнакомый код от стороннего разработчика
# не должен автоматически домёрживаться без ручной проверки.
on:
schedule:
- cron: '0 6 * * *' # ежедневно в 06:00 UTC; GitHub может отключить
# cron-триггер после ~60 дней без активности в репозитории —
# тогда просто запустите workflow вручную (workflow_dispatch).
workflow_dispatch: {}
permissions:
contents: write
concurrency:
group: sync-and-build
cancel-in-progress: false
env:
UPSTREAM_REPO: https://github.com/BEDOLAGA-DEV/bedolaga-cabinet.git
jobs:
sync-and-build:
runs-on: ubuntu-latest
steps:
- name: Checkout fork
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch and merge upstream
id: sync
run: |
BEFORE=$(git rev-parse HEAD)
git remote add upstream "$UPSTREAM_REPO"
git fetch upstream main
git merge --no-edit upstream/main
AFTER=$(git rev-parse HEAD)
if [ "$BEFORE" != "$AFTER" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Strip upstream-only CI/CD files
# Апстрим хранит у себя dependabot.yml и CI-workflow'ы, которых нам
# не нужно в приватном форке (плодят PR/раны, требуют чужих секретов).
# Merge может притащить их обратно — вычищаем перед пушем.
if: steps.sync.outputs.changed == 'true'
run: |
FILES=(
.github/dependabot.yml
.github/workflows/ci.yml
.github/workflows/codeql.yml
.github/workflows/docker.yml
.github/workflows/lint.yml
.github/workflows/release-please.yml
.github/workflows/release.yml
.github/workflows/security-audit.yml
)
REMOVED=false
for f in "${FILES[@]}"; do
if [ -e "$f" ]; then
git rm -q "$f"
REMOVED=true
fi
done
if [ "$REMOVED" = true ]; then
git commit -q -m "chore: strip upstream CI/CD workflows not needed in this fork"
fi
- name: Push merged main back to fork
if: steps.sync.outputs.changed == 'true'
run: git push origin HEAD:main
- name: Set up Node
if: steps.sync.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
if: steps.sync.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
run: npm ci
- name: Build frontend
if: steps.sync.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
# Те же build-args, что использует официальный образ (см. docker.yml) —
# чтобы поведение совпадало с тем, что уже стоит на VPS.
run: npm run build:docker
env:
VITE_API_URL: /api
VITE_TELEGRAM_BOT_USERNAME: ''
VITE_APP_NAME: Cabinet
VITE_APP_LOGO: V
- name: Package dist
if: steps.sync.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
run: |
cd dist
tar -czf ../cabinet-dist.tar.gz .
- name: Publish release
id: publish
if: steps.sync.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ github.token }}
run: |
# Тег как в апстриме (v1.63.0 и т.п.) вместо build-<timestamp> — меньше
# путаницы при сверке с апстримной версией. Если тег уже существует
# (повторный ручной запуск без нового апстримного коммита) — пересоздаём.
VERSION=$(node -p "require('./package.json').version")
TAG="v${VERSION}"
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
gh release delete "$TAG" --repo "$GITHUB_REPOSITORY" --yes --cleanup-tag
fi
gh release create "$TAG" cabinet-dist.tar.gz \
--repo "$GITHUB_REPOSITORY" \
--title "$TAG" \
--notes "Синхронизировано с апстримом (v${VERSION}) + локальный патч (скрыт блок «Дополнительные опции»)." \
--latest
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Notify Telegram on new release
# TG_BOT_TOKEN/TG_CHAT_ID задаются в Settings → Secrets and variables →
# Actions, значения сюда не попадают.
if: success() && (steps.sync.outputs.changed == 'true' || github.event_name == 'workflow_dispatch')
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
run: |
curl -s -X POST "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage" \
-d chat_id="${TG_CHAT_ID}" \
-d text="✅ Новая сборка кабинета готова: ${{ steps.publish.outputs.tag }} — https://github.com/${GITHUB_REPOSITORY}/releases/tag/${{ steps.publish.outputs.tag }}" \
> /dev/null
- name: Notify Telegram on failure
# Срабатывает, если упал любой предыдущий шаг (в первую очередь —
# конфликт при merge апстрима).
if: failure()
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
run: |
curl -s -X POST "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage" \
-d chat_id="${TG_CHAT_ID}" \
-d text="⚠️ sync-and-build упал: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
> /dev/null