Skip to content

Instantly share code, notes, and snippets.

@bsnacks000
Created December 16, 2021 14:53
Show Gist options
  • Select an option

  • Save bsnacks000/814e955f1cfec6a706a1188c79823362 to your computer and use it in GitHub Desktop.

Select an option

Save bsnacks000/814e955f1cfec6a706a1188c79823362 to your computer and use it in GitHub Desktop.
version tag for github CI workflows with poetry
"""
Assuming you have pyproject.toml we will read in the current version tag into the environment tag: VERSION_TAG
This will be available in your workflow now.
Place this at the root of .github folder
"""
import toml
import os
import sys
import logging
l = logging.getLogger(__name__)
if __name__ == '__main__':
rootdir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
try:
proj = toml.load(os.path.join(rootdir, 'pyproject.toml'))
except IOError as err:
l.error(err)
sys.exit(1)
try:
num = proj['tool']['poetry']['version']
print(f"VERSION_TAG={num}")
except KeyError as err:
l.error(err)
sys.exit(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment