Skip to content

Commit

Permalink
build: added publish action (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankanno authored Aug 5, 2022
1 parent d7e4c96 commit f648556
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Builds and publishes to testpypi on every push to main
# On release, publishes to pypi
name: publish

on:
push:
branches:
- main
release:
types: [published]

env:
PYTHON_VERSION: 3.8
DUNAMAI_VERSION: 1.8.0

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"

- name: Set version with dunamai
uses: mtkennerly/dunamai-action@v1
with:
env-var: LIB_VERSION
command: dunamai from git
args: --no-metadata --style semver

- run: echo $LIB_VERSION
- run: poetry version $LIB_VERSION

- name: poetry build
run: poetry build

- uses: actions/upload-artifact@v2
with:
name: poetry_build
path: dist/

publish_test_pypi:
if: github.repository_owner == 'ryankanno'
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"

- uses: actions/download-artifact@v2
with:
name: poetry_build
path: dist/

- name: Install Poetry
run: python -m pip install poetry

- name: poetry configure TestPyPI Repo
run: poetry config repositories.test-pypi https://test.pypi.org/legacy/

- name: poetry configure TestPyPI Token
run: poetry config pypi-token.test-pypi ${{ secrets.TEST_PYPI_API_TOKEN }}

- name: poetry publish TestPyPi
run: poetry publish -r test-pypi

publish_pypi:
if: github.repository_owner == 'ryankanno' && github.event_name == 'release' && github.event.action == 'published'
runs-on: ubuntu-latest
needs: publish_test_pypi
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"

- uses: actions/download-artifact@v2
with:
name: poetry_build
path: dist/

- name: Install Poetry
run: python -m pip install poetry

- name: poetry configure PyPI Token
run: poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}

- name: poetry publish PyPi
run: poetry publish

0 comments on commit f648556

Please sign in to comment.