Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Publish package

on:
workflow_dispatch:

jobs:
get-release-tag:
name: Get the package version
runs-on: ubuntu-latest
outputs:
package-version: ${{ steps.package-version.outputs.package-version }}
steps:
- name: Check out 🎉
uses: actions/checkout@v4.1.1
- name: Set up Python 🐍
uses: actions/setup-python@v4.7.1
with:
cache: pip
- name: Get the package version 🔖
id: package-version
run:
echo "package-version=$(python ./scripts/package_version.py)" >> "$GITHUB_OUTPUT"
pypi-publish:
needs: get-release-tag
name: Upload to PyPI
runs-on: ubuntu-latest
environment:
name: PyPI
url: https://pypi.org/p/python-gitmojis
permissions:
id-token: write
steps:
- name: Check out 🎉
uses: actions/checkout@v4.1.1
- name: Set up Python 🐍
uses: actions/setup-python@v4.7.1
with:
cache: pip
- name: Install PyPA `build` package 📦
run: |
python -m pip install --upgrade pip
python -m pip install build
- name: Build the package 👷
run:
python -m build
- name: Publish to PyPI 🚀
uses: pypa/gh-action-pypi-publish@v1.8.10
create-release-tag:
needs:
- get-release-tag
- pypi-publish
name: Create the release tag
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out 🎉
uses: actions/checkout@v4.1.1
- name: Create tag 🔖
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
git tag "${{ needs.get-release-tag.outputs.package-version }}"
git push --tags
publish-release:
needs:
- get-release-tag
- create-release-tag
name: Publish GitHub release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out 🎉
uses: actions/checkout@v4.1.1
- name: Publish GitHub Release 📝
uses: softprops/action-gh-release@v0.1.15
with:
tag_name: ${{ needs.get-release-tag.outputs.package-version }}
generate_release_notes: true
15 changes: 15 additions & 0 deletions scripts/package_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys
from pathlib import Path

import tomllib


def get_package_version() -> str:
"""Return the package version from the `pyproject.toml` metadata."""
with (Path.cwd() / "pyproject.toml").open("rb") as pyproject_toml:
metadata = tomllib.load(pyproject_toml)
return metadata["project"]["version"]


if __name__ == "__main__":
sys.stdout.write(get_package_version())