|
| 1 | +name: Release to pypi |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version to use. Leave default to use the current version' |
| 8 | + required: true |
| 9 | + default: '~~version~~' |
| 10 | + |
| 11 | + |
| 12 | +env: |
| 13 | + # comment TWINE_REPOSITORY_URL to use the real pypi. NOTE: change also the secret used in TWINE_PASSWORD |
| 14 | + # TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/ |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + name: Release |
| 19 | + if: github.actor == 'CaselIT' || github.actor == 'zzzeek' |
| 20 | + runs-on: "ubuntu-latest" |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout repo |
| 24 | + uses: actions/checkout@v2 |
| 25 | + |
| 26 | + - name: Set up python |
| 27 | + uses: actions/setup-python@v2 |
| 28 | + with: |
| 29 | + python-version: "3.9" |
| 30 | + |
| 31 | + - name: Set version |
| 32 | + # A specific version was set in the action trigger. |
| 33 | + # Change the version in setup.cfg to that version |
| 34 | + if: ${{ github.event.inputs.version != '~~version~~' }} |
| 35 | + run: | |
| 36 | + python .github/workflows/scripts/update_version.py --set-version ${{ github.event.inputs.version }} |
| 37 | +
|
| 38 | + - name: Commit version change |
| 39 | + # If the setup.cfg version was changed commit it. |
| 40 | + if: ${{ github.event.inputs.version != '~~version~~' }} |
| 41 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 42 | + with: |
| 43 | + commit_message: Version ${{ github.event.inputs.version }} |
| 44 | + file_pattern: setup.cfg |
| 45 | + |
| 46 | + - name: Get version |
| 47 | + # Get current version |
| 48 | + id: get-version |
| 49 | + run: | |
| 50 | + version=`grep 'version =' setup.cfg | awk '{print $NF}'` |
| 51 | + echo $version |
| 52 | + echo "::set-output name=version::$version" |
| 53 | +
|
| 54 | + - name: Create distribution |
| 55 | + # Create wheel and sdist |
| 56 | + run: | |
| 57 | + python -m pip install --upgrade pip |
| 58 | + pip --version |
| 59 | + pip install build |
| 60 | + pip list |
| 61 | + python -m build --sdist --wheel . |
| 62 | +
|
| 63 | + - name: Create release |
| 64 | + # Create github tag and release and upload the distribution wheels and sdist |
| 65 | + uses: softprops/action-gh-release@v1 |
| 66 | + with: |
| 67 | + body: Release ${{ steps.get-version.outputs.version }} |
| 68 | + files: dist/* |
| 69 | + name: 'v${{ steps.get-version.outputs.version }}' |
| 70 | + tag_name: v${{ steps.get-version.outputs.version }} |
| 71 | + env: |
| 72 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + |
| 74 | + - name: Next version |
| 75 | + # Update the version to the next version |
| 76 | + run: | |
| 77 | + python .github/workflows/scripts/update_version.py --update-version |
| 78 | +
|
| 79 | + - name: Get version |
| 80 | + # Get new current version |
| 81 | + id: get-new-version |
| 82 | + run: | |
| 83 | + version=`grep 'version =' setup.cfg | awk '{print $NF}'` |
| 84 | + echo $version |
| 85 | + echo "::set-output name=version::$version" |
| 86 | +
|
| 87 | + - name: Commit next version update |
| 88 | + # Commit new current version |
| 89 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 90 | + with: |
| 91 | + commit_message: Start work on ${{ steps.get-new-version.outputs.version }} |
| 92 | + file_pattern: setup.cfg |
| 93 | + |
| 94 | + - name: Publish distribution |
| 95 | + # Publish to pypi |
| 96 | + env: |
| 97 | + TWINE_USERNAME: __token__ |
| 98 | + # replace TWINE_PASSWORD with token for real pypi |
| 99 | + # TWINE_PASSWORD: ${{ secrets.test_pypi_token }} |
| 100 | + TWINE_PASSWORD: ${{ secrets.pypi_token }} |
| 101 | + run: | |
| 102 | + pip install -U twine |
| 103 | + twine upload --skip-existing dist/* |
0 commit comments