Skip to content

Commit

Permalink
more robust parsing of dpcolor to a semver (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
theganyo authored Sep 28, 2023
1 parent 367fc3e commit 1b352db
Showing 1 changed file with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Set the "runtime_version" flow variable to a semver-style version made
by splitting APIGEE_DPCOLOR by "-" and concatenating the first three
segments that are digits. If this fails, the var is set to "unknown."
"""

import os

version = os.environ.get("APIGEE_DPCOLOR", "")

if len(version) > 0:
dig = [c for c in version if c.isdigit()]
flow.setVariable("runtime_version", ".".join(dig[0:3]))
else:
flow.setVariable("runtime_version", "unknown")
def make_semver(version_string):
if not version_string:
return "unknown"

nums = []
for segment in version_string.split("-"):
try:
int(segment)
nums.append(segment)
except ValueError:
pass

if len(nums) < 3:
return "unknown"

return ".".join(nums[:3])


dp_color = os.environ.get("APIGEE_DPCOLOR", "")
semver = make_semver(dp_color)
flow.setVariable("runtime_version", semver)

0 comments on commit 1b352db

Please sign in to comment.