|
| 1 | +on: |
| 2 | + push: |
| 3 | + tags: |
| 4 | + - '*' |
| 5 | + |
| 6 | +name: Create & Publish Package |
| 7 | + |
| 8 | +jobs: |
| 9 | + publish: |
| 10 | + name: Create & Publish Package |
| 11 | + runs-on: 'ubuntu-latest' |
| 12 | + steps: |
| 13 | + - name: Checkout Source |
| 14 | + uses: actions/checkout@v2 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + |
| 18 | + - name: Setup Python |
| 19 | + uses: actions/setup-python@v2 |
| 20 | + with: |
| 21 | + python-version: '3.7' |
| 22 | + |
| 23 | + - name: Cache Poetry |
| 24 | + id: cache-poetry |
| 25 | + uses: actions/cache@v2 |
| 26 | + with: |
| 27 | + path: ~/.poetry |
| 28 | + key: poetry |
| 29 | + |
| 30 | + - name: Install Poetry |
| 31 | + if: steps.cache-poetry.outputs.cache-hit != 'true' |
| 32 | + run: | |
| 33 | + curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -O |
| 34 | + python install-poetry.py --preview |
| 35 | +
|
| 36 | + - name: Add Poetry to $PATH |
| 37 | + run: echo "$HOME/.poetry/bin" >> $GITHUB_PATH |
| 38 | + |
| 39 | + - name: Add versioning plugin |
| 40 | + run: poetry plugin add poetry-version-plugin |
| 41 | + |
| 42 | + - name: Poetry Version |
| 43 | + run: poetry --version |
| 44 | + |
| 45 | + - name: Add version to environment vars |
| 46 | + run: echo "MODULE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV |
| 47 | + |
| 48 | + - name: Check if source version is up-to-date |
| 49 | + run: | |
| 50 | + TAG=$(git describe HEAD --tags --abbrev=0) |
| 51 | + echo Current Tag: $TAG -- Current Module Version: $MODULE_VERSION |
| 52 | + if [[ "$TAG" != "$MODULE_VERSION" ]]; then exit 1; fi |
| 53 | +
|
| 54 | + - name: Check pyproject.toml validity |
| 55 | + run: poetry check --no-interaction |
| 56 | + |
| 57 | + - name: Cache Dependencies |
| 58 | + id: cache-deps |
| 59 | + uses: actions/cache@v2 |
| 60 | + with: |
| 61 | + path: ${{github.workspace}}/.venv |
| 62 | + key: poetry-${{ hashFiles('**/poetry.lock') }} |
| 63 | + restore-keys: poetry- |
| 64 | + |
| 65 | + - name: Install deps |
| 66 | + if: steps.cache-deps.cache-hit != 'true' |
| 67 | + run: | |
| 68 | + poetry config virtualenvs.in-project true |
| 69 | + poetry install --no-interaction |
| 70 | +
|
| 71 | + - name: Build Package |
| 72 | + run: poetry build |
| 73 | + |
| 74 | + - name: Publish to PyPi |
| 75 | + run: poetry publish -u __token__ -p $PYPI_TOKEN |
| 76 | + env: |
| 77 | + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} |
0 commit comments