diff --git a/.github/workflows/publish-to-test-pypi.yaml b/.github/workflows/publish-to-test-pypi.yaml new file mode 100644 index 0000000..076eac1 --- /dev/null +++ b/.github/workflows/publish-to-test-pypi.yaml @@ -0,0 +1,77 @@ +name: publish-to-test-pypi + +on: + push: + branches: ["test_pypi"] + +jobs: + build: + name: Build distribution + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + + - name: Set up Python + uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c + with: + python-version: "3.x" + + - name: Install uv + uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2 + + - name: Build distributions with uv + run: uv build + + - name: Install twine + run: uv tool install twine + + - name: Rename distributions with build number + run: | + BUILD_NUMBER=${GITHUB_RUN_NUMBER} + for file in dist/*.whl; do + base=$(basename "$file") + new=$(echo "$base" | sed "s/\(-py[0-9]\)/-${BUILD_NUMBER}\1/") + + mv "dist/$base" "dist/$new" + echo "Renamed $base → $new" + done + - name: Validate metadata + run: | + uv run twine check dist/* + - name: Install built wheel + run uv pip install dist/*.whl + + - name: Test import + run: python -c "import dcm230" + + - name: Upload distributions as artifact + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + with: + name: dist-files + path: dist/ + + publish-to-test-pypi: + name: Publish Python distribution to TestPyPI + needs: [build] + runs-on: ubuntu-latest + + environment: + name: testpypi + url: https://test.pypi.org/p/python-dcm230 + + permissions: + id-token: write + + steps: + - name: Download all build artifacts + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 + with: + name: dist-files + path: dist/ + + - name: Publish distribution to TestPyPI + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e + with: + repository-url: https://test.pypi.org/legacy/