|
| 1 | +name: publish-to-test-pypi |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + name: Build distribution |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout repository |
| 14 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 |
| 15 | + |
| 16 | + - name: Set up Python |
| 17 | + uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c |
| 18 | + with: |
| 19 | + python-version: "3.x" |
| 20 | + |
| 21 | + - name: Install uv |
| 22 | + uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2 |
| 23 | + |
| 24 | + - name: Build distributions with uv |
| 25 | + run: uv build |
| 26 | + |
| 27 | + - name: Rename distributions with build number |
| 28 | + run: | |
| 29 | + BUILD_NUMBER=${GITHUB_RUN_NUMBER} |
| 30 | +
|
| 31 | + for file in dist/*.whl; do |
| 32 | + base=$(basename "$file") |
| 33 | +
|
| 34 | + new=$(echo "$base" | sed "s/\(-py[0-9]\)/-${BUILD_NUMBER}\1/") |
| 35 | + |
| 36 | + mv "dist/$base" "dist/$new" |
| 37 | + echo "Renamed $base → $new" |
| 38 | + done |
| 39 | +
|
| 40 | + - name: Validate metadata |
| 41 | + run: | |
| 42 | + uv run twine check dist/* |
| 43 | +
|
| 44 | + - name: Test import |
| 45 | + run: python -c "import em511" |
| 46 | + |
| 47 | + - name: Run tests |
| 48 | + run: | |
| 49 | + uv pip install pytest |
| 50 | + pytest |
| 51 | +
|
| 52 | + - name: Upload distributions as artifact |
| 53 | + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 |
| 54 | + with: |
| 55 | + name: dist-files |
| 56 | + path: dist/ |
| 57 | + |
| 58 | + publish-to-test-pypi: |
| 59 | + name: Publish Python distribution to TestPyPI |
| 60 | + needs: [build] |
| 61 | + runs-on: ubuntu-latest |
| 62 | + |
| 63 | + environment: |
| 64 | + name: testpypi |
| 65 | + url: https://test.pypi.org/p/python-em511 |
| 66 | + |
| 67 | + permissions: |
| 68 | + id-token: write |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: Download all build artifacts |
| 72 | + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 |
| 73 | + with: |
| 74 | + name: dist-files |
| 75 | + path: dist/ |
| 76 | + |
| 77 | + - name: Publish distribution to TestPyPI |
| 78 | + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e |
| 79 | + with: |
| 80 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments