Publish #25
Workflow file for this run
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: Publish | |
on: | |
workflow_dispatch: | |
inputs: | |
targetenv: | |
description: 'Target Environment' | |
required: true | |
default: 'testpypi' | |
type: choice | |
options: | |
- testpypi | |
- pypi | |
permissions: | |
contents: write | |
jobs: | |
overview: | |
name: Overview | |
runs-on: ubuntu-latest | |
steps: | |
- name: Job Summary | |
run: | | |
if [[ "${{ github.ref_name }}" != "main" && "${{ inputs.targetenv || 'testpypi' }}" == "pypi" ]] | |
then | |
{ | |
echo "::error::Publishing to PyPI is only allowed from the main branch"; | |
exit 1; | |
} | |
fi; | |
echo "### Job Summary" >> $GITHUB_STEP_SUMMARY | |
echo "Publish to ${{ inputs.targetenv || 'testpypi' }} environment from ${{ github.ref_name }} branch." >> $GITHUB_STEP_SUMMARY | |
publish: | |
name: Publish | |
runs-on: windows-2022 | |
needs: overview | |
environment: ${{ inputs.targetenv || 'testpypi' }} | |
env: | |
TWINE_USERNAME: '__token__' | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.9 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.9" | |
- name: Install build tools | |
run: | | |
python -m pip install --upgrade pip | |
pip install build~=1.2.2 twine~=5.1.1 | |
- name: Build | |
run: | | |
python -m build --wheel | |
- name: Publish distribution | |
run: | | |
twine upload --repository-url ${{ vars.PYPI_API_ENDPOINT }} dist/* | |
- name: Tag commit | |
id: tag_commit | |
if: ${{ (github.ref_name == 'main') || ((inputs.targetenv || 'testpypi') == 'pypi') }} | |
run: | | |
pip install --no-index --no-deps --find-links=dist/ pysweepme | |
$PysweepmeVersion = python -c "import importlib.metadata; print(importlib.metadata.version('pysweepme'))" | |
if ( -not (Get-ChildItem -Path dist -Filter "*${PysweepmeVersion}*.whl")) | |
{ | |
Throw "Inspected version $PysweepmeVersion could not be found in any wheels in the dist folder." | |
} | |
$TagName = "v${PysweepmeVersion}" | |
git tag $TagName | |
git push origin $TagName | |
"PysweepmeVersion=${PysweepmeVersion}" | Out-File -FilePath $env:GITHUB_OUTPUT -Append | |
"TagName=${TagName}" | Out-File -FilePath $env:GITHUB_OUTPUT -Append | |
shell: pwsh | |
- name: Create github release | |
if: ${{ (github.ref_name == 'main') || ((inputs.targetenv || 'testpypi') == 'pypi') }} | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "dist/*" | |
generateReleaseNotes: true | |
makeLatest: true | |
name: ${{ format('pysweepme {0}', steps.tag_commit.outputs.PysweepmeVersion) }} | |
tag: ${{ steps.tag_commit.outputs.TagName }} |