diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 8719e51..a8d4fb2 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index efcf32b..047cbf9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 0000000..888e52e --- /dev/null +++ b/.github/workflows/unittest.yml @@ -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