From 95b78c4f7a3bd183672ac381731d7bcc035675b4 Mon Sep 17 00:00:00 2001 From: Mark Beacom <7315957+mbeacom@users.noreply.github.com> Date: Fri, 25 Feb 2022 15:23:01 -0500 Subject: [PATCH] Enable automatic release to PyPi on tag --- .github/workflows/publish.yml | 77 +++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..cea8c32c --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,77 @@ +on: + push: + tags: + - '*' + +name: Create & Publish Package + +jobs: + publish: + name: Create & Publish Package + runs-on: 'ubuntu-latest' + steps: + - name: Checkout Source + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.7' + + - name: Cache Poetry + id: cache-poetry + uses: actions/cache@v2 + with: + path: ~/.poetry + key: poetry + + - name: Install Poetry + if: steps.cache-poetry.outputs.cache-hit != 'true' + run: | + curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -O + python install-poetry.py --preview + + - name: Add Poetry to $PATH + run: echo "$HOME/.poetry/bin" >> $GITHUB_PATH + + - name: Add versioning plugin + run: poetry plugin add poetry-version-plugin + + - name: Poetry Version + run: poetry --version + + - name: Add version to environment vars + run: echo "MODULE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Check if source version is up-to-date + run: | + TAG=$(git describe HEAD --tags --abbrev=0) + echo Current Tag: $TAG -- Current Module Version: $MODULE_VERSION + if [[ "$TAG" != "$MODULE_VERSION" ]]; then exit 1; fi + + - name: Check pyproject.toml validity + run: poetry check --no-interaction + + - name: Cache Dependencies + id: cache-deps + uses: actions/cache@v2 + with: + path: ${{github.workspace}}/.venv + key: poetry-${{ hashFiles('**/poetry.lock') }} + restore-keys: poetry- + + - name: Install deps + if: steps.cache-deps.cache-hit != 'true' + run: | + poetry config virtualenvs.in-project true + poetry install --no-interaction + + - name: Build Package + run: poetry build + + - name: Publish to PyPi + run: poetry publish -u __token__ -p $PYPI_TOKEN + env: + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}