Bunchee
Back to Blog

Automated Release Workflow สำหรับ Frappe App ด้วย standard-version

เรียนรู้วิธีสร้าง Automated Release Workflow สำหรับ Frappe App รวมถึง Version Bump, CHANGELOG Generation, Git Tags และ GitHub Release

Automated Release Workflow สำหรับ Frappe App ด้วย standard-version

การ Release Frappe App แบบ Manual นั้นใช้เวลาและมีโอกาสผิดพลาด บทความนี้จะแนะนำวิธีสร้าง Automated Release Workflow ที่ช่วยให้การ Bump Version, Generate CHANGELOG, และ Create GitHub Release เป็นเรื่องง่าย

สิ่งที่ Workflow ทำ

  1. Bump Version - เพิ่ม Version ตาม Semantic Versioning
  2. Update CHANGELOG.md - Generate จาก Conventional Commits
  3. Sync Version Files - Update ทุกไฟล์ที่มี Version
  4. Create Git Tag - Tag เวอร์ชันใหม่
  5. Push to Remote - Push พร้อม Tags
  6. Create GitHub Release - พร้อม Release Notes

Version Files ที่ต้อง Update

  1. Python: your_app/__init__.py - __version__ = "x.y.z"
  2. Frontend: frontend/package.json - "version": "x.y.z"
  3. Root: package.json - "version": "x.y.z"
  4. CHANGELOG: CHANGELOG.md - Auto-generated

Prerequisites

ติดตั้ง standard-version

cd apps/your_app
yarn add -D standard-version
# หรือ
npm install --save-dev standard-version

ตั้งค่า package.json

{
  "name": "your_app",
  "version": "1.0.0",
  "devDependencies": {
    "standard-version": "^9.5.0"
  },
  "scripts": {
    "release": "standard-version",
    "release:patch": "standard-version --release-as patch",
    "release:minor": "standard-version --release-as minor",
    "release:major": "standard-version --release-as major"
  }
}

ตั้งค่า .versionrc.js (Optional)

สำหรับ Sync Version ไปยังหลายไฟล์:

// .versionrc.js
module.exports = {
  bumpFiles: [
    {
      filename: "package.json",
      type: "json",
    },
    {
      filename: "frontend/package.json",
      type: "json",
    },
    {
      filename: "your_app/__init__.py",
      updater: require.resolve("./scripts/python-version-updater.js"),
    },
  ],
  tagPrefix: "v",
  header: "# Changelog\n\nAll notable changes to this project will be documented in this file.\n",
  types: [
    { type: "feat", section: "✨ Features" },
    { type: "fix", section: "🐛 Bug Fixes" },
    { type: "chore", section: "🔧 Maintenance" },
    { type: "docs", section: "📚 Documentation" },
    { type: "style", section: "💄 Styles" },
    { type: "refactor", section: "♻️ Refactoring" },
    { type: "perf", section: "⚡ Performance" },
    { type: "test", section: "🧪 Tests" },
    { type: "ci", section: "👷 CI/CD" },
  ],
};

สร้าง Python Version Updater

