Skip to content

Commit 98fb08b

Browse files
committed
Add 🤖 publish and release workflow
1 parent 6d9345f commit 98fb08b

File tree

3 files changed

+272
-47
lines changed

3 files changed

+272
-47
lines changed

.github/workflows/publish_release.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Modify from https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
2+
# The tasks defined in this workflow are strictly follow the steps in README.md
3+
4+
# workflow name
5+
name: 📤 Publish and Release 🗳
6+
7+
# trigger event, receive a single event or list of events, i.e. [push, pull_request]
8+
on:
9+
push:
10+
tags:
11+
- "v*.*.*" # only trigger when push a tag with pattern "v*.*.*"
12+
13+
env:
14+
FORCE_COLOR: 1 # force color output
15+
16+
# Declare task list
17+
jobs:
18+
Build-distribution-packages: # task 1: build
19+
name: 📦 Build distribution # task 1 description
20+
runs-on: ubuntu-latest # operating system
21+
22+
steps: # Declare task steps
23+
- name: Fetch repository # Step 1: pull the repository to the runner
24+
uses: actions/checkout@v4
25+
26+
- name: Install Python # Step 2: install python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.x" # Step 2 parameters: python version
30+
31+
- name: Install packages used for building # Step 3: Install dependencies used for package building
32+
run: | # concrete commands, `|` is used to indicate a multi-line command
33+
python3 -m pip install setuptools build wheel isort ruff --user
34+
python3 -m pip install twine check-manifest --user
35+
36+
- name: Build distribution packages # Step 4: Build Python distribution packages.
37+
run: python3 -m build -v -n .
38+
39+
- name: Execute validation script # Step 5: validate metadate of the packages
40+
run: |
41+
chmod +x ./check_meta.sh
42+
bash ./check_meta.sh
43+
44+
- name: Check MANIFEST.in # Step 6: update MANIFEST.in
45+
run: |
46+
check-manifest -u -v
47+
48+
- name: Store the building results # Step 7: Upload building results to the Github server, in order to expose to other job.
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: build-results
52+
path: dist/
53+
if-no-files-found: error
54+
55+
Publish-PyPI: # task 2: publish to PyPI
56+
name: 📤 Publish to PyPI
57+
runs-on: ubuntu-latest
58+
59+
needs: Build-distribution-packages # wait for task 1 to finish
60+
61+
environment:
62+
name: pypi
63+
url: https://pypi.org/p/<package-name> # Replace <package-name> with your PyPI project name
64+
65+
permissions:
66+
id-token: write # IMPORTANT: mandatory for trusted publishing
67+
68+
steps:
69+
- name: Download all the dists
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: build-results # should be the same as the name in task 1
73+
path: dist/
74+
75+
- name: Upload to PyPI
76+
uses: pypa/gh-action-pypi-publish@release/v1
77+
78+
Publish-TestPyPI: # task 3: publish to TestPyPI
79+
name: 📤 Publish to TestPyPI
80+
runs-on: ubuntu-latest
81+
82+
needs: Build-distribution-packages # wait for task 1 to finish
83+
84+
environment:
85+
name: testpypi
86+
url: https://test.pypi.org/p/<package-name> # Replace <package-name> with your PyPI project name
87+
88+
permissions:
89+
id-token: write # IMPORTANT: mandatory for trusted publishing
90+
91+
steps:
92+
- name: Download all the dists
93+
uses: actions/download-artifact@v4
94+
with:
95+
name: build-results # should be the same as the name in task 1
96+
path: dist/
97+
98+
- name: Upload to TestPyPI
99+
uses: pypa/gh-action-pypi-publish@release/v1
100+
with:
101+
repository-url: https://test.pypi.org/legacy/
102+
103+
Github-Release: # task 4: create a Github Release
104+
name: 🗳 Create a Release
105+
runs-on: ubuntu-latest
106+
107+
needs: Build-distribution-packages # wait for task 3 to finish
108+
109+
permissions:
110+
contents: write # IMPORTANT: mandatory for making GitHub Releases
111+
112+
steps:
113+
- name: Fetch repository
114+
uses: actions/checkout@v4
115+
116+
- name: Generate Changelog # this step is to get the first entry divided by '---' in CHANGELOG.md
117+
run: |
118+
awk -v RS="---" 'NR==1{gsub(/\n+$/, ""); print}' CHANGELOG.md > ${{ github.workspace }}-RELEASE.txt
119+
cat ${{ github.workspace }}-RELEASE.txt
120+
121+
- name: Download all the dists
122+
uses: actions/download-artifact@v4
123+
with:
124+
name: build-results
125+
path: dist/
126+
127+
- name: Create GitHub Release
128+
env:
129+
GITHUB_TOKEN: ${{ github.token }}
130+
run: >- # multi-line command
131+
gh release create
132+
'${{ github.ref_name }}'
133+
--repo '${{ github.repository }}'
134+
--notes "$(cat ${{ github.workspace }}-RELEASE.txt)"
135+
136+
- name: Upload artifact to GitHub Release
137+
env:
138+
GITHUB_TOKEN: ${{ github.token }}
139+
# Upload to GitHub Release using the `gh` CLI.
140+
# `dist/` contains the built packages
141+
run: >-
142+
gh release upload
143+
'${{ github.ref_name }}' dist/**
144+
--repo '${{ github.repository }}'
145+

CHANGELOG.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
# v1.3.0
1+
<!-- # v1.3.1 -->
2+
3+
![](https://img.shields.io/badge/Version-v1.3.1-green)
4+
5+
## 🌟 Add
6+
7+
1. `.github/workflows/publish_release.yml` : enable continuous deployment(CD) workflows for automatic package building, publishing, and creating GitHub releases.
8+
9+
---
10+
11+
<!-- # v1.3.0 -->
212

313
![](https://img.shields.io/badge/Version-v1.3.0-green)
414

@@ -12,7 +22,7 @@
1222

1323
---
1424

15-
# v1.2.3
25+
<!-- # v1.2.3 -->
1626

1727
![](https://img.shields.io/badge/Version-v1.2.3-green)
1828

@@ -30,7 +40,7 @@
3040

3141
---
3242

33-
# v1.2.2
43+
<!-- # v1.2.2 -->
3444

3545
![](https://img.shields.io/badge/Version-v1.2.2-green)
3646

@@ -41,7 +51,7 @@
4151

4252
---
4353

44-
# v1.2.1
54+
<!-- # v1.2.1 -->
4555

4656
![](https://img.shields.io/badge/Version-v1.2.1-green)
4757

@@ -52,7 +62,7 @@
5262

5363
---
5464

55-
# v1.2.0
65+
<!-- # v1.2.0 -->
5666

5767
![](https://img.shields.io/badge/Version-v1.2.0-green)
5868

@@ -76,7 +86,7 @@ Please refer to steps `6` through `8` in [`README.md`](https://github.com/Ahzyua
7686

7787
---
7888

79-
# v1.1.0
89+
<!-- # v1.1.0 -->
8090

8191
![](https://img.shields.io/badge/Version-v1.1.0-green)
8292

@@ -92,7 +102,7 @@ Please refer to steps `6` through `8` in [`README.md`](https://github.com/Ahzyua
92102

93103
---
94104

95-
# v1.0.1
105+
<!-- # v1.0.1 -->
96106

97107
![](https://img.shields.io/badge/Version-v1.0.1-green)
98108

@@ -110,7 +120,7 @@ Please refer to steps `6` through `8` in [`README.md`](https://github.com/Ahzyua
110120

111121
---
112122

113-
# v1.0.0
123+
<!-- # v1.0.0 -->
114124

115125
![](https://img.shields.io/badge/Version-v1.0.0-green)
116126

0 commit comments

Comments
 (0)