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
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.
Monitoring GitHub Actions Workflows
CICube is a GitHub Actions monitoring tool that provides you with detailed insights into your workflows to further optimize your CI/CD pipeline. With CICube, you will be able to track your workflow runs, understand where the bottlenecks are, and tease out the best from your build times. Go to cicube.io now and create a free account to better optimize your GitHub Actions workflows!