|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + - "[0-9]*" |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + id-token: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: "3.12" |
| 25 | + |
| 26 | + - name: Validate tag/version consistency |
| 27 | + shell: bash |
| 28 | + run: | |
| 29 | + set -euo pipefail |
| 30 | +
|
| 31 | + TAG_NAME="${GITHUB_REF_NAME}" |
| 32 | + TAG_VERSION="${TAG_NAME#v}" |
| 33 | +
|
| 34 | + PYPROJECT_VERSION=$(python - <<'PY' |
| 35 | + import tomllib |
| 36 | + from pathlib import Path |
| 37 | +
|
| 38 | + data = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8")) |
| 39 | + print(data["project"]["version"]) |
| 40 | + PY |
| 41 | + ) |
| 42 | +
|
| 43 | + CHANGELOG_VERSION=$(python - <<'PY' |
| 44 | + import re |
| 45 | + from pathlib import Path |
| 46 | +
|
| 47 | + changelog = Path("CHANGELOG.md").read_text(encoding="utf-8") |
| 48 | + match = re.search(r"^## \[([^\]]+)\]", changelog, re.MULTILINE) |
| 49 | + if not match: |
| 50 | + raise SystemExit("CHANGELOG.md에서 버전 섹션(## [x.y.z])을 찾지 못했습니다.") |
| 51 | + print(match.group(1).strip()) |
| 52 | + PY |
| 53 | + ) |
| 54 | +
|
| 55 | + echo "Tag version: ${TAG_VERSION}" |
| 56 | + echo "pyproject version: ${PYPROJECT_VERSION}" |
| 57 | + echo "changelog version: ${CHANGELOG_VERSION}" |
| 58 | +
|
| 59 | + if [[ "${TAG_VERSION}" != "${PYPROJECT_VERSION}" ]]; then |
| 60 | + echo "태그 버전(${TAG_VERSION})과 pyproject 버전(${PYPROJECT_VERSION})이 일치하지 않습니다." >&2 |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + if [[ "${TAG_VERSION}" != "${CHANGELOG_VERSION}" ]]; then |
| 65 | + echo "태그 버전(${TAG_VERSION})과 changelog 최신 버전(${CHANGELOG_VERSION})이 일치하지 않습니다." >&2 |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Extract latest changelog section for release notes |
| 70 | + run: | |
| 71 | + python - <<'PY' |
| 72 | + from pathlib import Path |
| 73 | +
|
| 74 | + lines = Path("CHANGELOG.md").read_text(encoding="utf-8").splitlines() |
| 75 | + start = next((i for i, line in enumerate(lines) if line.startswith("## [")), None) |
| 76 | + if start is None: |
| 77 | + raise SystemExit("CHANGELOG.md에서 릴리스 섹션을 찾지 못했습니다.") |
| 78 | +
|
| 79 | + end = next( |
| 80 | + (i for i in range(start + 1, len(lines)) if lines[i].startswith("## [")), |
| 81 | + len(lines), |
| 82 | + ) |
| 83 | +
|
| 84 | + section = "\n".join(lines[start:end]).strip() + "\n" |
| 85 | + Path("release_notes.md").write_text(section, encoding="utf-8") |
| 86 | + PY |
| 87 | +
|
| 88 | + - name: Build distributions (migrated from scripts/build-and-publish.sh) |
| 89 | + run: | |
| 90 | + python -m pip install --upgrade build twine |
| 91 | + rm -rf dist build |
| 92 | + python -m build |
| 93 | + twine check dist/* |
| 94 | +
|
| 95 | + - name: Publish package to PyPI |
| 96 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 97 | + |
| 98 | + - name: Create GitHub Release |
| 99 | + uses: softprops/action-gh-release@v2 |
| 100 | + with: |
| 101 | + body_path: release_notes.md |
| 102 | + files: dist/* |
0 commit comments