Skip to content

Commit

Permalink
add gh create release
Browse files Browse the repository at this point in the history
  • Loading branch information
Gogoshika-ga committed Oct 17, 2024
1 parent 977ee3b commit d1ead30
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Create Release
run-name: C++ SDK Release ${{ inputs.tag_name }}
# run-name: C++ SDK Release ${{ inputs.tag_name }}

on:
workflow_dispatch:
Expand All @@ -9,7 +9,6 @@ on:
required: true
type: string


jobs:
build:
uses: ./.github/workflows/cmake.yml
Expand Down
70 changes: 70 additions & 0 deletions gh_create_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import subprocess
import sys
import re

def run_command(command):
"""Run the specified command and handle errors."""
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(result.stdout)
return result.returncode
except subprocess.CalledProcessError as e:
print(f"Error occurred: {e.stderr}", file=sys.stderr)
return e.returncode

def trigger_workflow(tag_name):
"""Trigger the GitHub Actions workflow using GitHub CLI."""
# Set repository and branch
repo = "GameAnalytics/GA-SDK-CPP-NEW"
branch = "main"

# Construct the GitHub CLI command
command = f'gh workflow run "Create Release" --repo {repo} --ref {branch} -f tag_name={tag_name}'
print(f"Running command: {command}")

# Execute the command
return_code = run_command(command)

if return_code == 0:
print("Workflow triggered successfully.")
else:
print(f"Failed to trigger workflow. Return code: {return_code}")

def check_gh_cli_installed():
"""Check if GitHub CLI (gh) is installed and available in the system path."""
try:
subprocess.run(['gh', '--version'], capture_output=True, check=True)
return True
except FileNotFoundError:
return False

def validate_tag_name(tag_name):
"""Validate that the tag name matches the format 'v1.0.0'."""
pattern = r"^v\d+\.\d+\.\d+$"
if re.match(pattern, tag_name):
return True
else:
return False

def main():
# Ensure GitHub CLI is installed
if not check_gh_cli_installed():
print("GitHub CLI (gh) is not installed. Please install it and try again.")
sys.exit(1)

# Validate tag name passed as an argument
if len(sys.argv) != 2:
print("Usage: python trigger_workflow.py <tag_name>")
sys.exit(1)

tag_name = sys.argv[1]

if not validate_tag_name(tag_name):
print("Invalid tag name format. Please use the format 'v1.0.0'.")
sys.exit(1)

# Trigger the workflow with validated tag name
trigger_workflow(tag_name)

if __name__ == "__main__":
main()

0 comments on commit d1ead30

Please sign in to comment.