-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
129 additions
and
0 deletions.
There are no files selected for viewing
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
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 |