// scripts/python-version-updater.js
module.exports.readVersion = function (contents) {
  const match = contents.match(/__version__\s*=\s*["'](.+)["']/);
  return match ? match[1] : null;
};

module.exports.writeVersion = function (contents, version) {
  return contents.replace(
    /__version__\s*=\s*["'].+["']/,
    `__version__ = "${version}"`
  );
};

Conventional Commits

ใช้ Format นี้สำหรับ Commit Messages:

| Prefix | CHANGELOG Section | ตัวอย่าง | |--------|-------------------|----------| | feat: | ✨ Features | feat: add dark mode toggle | | fix: | 🐛 Bug Fixes | fix: resolve login timeout | | docs: | 📚 Documentation | docs: update API reference | | chore: | 🔧 Maintenance | chore: update dependencies | | ci: | 👷 CI/CD | ci: add GitHub Actions workflow | | refactor: | ♻️ Refactoring | refactor: simplify auth logic | | perf: | ⚡ Performance | perf: optimize database queries | | test: | 🧪 Tests | test: add unit tests for utils |

Release Workflow

Step 1: Stage และ Commit Changes

git add --all
git commit -m "feat: add new dashboard feature"

Step 2: Run Release Script

# Patch Release (1.0.0 → 1.0.1)
yarn release:patch

# Minor Release (1.0.0 → 1.1.0)
yarn release:minor

# Major Release (1.0.0 → 2.0.0)
yarn release:major

standard-version จะ:

  • Bump Version ใน package.json
  • Update CHANGELOG.md จาก Commits
  • Create Commit: chore(release): x.y.z
  • Create Tag: vx.y.z

Step 3: Verify Versions

ตรวจสอบว่าทุกไฟล์ถูก Update:

# Check Python version
grep "__version__" your_app/__init__.py

# Check package.json
cat package.json | grep version

# Check frontend/package.json
cat frontend/package.json | grep version

Step 4: Push to Remote

git push origin develop --follow-tags

สำคัญ: ใช้ --follow-tags เพื่อ Push Tag ที่สร้างโดย standard-version

Step 5: Merge to Main (Optional)

git checkout main
git pull origin main
git merge develop --no-edit
git push origin main
git checkout develop

หรือใช้ GitHub Actions Auto-merge Workflow

Step 6: Create GitHub Release

gh release create v1.5.0 \
  --target main \
  --title "v1.5.0" \
  --generate-notes

หรือใช้ Notes จาก CHANGELOG:

# Extract latest release notes
NOTES=$(sed -n '/^## \[1.5.0\]/,/^## \[/p' CHANGELOG.md | head -n -1)

gh release create v1.5.0 \
  --target main \
  --title "v1.5.0" \
  --notes "$NOTES"

ตัวอย่าง CHANGELOG.md ที่ Generate

# Changelog

All notable changes to this project will be documented in this file.

## [1.5.0](https://github.com/username/your_app/compare/v1.4.0...v1.5.0) (2026-02-03)

### ✨ Features

* add dark mode toggle ([abc1234](https://github.com/username/your_app/commit/abc1234))
* implement user preferences panel ([def5678](https://github.com/username/your_app/commit/def5678))

### 🐛 Bug Fixes

* resolve login timeout issue ([ghi9012](https://github.com/username/your_app/commit/ghi9012))

### 🔧 Maintenance

* update dependencies to latest versions ([jkl3456](https://github.com/username/your_app/commit/jkl3456))

GitHub Actions Workflow (Optional)

สร้างไฟล์ .github/workflows/release.yml:

name: Release

on:
  push:
    tags:
      - 'v*'

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v1
        with:
          generate_release_notes: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Auto-merge Workflow (Optional)

# .github/workflows/auto-merge.yml
name: Auto-merge to Main

on:
  push:
    branches:
      - develop

jobs:
  merge:
    runs-on: ubuntu-latest
    if: contains(github.event.head_commit.message, 'chore(release)')
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Merge to main
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
          git checkout main
          git merge origin/develop --no-edit
          git push origin main

Safety Features

Workflow ควรมี Safety Checks:

  • Clean Working Tree - ตรวจสอบก่อน Release
  • Branch Existence - ตรวจสอบ Branch มีอยู่
  • Remote Connectivity - ตรวจสอบเชื่อมต่อ Remote ได้
  • Version Format - ตรวจสอบ Semver ถูกต้อง
  • Tag Existence - ตรวจสอบก่อนสร้าง Release

Summary Output

หลัง Release เสร็จ ควรแสดง Summary:

🎉 Release 1.5.0 completed successfully!

📱 App: your_app
📦 Version: 1.4.0 → 1.5.0
📄 Updated files:
   - your_app/__init__.py
   - frontend/package.json
   - package.json
   - CHANGELOG.md ✨
🔀 Branch: develop → main
🏷️ Tag: v1.5.0
🔗 Release: https://github.com/username/your_app/releases/tag/v1.5.0

สรุป

Automated Release Workflow ช่วยให้:

  • ลดเวลาในการ Release
  • ลดโอกาสผิดพลาด
  • CHANGELOG Generate อัตโนมัติ
  • Version Sync ทุกไฟล์
  • GitHub Release พร้อม Notes

สิ่งที่ต้องมี:

  1. standard-version Package
  2. Conventional Commit Format
  3. package.json Scripts
  4. (Optional) .versionrc.js สำหรับ Multi-file Sync

เอกสารอ้างอิง