diff options
| author | 2025-12-31 17:45:58 +0800 | |
|---|---|---|
| committer | 2025-12-31 17:45:58 +0800 | |
| commit | 7b15d1470addfe6f7e7079c9f52c1ed7ded1484d (patch) | |
| tree | 2d11d28c8914d03ef7ae6dcfbc02c7fad461c743 | |
| parent | 14ba21c109916a9e2f119075b82deca8a81fa573 (diff) | |
| download | base-model-7b15d1470addfe6f7e7079c9f52c1ed7ded1484d.tar.gz base-model-7b15d1470addfe6f7e7079c9f52c1ed7ded1484d.zip | |
feat: add workflow to publish to TestPyPI on main branch push
| -rw-r--r-- | .github/workflows/publish.yml | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e3463b0..599798d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,8 +2,12 @@ name: Publish to PyPI & GitHub Release on: push: + # Tag 推送:发布到正式 PyPI tags: - "v*.*.*" + # Push 到 main 分支:发布到 TestPyPI + branches: + - main workflow_dispatch: inputs: tag_name: @@ -80,6 +84,53 @@ jobs: name: model-zip path: model.zip + publish-testpypi: + name: Publish to TestPyPI + needs: build + runs-on: ubuntu-latest + # Push 到 main 分支(非 tag)时发布到 TestPyPI + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + + environment: + name: test-pypi + url: https://test.pypi.org/project/${{ github.sha }}/ + + permissions: + id-token: write + + 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 + + - name: Publish to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + publish-pypi: name: Publish to PyPI needs: build |
