From fd694256423eaf007e14a9fd9d506cb6e2dfc7ea Mon Sep 17 00:00:00 2001 From: Nils Uhrberg Date: Thu, 30 Jan 2025 17:04:06 +0100 Subject: [PATCH] ci: Add release and pre-release pipeline --- .github/workflows/pre-release.yaml | 69 ++++++++++++++++++++++++++++++ .github/workflows/pytest.yaml | 4 +- .github/workflows/release.yaml | 68 +++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/pre-release.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/pre-release.yaml b/.github/workflows/pre-release.yaml new file mode 100644 index 0000000..9757f57 --- /dev/null +++ b/.github/workflows/pre-release.yaml @@ -0,0 +1,69 @@ +name: 📦Create Pre-Release + +on: + pull_request: + branches: + - develop + types: + - closed +jobs: + release: + if: ${{ github.event.pull_request.merged }} + name: 🏗️ Build package and publish to pypi + runs-on: ubuntu-latest + concurrency: release + permissions: + id-token: write + environment: + name: pypi + url: https://pypi.org/p/ligthml + steps: + - name: ⬇️ Checkout repository + uses: actions/checkout@v4 + with: + ref: 'develop' + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + - name: 🐍Setup Python + uses: actions/setup-python@v5 + with: + python-version-file: "pyproject.toml" + - name: 🧙‍♂️Install uv + uses: astral-sh/setup-uv@v5 + with: + enable-cache: true + cache-dependency-glob: "uv.lock" + - name: 🔨Install dependencies + run: uv sync --all-extras --dev + - name: ⬇️ Download current coverage report + uses: actions/download-artifact@v4 + with: + name: code-coverage + path: ./coverage.xml + - name: 📃Pytest coverage report + id: coverageComment + uses: MishaKav/pytest-coverage-comment@main + with: + hide-comment: true + pytest-xml-coverage-path: ./coverage.xml + + - name: ✏️ Update Readme with Coverage Badge + run: | + sed -i '//,//c\\n\${{ steps.coverageComment.outputs.coverageHtml }}\n' ./README.md + + - name: 🚀 Python Semantic Release + id: release + uses: python-semantic-release/python-semantic-release@v9 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + force: "prerelease" + + - name: 🐍 Publish package distributions to PyPI + if: steps.release.outputs.released == 'true' + run: uv publish + + - name: 🐙 Publish package distributions to GitHub Releases + uses: python-semantic-release/publish-action@9 + if: steps.release.outputs.released == 'true' + with: + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 86486dd..a35bab7 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -14,8 +14,8 @@ jobs: strategy: fail-fast: false matrix: - os: [ ubuntu-latest ] - python-version: [ "3.10" ] + os: [ ubuntu-latest, macos-latest, windows-latest ] + python-version: [ "3.10", "3.11", "3.12","3.13", "3.14" ] runs-on: ${{ matrix.os }} timeout-minutes: 30 name: 🧪 Run pytests wit ${{matrix.python-version}} on ${{matrix.os}} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..0df27c9 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,68 @@ +name: 📦 Create Release + +on: + pull_request: + branches: + - main + types: + - closed +jobs: + release: + if: ${{ github.event.pull_request.merged }} + name: 🏗️ Build package and publish to pypi + runs-on: ubuntu-latest + concurrency: release + permissions: + id-token: write + environment: + name: pypi + url: https://pypi.org/p/ligthml + steps: + - name: ⬇️ Checkout repository + uses: actions/checkout@v4 + with: + ref: 'main' + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + - name: 🐍Setup Python + uses: actions/setup-python@v5 + with: + python-version-file: "pyproject.toml" + - name: 🧙‍♂️Install uv + uses: astral-sh/setup-uv@v5 + with: + enable-cache: true + cache-dependency-glob: "uv.lock" + - name: 🔨Install dependencies + run: uv sync --all-extras --dev + - name: ⬇️ Download current coverage report + uses: actions/download-artifact@v4 + with: + name: code-coverage + path: ./coverage.xml + - name: 📃Pytest coverage report + id: coverageComment + uses: MishaKav/pytest-coverage-comment@main + with: + hide-comment: true + pytest-xml-coverage-path: ./coverage.xml + + - name: ✏️ Update Readme with Coverage Badge + run: | + sed -i '//,//c\\n\${{ steps.coverageComment.outputs.coverageHtml }}\n' ./README.md + + - name: 🚀 Python Semantic Release + id: release + uses: python-semantic-release/python-semantic-release@v9 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: 🐍 Publish package distributions to PyPI + if: steps.release.outputs.released == 'true' + run: uv publish + + - name: 🐙 Publish package distributions to GitHub Releases + uses: python-semantic-release/publish-action@9 + if: steps.release.outputs.released == 'true' + with: + github_token: ${{ secrets.GITHUB_TOKEN }}