From fc93eb592f36832dcfc256b56f4c35992e12f3e8 Mon Sep 17 00:00:00 2001 From: Daniel Tan Date: Thu, 9 May 2024 01:18:00 +0100 Subject: [PATCH] chore: split CI --- .github/workflows/build_and_release.yaml | 89 ------------------------ .github/workflows/release.yaml | 46 ++++++++++++ .github/workflows/tests.yaml | 48 +++++++++++++ README.md | 2 +- 4 files changed, 95 insertions(+), 90 deletions(-) delete mode 100644 .github/workflows/build_and_release.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/build_and_release.yaml b/.github/workflows/build_and_release.yaml deleted file mode 100644 index 9753d46..0000000 --- a/.github/workflows/build_and_release.yaml +++ /dev/null @@ -1,89 +0,0 @@ -name: "build and release" -on: - pull_request: - branches: - - main - push: - branches: - - main - - # Allow this workflow to be called from other workflows - workflow_call: - inputs: - # Requires at least one input to be valid, but in practice we don't need any - dummy: - type: string - required: false - -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.11", "3.12"] - - steps: - - uses: actions/checkout@v4 - - name: Setup PDM - uses: pdm-project/setup-pdm@v4 - with: - cache: true - python-version: ${{ matrix.python-version }} - - name: Cache Huggingface assets - uses: actions/cache@v4 - with: - key: huggingface-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }} - path: ~/.cache/huggingface - restore-keys: | - huggingface-${{ runner.os }}-${{ matrix.python-version }}- - - name: Install dependencies - run: pdm install - - name: check formatting - run: pdm run ruff format --check - - name: check linting - run: pdm run ruff check - - name: check types - run: pdm run pyright - - name: test - run: pdm run pytest - - build_and_release: - needs: test - runs-on: ubuntu-latest - permissions: - contents: write - id-token: write - environment: - # Same environment name configured in PyPI trusted publisher - name: pypi - - if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'chore(release):') - concurrency: release - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Setup PDM - uses: pdm-project/setup-pdm@v4 - with: - cache: true - python-version: "3.11" - - name: Install dependencies - run: pdm install - - name: Build - run: pdm build - - name: Semantic Release - id: release - uses: python-semantic-release/python-semantic-release@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Publish package distributions to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - if: steps.release.outputs.released == 'true' - - name: Publish package distributions to GitHub Releases - uses: python-semantic-release/upload-to-gh-release@main - if: steps.release.outputs.released == 'true' - with: - github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..124660e --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,46 @@ +name: "release" +on: + workflow_run: + workflows: ["tests"] + types: + - completed + +jobs: + release: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + environment: + # Same environment name configured in PyPI trusted publisher + name: pypi + concurrency: release + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup PDM + uses: pdm-project/setup-pdm@v4 + with: + cache: true + python-version: "3.11" + - name: Install dependencies + run: pdm install + - name: Build + run: pdm build + - name: Semantic Release + id: release + uses: python-semantic-release/python-semantic-release@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + if: steps.release.outputs.released == 'true' + - name: Publish package distributions to GitHub Releases + uses: python-semantic-release/upload-to-gh-release@main + if: steps.release.outputs.released == 'true' + with: + github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..061d4b2 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,48 @@ +name: "tests" +on: + pull_request: + branches: + - main + push: + branches: + - main + + # Allow this workflow to be called from other workflows + workflow_call: + inputs: + # Requires at least one input to be valid, but in practice we don't need any + dummy: + type: string + required: false + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + - name: Setup PDM + uses: pdm-project/setup-pdm@v4 + with: + cache: true + python-version: ${{ matrix.python-version }} + - name: Cache Huggingface assets + uses: actions/cache@v4 + with: + key: huggingface-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }} + path: ~/.cache/huggingface + restore-keys: | + huggingface-${{ runner.os }}-${{ matrix.python-version }}- + - name: Install dependencies + run: pdm install + - name: check formatting + run: pdm run ruff format --check + - name: check linting + run: pdm run ruff check + - name: check types + run: pdm run pyright + - name: test + run: pdm run pytest \ No newline at end of file diff --git a/README.md b/README.md index c527dd0..074ebe6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # PDM Python Project Template -![Github Actions](https://github.com/90HH/pdm-python-project-template/actions/workflows/build_and_release.yaml/badge.svg) +![Github Actions](https://github.com/90HH/pdm-python-project-template/actions/workflows/tests.yaml/badge.svg) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm-project.org) [![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)