|
1 |
| -# This workflow will upload a Python Package using Poetry when a release is published |
2 |
| - |
3 |
| -name: Publish Python Package (PyPi) |
| 1 | +name: Release |
4 | 2 |
|
5 | 3 | on:
|
6 |
| - release: |
7 |
| - types: [ published ] |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
8 | 8 |
|
9 | 9 | jobs:
|
10 |
| - deploy: |
| 10 | + release: |
| 11 | + name: Release |
11 | 12 | runs-on: ubuntu-latest
|
12 |
| - |
13 | 13 | steps:
|
14 |
| - - uses: actions/checkout@v2 |
| 14 | + - name: Check out the repository |
| 15 | + uses: actions/checkout@v2.3.4 |
| 16 | + with: |
| 17 | + fetch-depth: 2 |
| 18 | + |
15 | 19 | - name: Set up Python
|
16 |
| - uses: actions/setup-python@v2 |
| 20 | + uses: actions/setup-python@v2.2.2 |
| 21 | + with: |
| 22 | + python-version: "3.9" |
| 23 | + |
| 24 | + - name: Upgrade pip |
| 25 | + run: | |
| 26 | + pip install --constraint=.github/workflows/constraints.txt pip |
| 27 | + pip --version |
| 28 | +
|
| 29 | + - name: Install Poetry |
| 30 | + run: | |
| 31 | + pip install --constraint=.github/workflows/constraints.txt poetry |
| 32 | + poetry --version |
| 33 | +
|
| 34 | + - name: Check if there is a parent commit |
| 35 | + id: check-parent-commit |
| 36 | + run: | |
| 37 | + echo "::set-output name=sha::$(git rev-parse --verify --quiet HEAD^)" |
| 38 | +
|
| 39 | + - name: Detect and tag new version |
| 40 | + id: check-version |
| 41 | + if: steps.check-parent-commit.outputs.sha |
| 42 | + uses: salsify/action-detect-and-tag-new-version@v2.0.1 |
17 | 43 | with:
|
18 |
| - python-version: '3.x' |
19 |
| - - name: Set up Poetry |
20 |
| - uses: Gr1N/setup-poetry@v4 |
21 |
| - - name: Bump Poetry version |
| 44 | + version-command: | |
| 45 | + bash -o pipefail -c "poetry version | awk '{ print \$2 }'" |
| 46 | +
|
| 47 | + - name: Bump version for developmental release |
| 48 | + if: "! steps.check-version.outputs.tag" |
| 49 | + run: | |
| 50 | + poetry version patch && |
| 51 | + version=$(poetry version | awk '{ print $2 }') && |
| 52 | + poetry version $version.dev.$(date +%s) |
| 53 | +
|
| 54 | + - name: Build package |
22 | 55 | run: |
|
23 |
| - tag=${{ github.event.release.tag_name }} |
24 |
| - version_number=${tag#?} |
25 |
| - poetry version $version_number |
26 |
| - - name: Commit changes |
27 |
| - uses: EndBug/add-and-commit@v4 |
| 56 | + poetry build --ansi |
| 57 | +
|
| 58 | + - name: Publish package on PyPI |
| 59 | + if: steps.check-version.outputs.tag |
| 60 | + uses: pypa/gh-action-pypi-publish@v1.4.2 |
| 61 | + with: |
| 62 | + user: __token__ |
| 63 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 64 | + |
| 65 | + - name: Publish the release notes |
| 66 | + uses: release-drafter/release-drafter@v5.15.0 |
28 | 67 | with:
|
29 |
| - message: "Bump version to ${{ github.event.release.tag_name }}" |
30 |
| - add: "pyproject.toml" |
31 |
| - ref: "main" |
| 68 | + publish: ${{ steps.check-version.outputs.tag != '' }} |
| 69 | + tag: ${{ steps.check-version.outputs.tag }} |
32 | 70 | env:
|
33 | 71 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
34 |
| - - name: Build and publish to PyPi |
35 |
| - env: |
36 |
| - POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }} |
37 |
| - run: | |
38 |
| - poetry publish --build |
|
0 commit comments