Skip to content

Commit

Permalink
Merge pull request #1 from marcpinet/ci-improve-efficiency
Browse files Browse the repository at this point in the history
ci: improve efficiency and add auto unit testing
  • Loading branch information
marcpinet authored Nov 12, 2023
2 parents c9ea8f4 + f580c52 commit 345c361
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
28 changes: 25 additions & 3 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,49 @@ on:
push:
branches:
- main
paths:
- 'setup.py'
pull_request:
branches:
- "main"
paths:
- 'setup.py'

jobs:
publish:
check-version-changed:
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.version-change.outputs.version_changed }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Check if version changed
id: version-change
run: |
VERSION_CHANGE=$(git diff HEAD^ HEAD -- setup.py | grep -e "^+.*version.*=" -e "^-.*version.*=" | wc -l)
if [ "$VERSION_CHANGE" -eq 0 ]; then
echo "Version not changed"
echo "::set-output name=version_changed::false"
else
echo "Version changed"
echo "::set-output name=version_changed::true"
fi
publish:
needs: check-version-changed
if: needs.check-version-changed.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand Down
29 changes: 25 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,55 @@ on:
push:
branches:
- main
paths:
- 'setup.py'
pull_request:
branches:
- "main"
paths:
- 'setup.py'

jobs:
release:
check-version-changed:
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.version-change.outputs.version_changed }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Check if version changed
id: version-change
run: |
VERSION_CHANGE=$(git diff HEAD^ HEAD -- setup.py | grep -e "^+.*version.*=" -e "^-.*version.*=" | wc -l)
if [ "$VERSION_CHANGE" -eq 0 ]; then
echo "Version not changed"
echo "::set-output name=version_changed::false"
else
echo "Version changed"
echo "::set-output name=version_changed::true"
fi
release:
needs: check-version-changed
if: needs.check-version-changed.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Extract Version from setup.py
id: get_version
run: |
echo "::set-output name=VERSION::$(python setup.py --version)"
- name: Create and Push Tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag v${{ steps.get_version.outputs.VERSION }}
git push origin v${{ steps.get_version.outputs.VERSION }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run Unit Tests

on:
push:
branches:
- main
pull_request:
branches:
- "main"

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Unit Tests
run: |
python -m unittest discover tests

0 comments on commit 345c361

Please sign in to comment.