Skip to content

Commit 7343653

Browse files
committed
ci(publish): add publish.yml ci for publishing to pypi
1 parent de61841 commit 7343653

File tree

3 files changed

+97
-7
lines changed

3 files changed

+97
-7
lines changed

.github/workflows/docs.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# copy from: https://github.com/frankie567/httpx-ws/blob/main/.github/workflows/docs.yml
22

3-
name: Build documentation
3+
name: Deploy documentation
44

5+
6+
# Since document updates may be frequent,
7+
# we do not run tests when deploying documents,
8+
# instead test during the PR stage.
59
on:
610
push:
711
branches:
@@ -19,7 +23,7 @@ defaults:
1923
shell: bash
2024

2125
jobs:
22-
build:
26+
build-docs:
2327
runs-on: ubuntu-latest
2428
steps:
2529
- uses: actions/checkout@v4
@@ -41,8 +45,8 @@ jobs:
4145
with:
4246
path: ./site
4347

44-
deploy:
45-
needs: build
48+
deploy-docs:
49+
needs: build-docs
4650
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
4751
permissions:
4852
pages: write # to deploy to Pages

.github/workflows/lint-test.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
# WARNING: Do not change the name of this file, keep `lint-test.yml`.
2+
13
name: Lint check and test
24

5+
6+
# We only automatically run checks for PRs.
7+
# It is best to avoid direct commits to the main branch, instead make a PR for checks.
8+
# For the pushes to the main branch, the checks is done by `publish.yml` when publish.
39
on:
4-
push:
5-
branches: ["main"]
610
pull_request:
7-
branches: ["main"]
811
workflow_dispatch:
12+
# NOTE: set `secrets: inherit` when call this workflow from other workflow.
13+
workflow_call:
14+
915

1016
jobs:
1117
lint-check:

.github/workflows/publish.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# refer to: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
2+
3+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
4+
5+
# NOTE: We do not restrict branches here,
6+
# instead restrict branches in the `environment` - `pypi`.
7+
on:
8+
push:
9+
tags:
10+
- v*
11+
12+
jobs:
13+
lint-test:
14+
name: Lint check and test 🧪
15+
uses: ./.github/workflows/lint-test.yml
16+
secrets: inherit # IMPORTANT: sub-workflow needs secrets for uploading codecov
17+
18+
build-dist:
19+
needs:
20+
- lint-test
21+
name: Build distribution 📦
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up Python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: "3.10"
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install hatch
33+
- name: Build a binary wheel and a source tarball
34+
run: |
35+
hatch build
36+
- name: Store the distribution packages
37+
uses: actions/upload-artifact@v3
38+
with:
39+
name: python-package-distributions
40+
path: dist/
41+
if-no-files-found: error
42+
43+
publish-to-pypi:
44+
needs:
45+
- build-dist
46+
name: Publish Python 🐍 distribution 📦 to PyPI
47+
runs-on: ubuntu-latest
48+
environment:
49+
name: pypi
50+
url: https://pypi.org/p/fastapi-proxy-lib
51+
permissions:
52+
id-token: write # IMPORTANT: mandatory for trusted publishing
53+
steps:
54+
- name: Download all the dists
55+
uses: actions/download-artifact@v3
56+
with:
57+
name: python-package-distributions
58+
path: dist/
59+
- name: Publish distribution 📦 to PyPI
60+
uses: pypa/gh-action-pypi-publish@release/v1
61+
62+
github-release:
63+
needs:
64+
- publish-to-pypi
65+
name: Create GitHub release 🏷️
66+
runs-on: ubuntu-latest
67+
permissions:
68+
contents: write # IMPORTANT: mandatory for creating release
69+
steps:
70+
- name: Download all the dists
71+
uses: actions/download-artifact@v3
72+
with:
73+
name: python-package-distributions
74+
path: dist/
75+
- name: Create release
76+
uses: ncipollo/release-action@v1
77+
with:
78+
draft: true
79+
body: ${{ github.event.head_commit.message }}
80+
artifacts: dist/*.whl,dist/*.tar.gz

0 commit comments

Comments
 (0)