DEV Community

loading...
Cover image for PyPI release using GitHub Actions
Leading EDJE

PyPI release using GitHub Actions

Andrew May
I used to be a developer, but these days I spend most of my time building and architecting Cloud Infrastructure.
・1 min read

My Workflow

I'm making use of the release event in a GitHub action to release my open source stackmanager project to PyPI. This allows me to use the GitHub tag name for the PyPI release and just have one place to manage versions.

I don't always want to release a new version after a PR is merged to master, so this gives me manual control over releases.

This has been my first time using GitHub Actions and I've been generally pleased with how it worked but found some of the documentation to be a bit cryptic.

Submission Category:

Maintainer Must-Haves

Yaml File or Link to Code

GitHub logo LeadingEDJE / stackmanager

Utility for managing Cloudformation stacks

stackmanager

PyPI version Coverage Status

Utility to manage CloudFormation stacks based upon a Template (either local or in S3) and a YAML configuration file.

Uses ChangeSets to create or update CloudFormation stacks, allowing the ChangeSets to either be automatically applied or applied later (e.g. during a later phase of a build pipeline after review of the ChangeSet).

There are also some utility methods for building a lambda file zip and uploading files to S3 These are to provide some of the AWS SAM CLI functionality while fitting into the workflow and configuration style of stackmanager.

Configuration

The configuration file can either be a single YAML document containing the configuration for a stack for a specific environment and region, or can contain multiple documents for different deployments of that stack to different environments and regions.

Single Environment

The configuration combines together the different values that are typically passed to the CloudFormation command line when creating…

Specifically, the release.yml workflow is triggered on release.

Additional Info

The version of the release is taken from the github.event.release.tag_name property of the release event and passed to setup.py as the STACKMANAGER_VERSION environment variable.

I'm using a PyPI API token restricted to this project so that I don't have to store a username and password in GitHub secrets (this also allows me to turn on 2FA for my PyPI account).

    - name: Package and Upload
      env:
        STACKMANAGER_VERSION: ${{ github.event.release.tag_name }}
        TWINE_USERNAME: __token__
        TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
      run: |
        python setup.py sdist bdist_wheel
        twine upload dist/*

Discussion (1)

Collapse
eitchtee profile image
Herculino Trotta

I have a very similar action for my packages, but I've been bumping versions manually for all this time, this changes everything.

Great work!

Forem Open with the Forem app