|
| 1 | +name: cicd |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - "*" |
| 9 | + pull_request: |
| 10 | + |
| 11 | +jobs: |
| 12 | + code-scan: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python ${{ matrix.python-version }} |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: ${{ matrix.python-version }} |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: pip install --no-cache-dir -U pip black flake8 bandit |
| 30 | + |
| 31 | + - name: Lint with flake8 |
| 32 | + run: flake8 pyproxy tests benchmark |
| 33 | + |
| 34 | + - name: Check with black |
| 35 | + run: black --check pyproxy tests benchmark |
| 36 | + |
| 37 | + - name: Check with bandit |
| 38 | + run: bandit -r pyproxy tests benchmark |
| 39 | + |
| 40 | + unittest: |
| 41 | + needs: code-scan |
| 42 | + runs-on: ubuntu-latest |
| 43 | + permissions: |
| 44 | + contents: read |
| 45 | + |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Set up Python |
| 50 | + uses: actions/setup-python@v5 |
| 51 | + with: |
| 52 | + python-version: 3.13 |
| 53 | + |
| 54 | + - name: Install build dependencies |
| 55 | + run: pip install --no-cache-dir -r requirements.txt |
| 56 | + |
| 57 | + - name: Run tests |
| 58 | + run: python -m unittest discover -s tests |
| 59 | + |
| 60 | + build-docker: |
| 61 | + needs: unittest |
| 62 | + if: github.event_name == 'push' |
| 63 | + runs-on: ubuntu-latest |
| 64 | + permissions: |
| 65 | + contents: write |
| 66 | + id-token: write |
| 67 | + |
| 68 | + steps: |
| 69 | + - uses: actions/checkout@v4 |
| 70 | + with: |
| 71 | + fetch-depth: 0 |
| 72 | + |
| 73 | + - name: Set up Docker Buildx |
| 74 | + uses: docker/setup-buildx-action@v2 |
| 75 | + |
| 76 | + - name: Log in to GitHub Container Registry |
| 77 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
| 78 | + |
| 79 | + - name: Get version |
| 80 | + id: get_version |
| 81 | + run: | |
| 82 | + version=$(grep '^__version__' pyproxy/__init__.py | cut -d'"' -f2) |
| 83 | + echo "version=${version}" >> $GITHUB_ENV |
| 84 | +
|
| 85 | + - name: Convert repository owner to lowercase |
| 86 | + run: echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV |
| 87 | + |
| 88 | + - name: Build Docker image |
| 89 | + run: docker build -t ghcr.io/${{ env.REPO_OWNER }}/pyproxy:${{ env.VERSION }} -t ghcr.io/${{ env.REPO_OWNER }}/pyproxy:latest . |
| 90 | + |
| 91 | + - name: Build Docker slim image |
| 92 | + run: docker build -f Dockerfile.slim -t ghcr.io/${{ env.REPO_OWNER }}/pyproxy:${{ env.VERSION }}-slim -t ghcr.io/${{ env.REPO_OWNER }}/pyproxy:latest-slim . |
| 93 | + |
| 94 | + - name: Push Docker image |
| 95 | + run: | |
| 96 | + docker push ghcr.io/${{ env.REPO_OWNER }}/pyproxy:${{ env.VERSION }}-slim |
| 97 | + docker push ghcr.io/${{ env.REPO_OWNER }}/pyproxy:latest-slim |
| 98 | + docker push ghcr.io/${{ env.REPO_OWNER }}/pyproxy:${{ env.VERSION }} |
| 99 | + docker push ghcr.io/${{ env.REPO_OWNER }}/pyproxy:latest |
| 100 | +
|
| 101 | + build-packages: |
| 102 | + needs: unittest |
| 103 | + if: github.event_name == 'push' |
| 104 | + runs-on: ubuntu-latest |
| 105 | + permissions: |
| 106 | + contents: read |
| 107 | + id-token: write |
| 108 | + |
| 109 | + steps: |
| 110 | + - uses: actions/checkout@v4 |
| 111 | + |
| 112 | + - name: Set up Python |
| 113 | + uses: actions/setup-python@v5 |
| 114 | + with: |
| 115 | + python-version: 3.13 |
| 116 | + |
| 117 | + - name: Get version |
| 118 | + id: get_version |
| 119 | + run: | |
| 120 | + version=$(grep '^__version__' pyproxy/__init__.py | cut -d'"' -f2) |
| 121 | + echo "version=${version}" >> $GITHUB_OUTPUT |
| 122 | +
|
| 123 | + - name: Create Tag |
| 124 | + run: | |
| 125 | + git config user.name "github-actions[bot]" |
| 126 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 127 | + git tag v${{ steps.get_version.outputs.version }} |
| 128 | + git push origin v${{ steps.get_version.outputs.version }} |
| 129 | +
|
| 130 | + - name: Create GitHub Release |
| 131 | + id: create_release |
| 132 | + uses: actions/create-release@v1 |
| 133 | + with: |
| 134 | + tag_name: v${{ steps.get_version.outputs.version }} |
| 135 | + release_name: Release v${{ steps.get_version.outputs.version }} |
| 136 | + draft: false |
| 137 | + prerelease: false |
| 138 | + env: |
| 139 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 140 | + |
| 141 | + - name: Install build dependencies |
| 142 | + run: pip install --no-cache-dir -U pip . build |
| 143 | + |
| 144 | + - name: Build package |
| 145 | + run: python -m build --sdist --wheel |
| 146 | + - name: Upload built distributions |
| 147 | + uses: actions/upload-artifact@v4 |
| 148 | + with: |
| 149 | + name: dist |
| 150 | + path: dist |
| 151 | + |
| 152 | + - name: Install release dependencies |
| 153 | + run: pip install --no-cache-dir -U pip . twine packaging |
| 154 | + |
| 155 | + - name: Upload to PyPI |
| 156 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments