Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Release

on:
push:
tags:
- "v*.*.*"

concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false

jobs:
build:
name: Validate, test, and build
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Check out repository
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"

- name: Set up uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
enable-cache: true

- name: Validate release tag
shell: bash
run: |
set -euo pipefail

if [[ ! "$GITHUB_REF_NAME" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "Tag must use stable semantic version format: vMAJOR.MINOR.PATCH"
exit 1
fi

tag_version="${GITHUB_REF_NAME#v}"
project_version="$(
python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])"
)"
if [[ "$tag_version" != "$project_version" ]]; then
echo "Tag version $tag_version does not match pyproject.toml version $project_version"
exit 1
fi

git fetch origin main
tagged_commit="$(git rev-list -n 1 "$GITHUB_REF_NAME")"
if ! git merge-base --is-ancestor "$tagged_commit" origin/main; then
echo "Tagged commit $tagged_commit is not contained in origin/main"
exit 1
fi

- name: Install dependencies
run: uv sync --locked --extra dev

- name: Run tests
run: uv run pytest

- name: Build distributions
run: uv build

- name: Check distribution metadata
run: uvx twine check dist/*

- name: Smoke-test wheel installation
shell: bash
run: |
set -euo pipefail
uv venv .release-venv
uv pip install --python .release-venv/bin/python dist/*.whl
.release-venv/bin/python -c "import fp; print(fp.__file__)"

- name: Upload distributions
uses: actions/upload-artifact@v7
with:
name: python-distributions
path: dist/
if-no-files-found: error

publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/foundation-protocol/
permissions:
id-token: write

steps:
- name: Download distributions
uses: actions/download-artifact@v8
with:
name: python-distributions
path: dist/

- name: Publish distributions
uses: pypa/gh-action-pypi-publish@v1.14.0

release:
name: Create GitHub Release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Check out repository
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Download distributions
uses: actions/download-artifact@v8
with:
name: python-distributions
path: dist/

- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$GITHUB_REF_NAME" dist/* --generate-notes --verify-tag
8 changes: 7 additions & 1 deletion README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ https://github.com/user-attachments/assets/ceab2515-b8f2-47ec-8d7f-10452759c32a

## Instalación

Instalar como dependencia git:
Recomendado: instalar la versión estable desde PyPI:

```bash
pip install foundation-protocol
```

Los desarrolladores también pueden instalar el código fuente más reciente desde GitHub:

```bash
pip install "foundation-protocol @ git+https://github.com/FoundationAgents/foundation-protocol.git"
Expand Down
8 changes: 7 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ https://github.com/user-attachments/assets/ceab2515-b8f2-47ec-8d7f-10452759c32a

## インストール

git依存としてインストール:
推奨:PyPIから安定版をインストール:

```bash
pip install foundation-protocol
```

開発者はGitHubの最新ソースもインストールできます:

```bash
pip install "foundation-protocol @ git+https://github.com/FoundationAgents/foundation-protocol.git"
Expand Down
8 changes: 7 additions & 1 deletion README.ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ https://github.com/user-attachments/assets/ceab2515-b8f2-47ec-8d7f-10452759c32a

## 설치

git 의존성으로 설치:
권장: PyPI에서 안정 버전 설치:

```bash
pip install foundation-protocol
```

개발자는 GitHub의 최신 소스도 설치할 수 있습니다:

```bash
pip install "foundation-protocol @ git+https://github.com/FoundationAgents/foundation-protocol.git"
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ https://github.com/user-attachments/assets/ceab2515-b8f2-47ec-8d7f-10452759c32a

## Installation

Install as a git dependency:
Recommended: install the stable release from PyPI:

```bash
pip install foundation-protocol
```

Developers can install the latest source from GitHub:

```bash
pip install "foundation-protocol @ git+https://github.com/FoundationAgents/foundation-protocol.git"
Expand Down
8 changes: 7 additions & 1 deletion README.vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ https://github.com/user-attachments/assets/ceab2515-b8f2-47ec-8d7f-10452759c32a

## Cài đặt

Cài đặt dưới dạng phụ thuộc git:
Khuyến nghị: cài đặt bản ổn định từ PyPI:

```bash
pip install foundation-protocol
```

Nhà phát triển cũng có thể cài đặt mã nguồn mới nhất từ GitHub:

```bash
pip install "foundation-protocol @ git+https://github.com/FoundationAgents/foundation-protocol.git"
Expand Down
8 changes: 7 additions & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ https://github.com/user-attachments/assets/ceab2515-b8f2-47ec-8d7f-10452759c32a

## 安装

作为 git 依赖安装:
推荐:从 PyPI 安装稳定版本:

```bash
pip install foundation-protocol
```

开发者也可以安装 GitHub 上的最新源码:

```bash
pip install "foundation-protocol @ git+https://github.com/FoundationAgents/foundation-protocol.git"
Expand Down
48 changes: 35 additions & 13 deletions fp/utils/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,47 @@

from __future__ import annotations

import fcntl
import json
import os
from contextlib import contextmanager
from datetime import datetime
from pathlib import Path
from typing import Any

if os.name == "nt":
import msvcrt
else:
import fcntl

from loguru import logger
from pydantic import BaseModel, Field


@contextmanager
def _config_file_lock(lock_path: Path, *, exclusive: bool):
"""Lock the config lock file on Windows and POSIX systems."""
with lock_path.open("a+b") as lock_file:
if os.name == "nt":
lock_file.seek(0, os.SEEK_END)
if lock_file.tell() == 0:
lock_file.write(b"\0")
lock_file.flush()
lock_file.seek(0)
msvcrt.locking(lock_file.fileno(), msvcrt.LK_LOCK, 1)
try:
yield
finally:
lock_file.seek(0)
msvcrt.locking(lock_file.fileno(), msvcrt.LK_UNLCK, 1)
else:
operation = fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH
fcntl.flock(lock_file.fileno(), operation)
try:
yield
finally:
fcntl.flock(lock_file.fileno(), fcntl.LOCK_UN)


# ============================================================================
# 存储数据模型
# ============================================================================
Expand Down Expand Up @@ -339,12 +369,8 @@ def load_config(self) -> GlobalConfig:
# 使用文件锁保护并发读取
lock_path = config_path.parent / ".config.lock"
try:
with open(lock_path, "w") as lock_file:
fcntl.flock(lock_file.fileno(), fcntl.LOCK_SH)
try:
return self._read_json_model(config_path, GlobalConfig)
finally:
fcntl.flock(lock_file.fileno(), fcntl.LOCK_UN)
with _config_file_lock(lock_path, exclusive=False):
return self._read_json_model(config_path, GlobalConfig)
except Exception as e:
logger.error(f"Failed to parse config.json: {e}")
raise
Expand All @@ -356,12 +382,8 @@ def save_config(self, config: GlobalConfig) -> None:

# 使用文件锁保护并发写入
lock_path = config_path.parent / ".config.lock"
with open(lock_path, "w") as lock_file:
fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX)
try:
self._write_json_model(config_path, config)
finally:
fcntl.flock(lock_file.fileno(), fcntl.LOCK_UN)
with _config_file_lock(lock_path, exclusive=True):
self._write_json_model(config_path, config)

def _create_default_config(self) -> GlobalConfig:
"""创建默认配置文件"""
Expand Down
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel]
packages = ["fp"]

[tool.hatch.build.targets.sdist]
include = [
"/fp",
"/tests",
"/docs",
"/LICENSE",
"/README.md",
"/pyproject.toml",
"/mkdocs.yml",
]

[project]
name = "foundation-protocol"
version = "0.1.0"
Expand Down Expand Up @@ -32,6 +43,12 @@ dependencies = [
"pydantic>=2.11.0",
]

[project.urls]
Homepage = "https://github.com/FoundationAgents/foundation-protocol"
Documentation = "https://foundationagents.github.io/foundation-protocol/"
Issues = "https://github.com/FoundationAgents/foundation-protocol/issues"
Repository = "https://github.com/FoundationAgents/foundation-protocol"

[project.optional-dependencies]
dev = [
"pytest>=8.0.0",
Expand Down
13 changes: 13 additions & 0 deletions tests/utils/test_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Tests for cross-platform storage behavior."""

from fp.utils.storage import GlobalConfig, StorageManager


def test_config_roundtrip(tmp_path) -> None:
"""Save and load config on every supported operating system."""
storage = StorageManager(tmp_path)
config = GlobalConfig(default_host="host-1")

storage.save_config(config)

assert storage.load_config() == config
Loading