Skip to content

Instantly share code, notes, and snippets.

@clarkritchie
Created December 12, 2023 20:35
Show Gist options
  • Save clarkritchie/a347d3fe9c72f47d9ece95f4dda38536 to your computer and use it in GitHub Desktop.
Save clarkritchie/a347d3fe9c72f47d9ece95f4dda38536 to your computer and use it in GitHub Desktop.
Python in GitHub Action
- name: Check release type
id: is-patch-release
# The -u means 'unbuffered', so print() statements in your python code are output correctly
# otherwise, they might be out of order with stdout from commands your code calls
# {0} is replaced with the name of the temporary file GitHub Actions creates with
# the contents of the run:
shell: python -u {0}
run: |
import os
import re
env_file = os.getenv('GITHUB_ENV')
#
# do whatever you need to do here
#
if "patch" in message:
level="patch"
if "minor" in message:
level="minor"
if "major" in message:
level="major"
if level is not None:
with open(env_file, "a") as f:
f.write(f"level={level}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment