Create README.md #31
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
name: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- master | |
- dev | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
services: | |
redis: | |
image: redis:alpine | |
ports: | |
- 6379:6379 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install flake8 black bandit mypy types-requests | |
- name: Run tests before version bump | |
run: pytest -v | |
- name: Calculate and update version | |
id: version | |
run: | | |
VERSION=$(grep -Po '(?<=VERSION = ")[^"]*' app.py) | |
if [[ $VERSION == *"-dev" ]]; then | |
VERSION_NUM=${VERSION%-dev} | |
if [ "${{ github.ref }}" == "refs/heads/master" ]; then | |
# Strip '-dev' suffix for the master branch | |
NEW_VERSION=$(python -c "major, minor, patch = map(int, '$VERSION_NUM'.split('.')); minor += 1; print(f'{major}.{minor}.{patch}')") | |
else | |
# Increment and keep '-dev' for the dev branch | |
NEW_VERSION=$(python -c "major, minor, patch = map(int, '$VERSION_NUM'.split('.')); patch += 1; print(f'{major}.{minor}.{patch}-dev')") | |
fi | |
else | |
# Regular version increment for non-dev versions | |
NEW_VERSION=$(python -c "major, minor, patch = map(int, '$VERSION'.split('.')); patch += 1; print(f'{major}.{minor}.{patch}')") | |
fi | |
sed -i "s/VERSION = .*/VERSION = \"$NEW_VERSION\"/" app.py | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
- name: Commit version change | |
if: success() | |
run: | | |
git config --global user.email "action@github.com" | |
git config --global user.name "GitHub Action" | |
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git | |
git add app.py | |
git commit -m "Bump version to $NEW_VERSION" | |
git tag -a v$NEW_VERSION -m "Release $NEW_VERSION" | |
git push origin HEAD --tags | |
- name: Run Flake8 | |
run: flake8 . | |
- name: Run Black | |
run: black --check . | |
- name: Run Bandit | |
run: bandit -r . --severity-level medium | |
- name: Run mypy | |
run: mypy app.py app_test.py |