Skip to content

Commit fea7858

Browse files
authored
πŸ‘· Add a workflow publishing the package to PyPI (#20)
1 parent 80a14f5 commit fea7858

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Publish package
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
get-release-tag:
8+
name: Get the package version
9+
runs-on: ubuntu-latest
10+
outputs:
11+
package-version: ${{ steps.package-version.outputs.package-version }}
12+
steps:
13+
- name: Check out πŸŽ‰
14+
uses: actions/checkout@v4.1.1
15+
- name: Set up Python 🐍
16+
uses: actions/setup-python@v4.7.1
17+
with:
18+
cache: pip
19+
- name: Get the package version πŸ”–
20+
id: package-version
21+
run:
22+
echo "package-version=$(python ./scripts/package_version.py)" >> "$GITHUB_OUTPUT"
23+
pypi-publish:
24+
needs: get-release-tag
25+
name: Upload to PyPI
26+
runs-on: ubuntu-latest
27+
environment:
28+
name: PyPI
29+
url: https://pypi.org/p/python-gitmojis
30+
permissions:
31+
id-token: write
32+
steps:
33+
- name: Check out πŸŽ‰
34+
uses: actions/checkout@v4.1.1
35+
- name: Set up Python 🐍
36+
uses: actions/setup-python@v4.7.1
37+
with:
38+
cache: pip
39+
- name: Install PyPA `build` package πŸ“¦
40+
run: |
41+
python -m pip install --upgrade pip
42+
python -m pip install build
43+
- name: Build the package πŸ‘·
44+
run:
45+
python -m build
46+
- name: Publish to PyPI πŸš€
47+
uses: pypa/gh-action-pypi-publish@v1.8.10
48+
create-release-tag:
49+
needs:
50+
- get-release-tag
51+
- pypi-publish
52+
name: Create the release tag
53+
runs-on: ubuntu-latest
54+
permissions:
55+
contents: write
56+
steps:
57+
- name: Check out πŸŽ‰
58+
uses: actions/checkout@v4.1.1
59+
- name: Create tag πŸ”–
60+
run: |
61+
git config user.name "${{ github.actor }}"
62+
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
63+
git tag "${{ needs.get-release-tag.outputs.package-version }}"
64+
git push --tags
65+
publish-release:
66+
needs:
67+
- get-release-tag
68+
- create-release-tag
69+
name: Publish GitHub release
70+
runs-on: ubuntu-latest
71+
permissions:
72+
contents: write
73+
steps:
74+
- name: Check out πŸŽ‰
75+
uses: actions/checkout@v4.1.1
76+
- name: Publish GitHub Release πŸ“
77+
uses: softprops/action-gh-release@v0.1.15
78+
with:
79+
tag_name: ${{ needs.get-release-tag.outputs.package-version }}
80+
generate_release_notes: true

β€Žscripts/package_version.pyβ€Ž

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import sys
2+
from pathlib import Path
3+
4+
import tomllib
5+
6+
7+
def get_package_version() -> str:
8+
"""Return the package version from the `pyproject.toml` metadata."""
9+
with (Path.cwd() / "pyproject.toml").open("rb") as pyproject_toml:
10+
metadata = tomllib.load(pyproject_toml)
11+
return metadata["project"]["version"]
12+
13+
14+
if __name__ == "__main__":
15+
sys.stdout.write(get_package_version())

0 commit comments

Comments
Β (0)