|
| 1 | +name: Publish Python Package |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + python-version: ['3.8', '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: | |
| 30 | + python -m pip install --upgrade pip |
| 31 | + pip install -e . |
| 32 | + pip install -r requirements-dev.txt |
| 33 | + |
| 34 | + - name: Lint with flake8 |
| 35 | + run: | |
| 36 | + flake8 src/gitspaces --count --select=E9,F63,F7,F82 --show-source --statistics |
| 37 | + flake8 src/gitspaces --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 38 | + |
| 39 | + - name: Check code formatting with black |
| 40 | + run: | |
| 41 | + black --check src/gitspaces tests |
| 42 | + |
| 43 | + - name: Run tests with pytest |
| 44 | + run: | |
| 45 | + pytest tests/ -v --cov=src/gitspaces --cov-report=xml --cov-report=term |
| 46 | +
|
| 47 | + build: |
| 48 | + needs: test |
| 49 | + runs-on: ubuntu-latest |
| 50 | + permissions: |
| 51 | + contents: read |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v4 |
| 54 | + |
| 55 | + - name: Set up Python |
| 56 | + uses: actions/setup-python@v5 |
| 57 | + with: |
| 58 | + python-version: '3.11' |
| 59 | + |
| 60 | + - name: Extract version from tag |
| 61 | + id: get_version |
| 62 | + run: | |
| 63 | + # Remove 'v' prefix from tag |
| 64 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 65 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 66 | + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 67 | + |
| 68 | + - name: Update version in pyproject.toml |
| 69 | + run: | |
| 70 | + sed -i 's/^version = ".*"/version = "${{ steps.get_version.outputs.version }}"/' pyproject.toml |
| 71 | + |
| 72 | + - name: Update version in __init__.py |
| 73 | + run: | |
| 74 | + sed -i 's/__version__ = ".*"/__version__ = "${{ steps.get_version.outputs.version }}"/' src/gitspaces/__init__.py |
| 75 | + |
| 76 | + - name: Install dependencies |
| 77 | + run: | |
| 78 | + python -m pip install --upgrade pip |
| 79 | + pip install build twine |
| 80 | + |
| 81 | + - name: Build package |
| 82 | + run: python -m build |
| 83 | + |
| 84 | + - name: Rename distribution files |
| 85 | + run: | |
| 86 | + cd dist |
| 87 | + for file in *; do |
| 88 | + # Add gitspaces- prefix if not already present |
| 89 | + if [[ ! "$file" =~ ^gitspaces- ]]; then |
| 90 | + mv "$file" "gitspaces-${{ steps.get_version.outputs.tag }}-${file}" |
| 91 | + fi |
| 92 | + done |
| 93 | + ls -la |
| 94 | + |
| 95 | + - name: Check package |
| 96 | + run: twine check dist/* |
| 97 | + |
| 98 | + - name: Upload artifacts |
| 99 | + uses: actions/upload-artifact@v4 |
| 100 | + with: |
| 101 | + name: python-package-distributions |
| 102 | + path: dist/ |
| 103 | + |
| 104 | + test-pypi-publish: |
| 105 | + name: Publish to TestPyPI |
| 106 | + needs: build |
| 107 | + runs-on: ubuntu-latest |
| 108 | + environment: |
| 109 | + name: testpypi |
| 110 | + url: https://test.pypi.org/p/gitspaces |
| 111 | + permissions: |
| 112 | + id-token: write |
| 113 | + |
| 114 | + steps: |
| 115 | + - name: Download artifacts |
| 116 | + uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + name: python-package-distributions |
| 119 | + path: dist/ |
| 120 | + |
| 121 | + - name: Publish to TestPyPI |
| 122 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 123 | + with: |
| 124 | + repository-url: https://test.pypi.org/legacy/ |
| 125 | + |
| 126 | + github-release: |
| 127 | + name: Create GitHub Release |
| 128 | + needs: test-pypi-publish |
| 129 | + runs-on: ubuntu-latest |
| 130 | + permissions: |
| 131 | + contents: write |
| 132 | + |
| 133 | + steps: |
| 134 | + - uses: actions/checkout@v4 |
| 135 | + |
| 136 | + - name: Extract version from tag |
| 137 | + id: get_version |
| 138 | + run: | |
| 139 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 140 | + TAG=${GITHUB_REF#refs/tags/} |
| 141 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 142 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 143 | + |
| 144 | + - name: Download artifacts |
| 145 | + uses: actions/download-artifact@v4 |
| 146 | + with: |
| 147 | + name: python-package-distributions |
| 148 | + path: dist/ |
| 149 | + |
| 150 | + - name: Create Release |
| 151 | + uses: softprops/action-gh-release@v1 |
| 152 | + with: |
| 153 | + files: dist/* |
| 154 | + tag_name: ${{ steps.get_version.outputs.tag }} |
| 155 | + name: Release ${{ steps.get_version.outputs.tag }} |
| 156 | + draft: false |
| 157 | + prerelease: false |
| 158 | + generate_release_notes: true |
| 159 | + |
| 160 | + pypi-publish: |
| 161 | + name: Publish to PyPI |
| 162 | + needs: github-release |
| 163 | + runs-on: ubuntu-latest |
| 164 | + environment: |
| 165 | + name: pypi |
| 166 | + url: https://pypi.org/p/gitspaces |
| 167 | + permissions: |
| 168 | + id-token: write |
| 169 | + |
| 170 | + steps: |
| 171 | + - name: Download artifacts |
| 172 | + uses: actions/download-artifact@v4 |
| 173 | + with: |
| 174 | + name: python-package-distributions |
| 175 | + path: dist/ |
| 176 | + |
| 177 | + - name: Publish to PyPI |
| 178 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments