Skip to content

Instantly share code, notes, and snippets.

@bpgould
Last active October 27, 2022 18:00
Show Gist options
  • Save bpgould/a6673d7377402accdb1f2da12084b36a to your computer and use it in GitHub Desktop.
Save bpgould/a6673d7377402accdb1f2da12084b36a to your computer and use it in GitHub Desktop.
bash regex to parse semver
#!/bin/bash
# fancy regex will parse 0.8.39, can be used to parse semver
VERSION_FROM_SETUP=$(sed -n 's/^ *version="\([^"]*\).*/\1/p' setup.py)
# example setup.py file, start multi-line comment
: '
import setuptools
import os
setuptools.setup(
name="project",
version="0.8.39",
author="Tom, Nancy",
author_email="email@email.com",
description="A CI/CD Automation Platform",
url="https://github.com/link",
install_requires=[
'click>=7',
'requests==2.21.0',
'pyyaml>=5.3',
'dependency-check==0.6.0'
]
...
)
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment