diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..64f0f4fc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,72 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version_type: + description: 'Version type' + required: true + default: 'patch' + type: choice + options: + - patch + - minor + - major + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + # 1. Клонируем репозиторий + - name: Checkout code + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + # 2. Настраиваем Node.js + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: '12' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Bump version + id: bump + run: | + npm version ${{ github.event.inputs.version_type }} --no-git-tag-version + echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + + - name: Update loader.js + run: node scripts/update-loader-version.js + + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v5 + with: + commit-message: Release ${{ steps.bump.outputs.version }} + title: Release ${{ steps.bump.outputs.version }} + branch: release-${{ steps.bump.outputs.version }} + base: master + body: | + ## Release ${{ steps.bump.outputs.version }} + + **Что изменилось:** + - Обновлен `package.json` + - Обновлен `app/loader.js` + - Обновлен `package-lock.json` + + **Проверка:** + - [ ] Локальный запуск (`npm run start`) + - [ ] Проверка на staging (после мержа) + + Closes #issue_number # (если есть) + labels: | + release + automated-pr \ No newline at end of file diff --git a/scripts/update-loader-version.js b/scripts/update-loader-version.js new file mode 100644 index 00000000..b52d718e --- /dev/null +++ b/scripts/update-loader-version.js @@ -0,0 +1,21 @@ +const fs = require('fs'); +const path = require('path'); + +// Читаем новую версию из package.json (который мы только что обновили) +const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); +const newVersion = pkg.version; + +const loaderPath = path.join(__dirname, '../app/loader.js'); + +let content = fs.readFileSync(loaderPath, 'utf8'); + +const regex = /var version = '.*?'/; + +if (regex.test(content)) { + content = content.replace(regex, `var version = 'v${newVersion}'`); + fs.writeFileSync(loaderPath, content); + console.log(`✅ Версия в loader.js обновлена на v${newVersion}`); +} else { + console.error('❌ Не удалось найти версию в app/loader.js. Проверьте регулярное выражение в скрипте.'); + process.exit(1); +} \ No newline at end of file