Skip to content

Commit

Permalink
ci: Use pypa/gh-action-pypi-publish and trusted publishing
Browse files Browse the repository at this point in the history
Steps needed to make this work:
1. GitHub: Create environment (only the name is necessary):
   https://github.com/JonathonReinhart/staticx/settings/environments/
2. PyPI: Add Trusted Publisher:
   https://test.pypi.org/manage/project/staticx/settings/publishing/
  • Loading branch information
JonathonReinhart committed Jul 10, 2023
1 parent b372c31 commit 79a7139
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions .github/workflows/publish-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ on:
#branches:
# - main

# TODO: De-duplicate with build-test.yml
# TODO: De-duplicate with python-publish-release.yml

jobs:
deploy:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -27,7 +28,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install setuptools wheel
sudo apt-get update
sudo apt-get install -y musl-tools scons
Expand All @@ -38,8 +39,33 @@ jobs:
CI_VERSION_BUILD_NUMBER: ${{ github.run_id }}
run: python setup.py sdist bdist_wheel

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: python-dist
path: dist/


pypi-publish:
name: Upload release to Test PyPI
runs-on: ubuntu-latest
environment:
name: TestPyPI
url: https://test.pypi.org/project/staticx/
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: python-dist
path: dist/

- name: Display downloaded files
run: ls -R

- name: Publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_TEST_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_TEST_PASSWORD }}
run: twine upload --repository-url https://test.pypi.org/legacy/ dist/*
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
repository-url: https://test.pypi.org/legacy/

0 comments on commit 79a7139

Please sign in to comment.