Automation of github release and tag, and publish to pypi #88
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 to PyPI | |
on: | |
pull_request: | |
branches: [test] | |
jobs: | |
pypi_release: | |
runs-on: ubuntu-latest | |
env: | |
POETRY_VERSION: 1.3.0 | |
#if: github.event_name == 'push' && contains(github.ref, 'refs/tags') | |
steps: | |
- name: Get list of tags | |
uses: octokit/[email protected] | |
id: get_latest_release | |
with: | |
route: GET /repos/${{ github.repository }}/git/matching-refs/tags | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
#---------------------------------------------- | |
# check-out repo and set-up python | |
#---------------------------------------------- | |
- name: Check out repository | |
uses: actions/checkout@v2 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
#---------------------------------------------- | |
# install & configure poetry | |
#---------------------------------------------- | |
- name: Install Poetry | |
run: | | |
curl -sSL https://install.python-poetry.org \ | |
| python3 - --version ${{ env.POETRY_VERSION }}; | |
poetry config virtualenvs.create true; | |
poetry config virtualenvs.in-project true; | |
#-----python----------------------------------------- | |
# load cached venv if cache exists | |
#---------------------------------------------- | |
- name: Load cached venv | |
id: cached-poetry-dependencies | |
uses: actions/cache@v2 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} | |
#---------------------------------------------- | |
# install dependencies and root project | |
#---------------------------------------------- | |
- name: Install dependencies and root project | |
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
run: poetry install --no-interaction --all-extras | |
#---------------------------------------------- | |
# Construct release version | |
#---------------------------------------------- | |
- name: Construct release version | |
id: release_version | |
run: | | |
VAR=$(poetry run python3.10 github_scripts/construct_release_version.py) | |
echo "RELEASE_VERSION=$VAR" >> "$GITHUB_OUTPUT" | |
shell: sh | |
env: | |
TAGS: ${{ steps.get_latest_release.outputs.data }} | |
#---------------------------------------------- | |
# Create release | |
#---------------------------------------------- | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.release_version.outputs.RELEASE_VERSION }} | |
release_name: ${{ steps.release_version.outputs.RELEASE_VERSION }} | |
draft: false | |
prerelease: false | |
#---------------------------------------------- | |
# Set release version | |
#---------------------------------------------- | |
- name: Set release version | |
run: | | |
poetry run python3 github_scripts/update_toml_version.py | |
shell: sh | |
env: | |
RELEASE_VERSION: ${{ steps.release_version.outputs.RELEASE_VERSION }} | |
#---------------------------------------------- | |
# publish to pypi | |
#---------------------------------------------- | |
- name: Publish package to Pypi | |
id: publish-to-pypi | |
#if: steps.check-tag.outputs.match == 'true' | |
env: | |
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} | |
PYPI_USERNAME: __token__ | |
run: | | |
poetry publish --build --username $PYPI_USERNAME --password $PYPI_TOKEN |