aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/.github/workflows
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2025-12-31 18:08:03 +0800
committerHsiangNianian <i@jyunko.cn>2025-12-31 18:08:03 +0800
commit9b4ec9c5fc256313e156c7d42b3104c711b15ecc (patch)
tree28323c07ce27f95c3d4ed1d46e53215a75623290 /.github/workflows
parent42fa9a49d378087f0a5e9127a84dccfb2bd21016 (diff)
downloadbase-model-9b4ec9c5fc256313e156c7d42b3104c711b15ecc.tar.gz
base-model-9b4ec9c5fc256313e156c7d42b3104c711b15ecc.zip
fix: update package name to use commit hash during TestPyPI publish
Diffstat (limited to '.github/workflows')
-rw-r--r--.github/workflows/publish.yml58
1 files changed, 11 insertions, 47 deletions
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 80d43bb..145705f 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -50,8 +50,19 @@ jobs:
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH
+ - name: Get commit hash
+ id: commit
+ run: |
+ COMMIT_HASH=$(git rev-parse HEAD)
+ echo "hash=${COMMIT_HASH}" >> $GITHUB_OUTPUT
+ echo "Commit hash: ${COMMIT_HASH}"
+
- name: Build with uv
run: |
+ # TestPyPI 发布时使用 commit hash 作为包名
+ if [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == "refs/heads/main" ]; then
+ sed -i "s/^name = \".*\"/name = \"${{ steps.commit.outputs.hash }}\"/" pyproject.toml
+ fi
uv sync
uv build
@@ -93,64 +104,17 @@ jobs:
url: https://test.pypi.org/p/${{ github.sha }}/
steps:
- - name: Checkout code
- uses: actions/checkout@v6
-
- - name: Get commit hash
- id: commit
- run: |
- COMMIT_HASH=$(git rev-parse HEAD)
- echo "hash=${COMMIT_HASH}" >> $GITHUB_OUTPUT
- echo "Commit hash: ${COMMIT_HASH}"
-
- name: Download dist
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- - name: Rename package with commit hash
- run: |
- COMMIT_HASH="${{ steps.commit.outputs.hash }}"
- cd dist
- for file in *; do
- # 重命名文件:base-model-trpgner-xxx -> {commit_hash}-xxx
- new_name=$(echo "$file" | sed "s/base_model_trpgner/${COMMIT_HASH}/g")
- mv "$file" "$new_name"
- done
- ls -la
-
- # 检查并修复 PKG-INFO 中的包名
- - name: Fix package metadata
- run: |
- COMMIT_HASH="${{ steps.commit.outputs.hash }}"
- cd dist
- # 修改 .tar.gz 中的 PKG-INFO
- for file in *.tar.gz; do
- tar -xzf "$file"
- # 获取解压后的目录名(第一个组件)
- dir=$(tar -tzf "$file" | head -1 | cut -d"/" -f1)
- (cd "$dir" && sed -i "s/^Name: base-model-trpgner/Name: ${COMMIT_HASH}/" PKG-INFO)
- tar -czf "$file" "${dir}/"
- rm -rf "$dir"
- done
- # 修改 .whl 中的 METADATA
- for file in *.whl; do
- unzip -q "$file"
- # 查找 dist-info 目录
- dist_dir=$(find . -maxdepth 1 -type d -name "*.dist-info")
- (cd "$dist_dir" && sed -i "s/^Name: base-model-trpgner/Name: ${COMMIT_HASH}/" METADATA)
- zip -qr "$file" "${dist_dir#./}"
- rm -rf "$dist_dir"
- done
- ls -la
-
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy
password: ${{ secrets.TEST_PYPI_TOKEN }}
- verbose: true
publish-pypi:
name: Publish to PyPI