diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 6d27b4f..6e6c3d2 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[skip ci]')" outputs: - new_tag: ${{ steps.tag.outputs.new_tag }} + version: ${{ steps.version.outputs.version }} steps: - name: Checkout uses: actions/checkout@v4 @@ -21,44 +21,40 @@ jobs: with: node-version: 24 - - name: Генерация ARCHITECTURE.md + - name: Версия из package.json + id: version + run: | + VERSION="v$(node -p "require('./package.json').version")" + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Версия: $VERSION" + + - name: Генерация docs run: | npm ci npm run docs - - name: Автоматический тег (semver patch) - id: tag + - name: Коммит generated/ run: | - LAST_TAG=$(git tag -l 'v*' --sort=-v:refname | head -1) - if [ -z "$LAST_TAG" ]; then - NEW_TAG="v0.1.0" - else - MAJOR=$(echo "$LAST_TAG" | cut -d. -f1) - MINOR=$(echo "$LAST_TAG" | cut -d. -f2) - PATCH=$(echo "$LAST_TAG" | cut -d. -f3) - NEW_TAG="${MAJOR}.${MINOR}.$((PATCH + 1))" - fi - echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT - echo "Новый тег: $NEW_TAG" - - - name: Подставить тег и коммит - run: | - NEW_TAG=${{ steps.tag.outputs.new_tag }} - sed -i "s|raw/branch/main|raw/tag/${NEW_TAG}|g" README_RU.md git config user.name "CI Bot" git config user.email "ci@gromlab.ru" git add generated/ README_RU.md if git diff --cached --quiet; then - echo "Нет изменений, пропуск коммита" + echo "Нет изменений, пропуск" else - git commit -m "docs: обновить generated (${NEW_TAG}) [skip ci]" + git commit -m "docs: обновить generated (${{ steps.version.outputs.version }}) [skip ci]" git push origin main fi - git tag "$NEW_TAG" - git push origin "$NEW_TAG" - echo "Создан тег: $NEW_TAG" - + - name: Создать тег + run: | + VERSION=${{ steps.version.outputs.version }} + if git tag -l "$VERSION" | grep -q "$VERSION"; then + echo "Тег $VERSION уже существует, пропуск" + else + git tag "$VERSION" + git push origin "$VERSION" + echo "Создан тег: $VERSION" + fi docker: runs-on: ubuntu-latest @@ -96,7 +92,7 @@ jobs: type=ref,event=branch type=sha,prefix= type=raw,value=latest,enable={{is_default_branch}} - type=raw,value=${{ needs.docs.outputs.new_tag }} + type=raw,value=${{ needs.docs.outputs.version }} - name: Build and push uses: docker/build-push-action@v5 @@ -108,7 +104,7 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | - VERSION_TAG=${{ needs.docs.outputs.new_tag }} + VERSION_TAG=${{ needs.docs.outputs.version }} provenance: false sbom: false @@ -137,31 +133,23 @@ jobs: IMAGE="${{ env.REGISTRY_IMAGE }}:latest" CONTAINER="slm-design" - # Логин в реестр echo '${{ secrets.CR_TOKEN }}' | docker login ${{ env.DOCKER_REGISTRY }} -u '${{ secrets.CR_USER }}' --password-stdin - # Сохранить ID текущего образа до pull OLD_IMAGE_ID=$(docker images -q "$IMAGE" 2>/dev/null || true) - - # Скачать новый образ docker pull "$IMAGE" - # Перезапустить контейнер docker stop "$CONTAINER" 2>/dev/null || true docker rm "$CONTAINER" 2>/dev/null || true docker run -d --name "$CONTAINER" --network web --restart unless-stopped "$IMAGE" - # Удалить старый образ если он отличается от нового NEW_IMAGE_ID=$(docker images -q "$IMAGE") if [ -n "$OLD_IMAGE_ID" ] && [ "$OLD_IMAGE_ID" != "$NEW_IMAGE_ID" ]; then docker rmi "$OLD_IMAGE_ID" 2>/dev/null || true fi - # Очистка docker image prune -af --filter "label=org.opencontainers.image.title=$CONTAINER" docker image prune -f docker builder prune -f 2>/dev/null || true - # Статус docker ps --filter "name=$CONTAINER" SCRIPT diff --git a/README_RU.md b/README_RU.md index 5387170..5e590a5 100644 --- a/README_RU.md +++ b/README_RU.md @@ -2,7 +2,7 @@ Scoped Layered Module Design — модульная архитектура фронтенд-приложений. Код организован по слоям ответственности, а модуль содержит всё, что ему нужно: компоненты, хуки, сторы, типы, стили. -🤖 Для AI-ассистентов доступен единый файл правил:
[https://gromlab.ru/gromov/slm-design/raw/branch/main/generated/ru/ARCHITECTURE.md](https://gromlab.ru/gromov/slm-design/raw/branch/main/generated/ru/ARCHITECTURE.md) +🤖 Для AI-ассистентов доступен единый файл правил:
[https://gromlab.ru/gromov/slm-design/raw/tag/v0.1.0/generated/ru/ARCHITECTURE.md](https://gromlab.ru/gromov/slm-design/raw/tag/v0.1.0/generated/ru/ARCHITECTURE.md) ## Преимущества diff --git a/concat-md.js b/concat-md.js index 962d06a..91ec114 100644 --- a/concat-md.js +++ b/concat-md.js @@ -73,6 +73,14 @@ const buildRules = (lang) => { buildRules("ru"); buildRules("en"); +// Версия из package.json +const pkg = JSON.parse(fs.readFileSync("./package.json", "utf8")); +const version = `v${pkg.version}`; + +// Подставить версию в ссылки +const replaceVersion = (content) => + content.replace(/raw\/branch\/main/g, `raw/tag/${version}`); + // Генерируем README из index.md const buildReadme = (lang, outFile) => { const indexPath = `./docs/${lang}/index.md`; @@ -82,9 +90,9 @@ const buildReadme = (lang, outFile) => { return; } - const content = stripFrontmatter(fs.readFileSync(indexPath, "utf8")); + const content = replaceVersion(stripFrontmatter(fs.readFileSync(indexPath, "utf8"))); fs.writeFileSync(outFile, content, "utf8"); - console.log(`${outFile} создан из ${indexPath}`); + console.log(`${outFile} создан из ${indexPath} (${version})`); }; buildReadme("ru", "./README_RU.md"); diff --git a/package.json b/package.json index c096bc9..76ae93c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "slm-design", "private": true, "type": "module", - "version": "0.0.0", + "version": "0.1.0", "scripts": { "docs": "node ./concat-md.js", "dev": "vitepress dev .",