CHG: refine codebase naming styles; reduce docsring complexity; add m… #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and publish python package | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to publish (e.g., 1.0.0). Defaults to pyproject.toml when empty.' | |
| required: false | |
| type: string | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Extract version from tag, input, or pyproject.toml | |
| id: get_version | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//') | |
| else | |
| VERSION=$(grep -E '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Publishing version: $VERSION" | |
| - name: Verify version matches pyproject.toml | |
| run: | | |
| PUBLISH_VERSION="${{ steps.get_version.outputs.version }}" | |
| FILE_VERSION=$(grep -E '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') | |
| if [ "$PUBLISH_VERSION" != "$FILE_VERSION" ]; then | |
| echo "Error: Version mismatch!" | |
| echo "Tag/Input version: $PUBLISH_VERSION" | |
| echo "pyproject.toml version: $FILE_VERSION" | |
| exit 1 | |
| fi | |
| echo "✓ Version verified: $PUBLISH_VERSION" | |
| - name: Install build tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| - name: Build package | |
| run: python -m build | |
| - name: Check package contents | |
| run: | | |
| echo "Built files:" | |
| ls -lh dist/ | |
| echo "" | |
| python -m twine check dist/* | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_TOKEN }} | |
| - name: Create GitHub Release | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ steps.get_version.outputs.version }} | |
| body: | | |
| ## Release ${{ steps.get_version.outputs.version }} | |
| Published to PyPI: https://pypi.org/project/da-stdk/${{ steps.get_version.outputs.version }}/ | |
| ### Installation | |
| ```bash | |
| pip install da-stdk==${{ steps.get_version.outputs.version }} | |
| ``` | |
| draft: false | |
| prerelease: false |