Skip to content

Commit

Permalink
Create python-publish.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzeh-pm authored Sep 6, 2024
1 parent 0c61583 commit 64be26a
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Django Package CI

on:
push:
branches:
- main
pull_request:
branches:
- main
release:
types: [created]

jobs:
test:
name: Pytest on Python 3.11 with MongoDB
runs-on: ubuntu-latest

services:
mongodb:
image: mongo:latest
ports:
- 27017:27017
options: >-
--health-cmd="mongosh --eval 'db.runCommand({ ping: 1 })'"
--health-interval=10s
--health-timeout=5s
--health-retries=5
env:
MONGO_INITDB_ROOT_USERNAME: root # Set the MongoDB root username
MONGO_INITDB_ROOT_PASSWORD: rootpassword # Set the MongoDB root password
MONGO_INITDB_DATABASE: django_mongoengine_logger # Set the default database name

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Install dependencies including dev packages
run: |
poetry install --with dev # Install both regular and dev dependencies
- name: Wait for MongoDB to be ready
run: sleep 15 # Give MongoDB some time to initialize

- name: Run tests
env:
MONGO_INITDB_ROOT_USERNAME: root # Set the MongoDB root username
MONGO_INITDB_ROOT_PASSWORD: rootpassword # Set the MongoDB root password
MONGO_INITDB_DATABASE: django_mongoengine_logger # Set the default database name
run: |
poetry run pytest
build:
name: Build the package
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Install dependencies including dev packages
run: |
poetry install --with dev
- name: Build the package
run: |
poetry build
# Save the built package as an artifact so it can be used in the publish step
- name: Upload package artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: ./dist # Assuming poetry build stores artifacts in ./dist

publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Install dependencies including dev packages
run: |
poetry install --with dev
# Download the built package artifact from the build step
- name: Download package artifact
uses: actions/download-artifact@v3
with:
name: dist
path: ./dist # Download to ./dist, which Poetry expects for publishing

- name: Publish to PyPI
env:
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
poetry publish --username $PYPI_USERNAME --password $PYPI_PASSWORD --repository pypi --no-interaction --skip-existing

0 comments on commit 64be26a

Please sign in to comment.