💸Save up to $132K/month in CI costs!👉 Try Free
Skip to main content
← Back to workflows

How to Use Python Semantic Release with GitHub Action

python-semantic-release-python-semantic-release -
GitHub Action
v9.8.8
806
Contributors
Contributor - relekangContributor - codejedi365Contributor - actions-user

Optimize Your CI/CD Pipeline

Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.

45% Faster Builds
60% Cost Reduction
Usage
name: 'Usage of python-semantic-release GitHub Action'
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Python Semantic Release
# Adjust tag with desired version if applicable. Version shorthand
# is NOT available, e.g. vX or vX.X will not work.
uses: python-semantic-release/python-semantic-[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

python-semantic-release logo

python-semantic-release

Automatic semantic versioning for python projects


Python Semantic Release is an excellent tool for automating semantic versioning in Python projects. Inspired by the popular semantic-release for JavaScript created by Stephan Bönnemann, this Python implementation offers a seamless way to manage your project’s versioning based on commit messages. If you’re interested in learning more, you can check out Stephan’s talk from JSConf Budapest for a deeper dive into the concept.

How to Set Up Python Semantic Release on GitHub Actions

This GitHub Action simplifies the setup for Python Semantic Release in your CI pipeline. Here’s a basic example of how to configure it:

name: Semantic Release

on:
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest
concurrency: release
permissions:
id-token: write
contents: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Python Semantic Release
uses: python-semantic-release/python-semantic-[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

Concurrency Control prevents race conditions by ensuring only one release job runs at a time. Be sure to set fetch-depth: 0 to allow the action to access the full commit history for accurate versioning.

Multiple Project Support

If you have multiple projects within the same repository, or if your project is not located in the root directory, you can specify a different directory for each project. The directory input allows you to release each project individually by pointing to their respective paths.

Here’s an example of how you can release multiple projects using Python Semantic Release:

- name: Release Project 1
uses: python-semantic-release/python-semantic-[email protected]
with:
directory: ./project1
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Release Project 2
uses: python-semantic-release/python-semantic-[email protected]
with:
directory: ./project2
github_token: ${{ secrets.GITHUB_TOKEN }}

With this configuration, both Project 1 and Project 2 will be released separately. This is useful for repositories that contain multiple services or packages that are developed and released independently.