|
| 1 | +name: ❯ Python akande |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - "feat/*" |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + - "feat/*" |
| 12 | + |
| 13 | +jobs: |
| 14 | + # This job reads the version number from setup.cfg and sets it as an |
| 15 | + # environment variable |
| 16 | + version: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + version: ${{ steps.set-version.outputs.version }} |
| 20 | + steps: |
| 21 | + - name: ❯ Set up Python 🐍 |
| 22 | + uses: actions/setup-python@v2 |
| 23 | + with: |
| 24 | + python-version: "3.9" |
| 25 | + - name: ❯ Get version number from setup.cfg |
| 26 | + id: set-version |
| 27 | + run: | |
| 28 | + echo "::set-output name=version::$(python -c 'import configparser; cfg = configparser.ConfigParser(); cfg.read("setup.cfg"); print(cfg.get("metadata", "version"))')" |
| 29 | +
|
| 30 | + # This job runs unit tests using pytest |
| 31 | + pytest: |
| 32 | + needs: version |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + # Check out the repository code |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + |
| 38 | + # Set up Python and install dependencies |
| 39 | + - name: ❯ Set up Python and install dependencies 🐍📦 |
| 40 | + uses: actions/setup-python@v2 |
| 41 | + with: |
| 42 | + python-version: "3.9" |
| 43 | + - name: ❯ Install dependencies 📦 |
| 44 | + run: | |
| 45 | + python -m pip install --upgrade pip |
| 46 | + python -m pip install -r requirements.txt |
| 47 | + # python -m pip install pytest pytest-cov |
| 48 | + |
| 49 | + # Run pytest |
| 50 | + # - name: ❯ Run pytest 🧪 |
| 51 | + # run: pytest --cov=akande --cov-report=xml |
| 52 | + |
| 53 | + # Upload code coverage report to Codecov |
| 54 | + # - name: ❯ Upload code coverage report to Codecov 📊 |
| 55 | + # if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 56 | + # uses: codecov/codecov-action@v1 |
| 57 | + # with: |
| 58 | + # token: ${{ secrets.CODECOV_TOKEN }} |
| 59 | + |
| 60 | + # This job runs flake8 to check for code style issues |
| 61 | + lint: |
| 62 | + needs: version |
| 63 | + runs-on: ubuntu-latest |
| 64 | + steps: |
| 65 | + # Check out the repository code |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + # Set up Python and install dependencies |
| 68 | + - name: ❯ Set up Python and install dependencies 🐍📦 |
| 69 | + uses: actions/setup-python@v2 |
| 70 | + with: |
| 71 | + python-version: "3.9" |
| 72 | + - name: ❯ Install flake8 📦 |
| 73 | + run: python -m pip install flake8 |
| 74 | + # Run flake8 |
| 75 | + - name: ❯ Run flake8 🔍 |
| 76 | + run: flake8 |
| 77 | + |
| 78 | + # This job builds the distribution packages, and publishes them |
| 79 | + # to PyPI |
| 80 | + build: |
| 81 | + needs: [version, pytest] |
| 82 | + runs-on: ubuntu-latest |
| 83 | + env: |
| 84 | + TWINE_USERNAME: __token__ |
| 85 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 86 | + VERSION: ${{ needs.version.outputs.version }} |
| 87 | + PKG_NAME: akande |
| 88 | + steps: |
| 89 | + # Check out the repository code |
| 90 | + - uses: actions/checkout@v4 |
| 91 | + - name: ❯ Set up Python 🐍 |
| 92 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 93 | + id: python |
| 94 | + uses: actions/setup-python@v2 |
| 95 | + with: |
| 96 | + python-version: "3.9" |
| 97 | + |
| 98 | + # Install dependencies |
| 99 | + - name: ❯ Install dependencies 📦 |
| 100 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 101 | + run: | |
| 102 | + python -m pip install --upgrade pip setuptools wheel |
| 103 | + python -m pip install -r requirements.txt |
| 104 | +
|
| 105 | + # Update the version number based on the setup.cfg file |
| 106 | + - name: Update version number from setup.cfg file 📝 |
| 107 | + id: update-version |
| 108 | + run: | |
| 109 | + NEW_VERSION=$(grep -E '^version =' setup.cfg | cut -d '=' -f 2 | tr -d '[:space:]') |
| 110 | + echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV |
| 111 | + shell: /bin/bash -e {0} |
| 112 | + |
| 113 | + # Generate the changelog based on git log and template file |
| 114 | + - name: Generate Changelog 📚 |
| 115 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 116 | + run: | |
| 117 | + # Append version information to CHANGELOG.md |
| 118 | + echo "## Release v${{ env.VERSION }} - $(date +'%Y-%m-%d')" >> ${{ github.workspace }}/CHANGELOG.md |
| 119 | + # Copy content of template file to CHANGELOG.md |
| 120 | + cat TEMPLATE.md >> ${{ github.workspace }}/CHANGELOG.md |
| 121 | + # Append git log to CHANGELOG.md |
| 122 | + echo "$(git log --pretty=format:'%s' --reverse $(git describe --tags --abbrev=0)..HEAD)" >> ${{ github.workspace }}/CHANGELOG.md |
| 123 | + # Append empty line to CHANGELOG.md |
| 124 | + echo "" >> ${{ github.workspace }}/CHANGELOG.md |
| 125 | +
|
| 126 | + # Build distribution packages |
| 127 | + - name: ❯ Build distribution packages 🧰 |
| 128 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 129 | + run: | |
| 130 | + python setup.py sdist bdist_wheel |
| 131 | +
|
| 132 | + # Publish distribution packages to PyPI |
| 133 | + - name: ❯ Publish distribution packages to PyPI 🚀 |
| 134 | + id: publish |
| 135 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 136 | + uses: pypa/gh-action-pypi-publish@v1.3.1 |
| 137 | + with: |
| 138 | + user: ${{ env.TWINE_USERNAME }} |
| 139 | + password: ${{ env.TWINE_PASSWORD }} |
| 140 | + packages_dir: dist |
| 141 | + verify_metadata: true |
| 142 | + skip_existing: true |
| 143 | + |
| 144 | + # Append artifact links to the changelog |
| 145 | + - name: Append Artifact Links 🔗 |
| 146 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 147 | + run: | |
| 148 | + echo "" >> ${{ github.workspace }}/CHANGELOG.md |
| 149 | + echo "## Artifacts 🎁" >> ${{ github.workspace }}/CHANGELOG.md |
| 150 | + for filename in dist/*; do |
| 151 | + link="$(basename $filename)" |
| 152 | + echo "* [$link](${{ env.RELEASES_URL }}/$link)" >> ${{ github.workspace }}/CHANGELOG.md |
| 153 | + done |
| 154 | + env: |
| 155 | + RELEASES_URL: https://github.com/${{ github.repository }}/releases/download/v${{ env.VERSION }} |
| 156 | + |
| 157 | + # Create a release |
| 158 | + - name: Create Release 🚀 |
| 159 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 160 | + id: create_release |
| 161 | + uses: actions/create-release@v1 |
| 162 | + env: |
| 163 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 164 | + with: |
| 165 | + tag_name: v${{ env.VERSION }} |
| 166 | + release_name: Release v${{ env.VERSION }} |
| 167 | + body_path: ${{ github.workspace }}/CHANGELOG.md |
| 168 | + draft: false |
| 169 | + prerelease: false |
| 170 | + |
| 171 | + - name: Upload Release Assets 📦 |
| 172 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 173 | + env: |
| 174 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 175 | + run: | |
| 176 | + upload_url=${{ steps.create_release.outputs.upload_url }} |
| 177 | + for file in dist/*; do |
| 178 | + curl \ |
| 179 | + -H "Authorization: token ${GITHUB_TOKEN}" \ |
| 180 | + -H "Content-Type: $(file --mime-type -b $file)" \ |
| 181 | + --data-binary @$file \ |
| 182 | + "${upload_url}?name=$(basename $file)" |
| 183 | + done |
0 commit comments