fix: add twine password using github secrets #9
This file contains 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 | |
on: push | |
permissions: | |
contents: write | |
jobs: | |
build-extension: | |
runs-on: ubuntu-24.04 | |
env: | |
VERSION: "" | |
SHORT_COMMIT: "" | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Install package | |
run: pip install . | |
- name: Extract commit metadata | |
run: | | |
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
echo "SHORT_COMMIT=$(echo ${GITHUB_SHA} | cut -c1-6)" >> $GITHUB_ENV | |
- name: Build | |
run: | | |
pip install build | |
python3 -m build | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: build-artifacts-${{ env.SHORT_COMMIT }} | |
path: dist/ | |
retention-days: 7 | |
- name: Upload to PYPI | |
if: startsWith(github.ref, 'refs/tags/') | |
env: | |
TWINE_USERNAME: __token__ # PyPI uses this username for API tokens | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: | | |
pip install twine | |
python3 -m twine upload dist/* | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v2 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
tag_name: ${{ env.VERSION }} | |
files: dist/* | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |