|
| 1 | +name: CI, Build, and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master, develop ] |
| 6 | + tags: |
| 7 | + - 'v*' |
| 8 | + pull_request: |
| 9 | + branches: [ main, master, develop ] |
| 10 | + |
| 11 | +env: |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + test: |
| 17 | + name: Test |
| 18 | + runs-on: ubuntu-latest |
| 19 | + strategy: |
| 20 | + matrix: |
| 21 | + python-version: ["3.8", "3.9", "3.10", "3.11"] |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Python ${{ matrix.python-version }} |
| 28 | + uses: actions/setup-python@v5 |
| 29 | + with: |
| 30 | + python-version: ${{ matrix.python-version }} |
| 31 | + |
| 32 | + - name: Cache pip packages |
| 33 | + uses: actions/cache@v4 |
| 34 | + with: |
| 35 | + path: ~/.cache/pip |
| 36 | + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt') }} |
| 37 | + restore-keys: | |
| 38 | + ${{ runner.os }}-pip-${{ matrix.python-version }}- |
| 39 | +
|
| 40 | + - name: Install dependencies |
| 41 | + run: | |
| 42 | + python -m pip install --upgrade pip |
| 43 | + pip install -r requirements.txt |
| 44 | + pip install -r requirements-dev.txt |
| 45 | +
|
| 46 | + - name: Run tests |
| 47 | + run: | |
| 48 | + pytest tests/ -v --cov=website_diff --cov-report=xml --cov-report=term |
| 49 | +
|
| 50 | + - name: Upload coverage to Codecov |
| 51 | + uses: codecov/codecov-action@v3 |
| 52 | + with: |
| 53 | + file: ./coverage.xml |
| 54 | + flags: unittests |
| 55 | + name: codecov-${{ matrix.python-version }} |
| 56 | + fail_ci_if_error: false |
| 57 | + |
| 58 | + docker-build: |
| 59 | + name: Build and Push Docker Image |
| 60 | + needs: test |
| 61 | + runs-on: ubuntu-latest |
| 62 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) |
| 63 | + permissions: |
| 64 | + contents: read |
| 65 | + packages: write |
| 66 | + |
| 67 | + steps: |
| 68 | + - name: Checkout code |
| 69 | + uses: actions/checkout@v4 |
| 70 | + |
| 71 | + - name: Set up Docker Buildx |
| 72 | + uses: docker/setup-buildx-action@v3 |
| 73 | + |
| 74 | + - name: Log in to Container Registry |
| 75 | + uses: docker/login-action@v3 |
| 76 | + with: |
| 77 | + registry: ${{ env.REGISTRY }} |
| 78 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 79 | + password: ${{ secrets.DOCKER_TOKEN }} |
| 80 | + |
| 81 | + - name: Extract metadata |
| 82 | + id: meta |
| 83 | + uses: docker/metadata-action@v5 |
| 84 | + with: |
| 85 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 86 | + tags: | |
| 87 | + type=ref,event=branch |
| 88 | + type=ref,event=pr |
| 89 | + type=semver,pattern={{version}} |
| 90 | + type=semver,pattern={{major}}.{{minor}} |
| 91 | + type=semver,pattern={{major}} |
| 92 | + type=sha |
| 93 | +
|
| 94 | + - name: Build and push Docker image |
| 95 | + uses: docker/build-push-action@v5 |
| 96 | + with: |
| 97 | + context: . |
| 98 | + push: true |
| 99 | + tags: ${{ steps.meta.outputs.tags }} |
| 100 | + labels: ${{ steps.meta.outputs.labels }} |
| 101 | + cache-from: type=gha |
| 102 | + cache-to: type=gha,mode=max |
| 103 | + |
| 104 | + build-package: |
| 105 | + name: Build Python Package |
| 106 | + needs: test |
| 107 | + runs-on: ubuntu-latest |
| 108 | + if: startsWith(github.ref, 'refs/tags/v') |
| 109 | + |
| 110 | + steps: |
| 111 | + - name: Checkout code |
| 112 | + uses: actions/checkout@v4 |
| 113 | + with: |
| 114 | + fetch-depth: 0 |
| 115 | + |
| 116 | + - name: Set up Python |
| 117 | + uses: actions/setup-python@v5 |
| 118 | + with: |
| 119 | + python-version: "3.11" |
| 120 | + |
| 121 | + - name: Install build dependencies |
| 122 | + run: | |
| 123 | + python -m pip install --upgrade pip |
| 124 | + pip install build twine |
| 125 | +
|
| 126 | + - name: Extract version from tag |
| 127 | + id: tag_version |
| 128 | + run: | |
| 129 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 130 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 131 | + echo "Version: $VERSION" |
| 132 | +
|
| 133 | + - name: Update version in setup.py |
| 134 | + run: | |
| 135 | + sed -i "s/version=\".*\"/version=\"${{ steps.tag_version.outputs.version }}\"/" setup.py |
| 136 | + cat setup.py | grep version |
| 137 | +
|
| 138 | + - name: Build package |
| 139 | + run: | |
| 140 | + python -m build |
| 141 | +
|
| 142 | + - name: Upload artifacts |
| 143 | + uses: actions/upload-artifact@v4 |
| 144 | + with: |
| 145 | + name: dist-packages |
| 146 | + path: dist/* |
| 147 | + retention-days: 30 |
| 148 | + |
| 149 | + release: |
| 150 | + name: Create GitHub Release |
| 151 | + needs: [test, build-package, docker-build] |
| 152 | + runs-on: ubuntu-latest |
| 153 | + if: startsWith(github.ref, 'refs/tags/v') |
| 154 | + permissions: |
| 155 | + contents: write |
| 156 | + |
| 157 | + steps: |
| 158 | + - name: Checkout code |
| 159 | + uses: actions/checkout@v4 |
| 160 | + with: |
| 161 | + fetch-depth: 0 |
| 162 | + |
| 163 | + - name: Download artifacts |
| 164 | + uses: actions/download-artifact@v4 |
| 165 | + with: |
| 166 | + name: dist-packages |
| 167 | + path: dist/ |
| 168 | + |
| 169 | + - name: Extract version from tag |
| 170 | + id: tag_version |
| 171 | + run: | |
| 172 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 173 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 174 | + echo "Version: $VERSION" |
| 175 | +
|
| 176 | + - name: Create GitHub Release |
| 177 | + uses: softprops/action-gh-release@v1 |
| 178 | + with: |
| 179 | + files: | |
| 180 | + dist/*.whl |
| 181 | + dist/*.tar.gz |
| 182 | + name: Release ${{ steps.tag_version.outputs.version }} |
| 183 | + body: | |
| 184 | + ## Website-Diff ${{ steps.tag_version.outputs.version }} |
| 185 | + |
| 186 | + ### Installation |
| 187 | + ```bash |
| 188 | + pip install website-diff==${{ steps.tag_version.outputs.version }} |
| 189 | + ``` |
| 190 | + |
| 191 | + ### Docker |
| 192 | + ```bash |
| 193 | + docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag_version.outputs.version }} |
| 194 | + ``` |
| 195 | + |
| 196 | + ### Changes |
| 197 | + See [CHANGELOG](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details. |
| 198 | + |
| 199 | + ### Downloads |
| 200 | + - Source distribution: `website-diff-${{ steps.tag_version.outputs.version }}.tar.gz` |
| 201 | + - Wheel: `website_diff-${{ steps.tag_version.outputs.version }}-py3-none-any.whl` |
| 202 | + draft: false |
| 203 | + prerelease: false |
0 commit comments