mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
📦 Move PyPI release workflow into the main workflow.
This ensures that any releases are fully tested before publication. The workflow first builds the distribution files (sdist, wheel) before using a deployment environment to publish these to PyPI, using the GitHub actions OpenID support to authenticate with PyPI.
This commit is contained in:
118
.github/workflows/ci-cd.yml
vendored
Normal file
118
.github/workflows/ci-cd.yml
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
name: CI/CD
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Linter
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install Poetry
|
||||
run: pipx install poetry
|
||||
- name: Setup Python
|
||||
id: setup-python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.x'
|
||||
cache: poetry
|
||||
- name: Cache mypy cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: .mypy_cache
|
||||
key: ${{ runner.os }}-mypy-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-mypy-${{ steps.setup-python.outputs.python-version }}-
|
||||
${{ runner.os }}-mypy-
|
||||
- name: Install linting requirements
|
||||
run: poetry install --no-root
|
||||
- name: Execute linters
|
||||
run: make lint
|
||||
|
||||
test:
|
||||
needs:
|
||||
- lint
|
||||
strategy:
|
||||
matrix:
|
||||
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
|
||||
fail-fast: false
|
||||
|
||||
name: "Test on Python ${{ matrix.python }}"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install Poetry
|
||||
run: pipx install poetry
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "${{ matrix.python }}"
|
||||
cache: poetry
|
||||
- name: Install testing requirements
|
||||
run: |
|
||||
poetry install --no-root
|
||||
poetry run pip install tox-gh-actions
|
||||
- name: Execute tests
|
||||
run: poetry run tox
|
||||
|
||||
test-summary:
|
||||
name: Test matrix status
|
||||
runs-on: ubuntu-latest
|
||||
needs: [test]
|
||||
if: always()
|
||||
steps:
|
||||
- name: Decide whether the needed jobs succeeded or failed
|
||||
uses: re-actors/alls-green@release/v1
|
||||
with:
|
||||
jobs: ${{ toJSON(needs) }}
|
||||
|
||||
build:
|
||||
name: Build distributions
|
||||
runs-on: ubuntu-latest
|
||||
needs: [test-summary]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Poetry
|
||||
run: pipx install poetry
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.x'
|
||||
cache: poetry
|
||||
- name: Build distributions
|
||||
run:
|
||||
make build
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
|
||||
publish:
|
||||
name: Build and publish Python 🐍 distributions 📦 to PyPI
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
||||
needs: [build]
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: pypi
|
||||
# The URL is used in the 'successfully deployed' message as the link
|
||||
# for the 'View deployment' button.
|
||||
url: https://pypi.org/p/fastapi-cache2
|
||||
permissions:
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
- name: Publish distribution 📦 to PyPI
|
||||
uses: pypa/gh-action-pypi-publish@release/v1
|
||||
Reference in New Issue
Block a user