Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add release workflow for PyPI #23

Merged
merged 1 commit into from
Jul 29, 2024
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
77 changes: 77 additions & 0 deletions .github/workflows/cd-pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Continuous delivery - PyPI

on:
release:
types: [released]

env:
REQUIRED_PACKAGES: make

jobs:
version-check:
name: Check versioning
runs-on: ubuntu-latest
container: python:3.9-slim
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install required packages
run: apt update && apt install -y ${REQUIRED_PACKAGES}
- name: Install Poetry
run: pip install poetry
- name: Create virtual environment
run: make install
- name: Check version tag format
shell: bash
run: |
VERSION_TAG="${{ github.event.release.tag_name }}"
if [[ $VERSION_TAG =~ ^v[0-9]+.[0-9]+.[0-9]+$ ]]; then exit 0; else exit 1; fi
- name: Check if version tag and package version are equal
shell: bash
run: |
VERSION_TAG="${{ github.event.release.tag_name }}"
PACKAGE_VERSION="v"$(poetry version --short)
if [ $VERSION_TAG == $PACKAGE_VERSION ]; then exit 0; else exit 1; fi
build:
name: Build
runs-on: ubuntu-latest
container: python:3.9-slim
needs: version-check
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install required packages
run: apt update && apt install -y ${REQUIRED_PACKAGES}
- name: Install Poetry
run: pip install poetry
- name: Create virtual environment
run: make install
- name: Build
run: poetry build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nitrokey-pypi
path: dist
publish-binary:
name: Publish
runs-on: ubuntu-latest
container: python:3.9-slim
needs: build
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
POETRY_PYPI_URL: https://upload.pypi.org/legacy/
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: nitrokey-pypi
path: dist
- name: Install Poetry
run: pip install poetry
- name: Configure PyPI repository
run: poetry config repositories.pypi $POETRY_PYPI_URL
- name: Publish release
run: poetry publish --repository pypi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
dist