Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor project workflow #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 62 additions & 45 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,82 @@
name: Publish Python 🐍 distributions 📦 to PyPI
name: Build and publish Python 🐍 distributions 📦 to PyPI

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

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.10'

- name: Install test dependencies
run: python -m pip install -r requirements/local.txt

# Run tests
- name: Run tests
run: pytest

build-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.9'
- uses: actions/checkout@v2

- name: Install pypa/setuptools
run: python -m pip install wheel
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.9'

- name: Extract tag name
id: tag
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
- name: Install pypa/setuptools
run: python -m pip install wheel

- name: Determine new release version
id: release-version
if: github.ref == 'refs/heads/main'
run: |
current_version=${{ steps.tag.outputs.TAG_NAME }}
IFS='.' read -ra version_parts <<< "$current_version"
new_version="${version_parts[0]}.${version_parts[1]}.$((${version_parts[2]} + 1))"
echo "::set-output name=NEW_RELEASE_VERSION::$new_version"
- name: Extract tag name
id: tag
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)

- name: Update version in setup.py
run: |
if [[ -n "${{ steps.release-version.outputs.NEW_RELEASE_VERSION }}" ]]; then
new_release_version="${{ steps.release-version.outputs.NEW_RELEASE_VERSION }}"
sed -i "s/{{VERSION_PLACEHOLDER}}/${new_release_version}/g" setup.py
else
sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" setup.py
fi
- name: Determine new release version
id: release-version
if: github.ref == 'refs/heads/main'
run: |
current_version=${{ steps.tag.outputs.TAG_NAME }}
IFS='.' read -ra version_parts <<< "$current_version"
new_version="${version_parts[0]}.${version_parts[1]}.$((${version_parts[2]} + 1))"
echo "::set-output name=NEW_RELEASE_VERSION::$new_version"

- name: Build a binary wheel
run: python setup.py sdist bdist_wheel
- name: Update version in setup.py
run: |
if [[ -n "${{ steps.release-version.outputs.NEW_RELEASE_VERSION }}" ]]; then
new_release_version="${{ steps.release-version.outputs.NEW_RELEASE_VERSION }}"
sed -i "s/{{VERSION_PLACEHOLDER}}/${new_release_version}/g" setup.py
else
sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" setup.py
fi

- name: Publish package 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Build a binary wheel
run: python setup.py sdist bdist_wheel

- name: Adjust release tag
if: startsWith(github.ref, 'refs/tags/')
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -d "${{ steps.tag.outputs.TAG_NAME }}"
git push origin :refs/tags/${{ steps.tag.outputs.TAG_NAME }}
git tag "${{ steps.tag.outputs.TAG_NAME }}"
git push origin "${{ steps.tag.outputs.TAG_NAME }}"
- name: Publish package 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

- name: Adjust release tag
if: startsWith(github.ref, 'refs/tags/')
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -d "${{ steps.tag.outputs.TAG_NAME }}"
git push origin :refs/tags/${{ steps.tag.outputs.TAG_NAME }}
git tag "${{ steps.tag.outputs.TAG_NAME }}"
git push origin "${{ steps.tag.outputs.TAG_NAME }}"
26 changes: 26 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Run Tests

on:
push:
branches:
- main


jobs:
test:
name: Run Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.9'

- name: Install test dependencies
run: python -m pip install -r requirements/local.txt

# Run tests
- name: Run tests
run: pytest
2 changes: 1 addition & 1 deletion docs/contribution_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cd Paymob

3. Install the necessary dependencies:
```shell
pip install -r requirements.txt
pip install -r requirements/local.txt
```

## Step 3: Make Changes
Expand Down
22 changes: 0 additions & 22 deletions requirements.txt

This file was deleted.

7 changes: 7 additions & 0 deletions requirements/local.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
multimethod==1.9.1
pre-commit==3.3.3
pydantic==2.0.2
pytest==7.4.0
python-decouple==3.8
requests==2.31.0
virtualenv==20.23.1
3 changes: 3 additions & 0 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
requests==2.31.0
python-decouple==3.8
multimethod==1.9.1