|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Script to extract action sections from existing files and create new organized files |
| 4 | +""" |
| 5 | + |
| 6 | +import re |
| 7 | +import os |
| 8 | + |
| 9 | +BASE_DIR = "src/content/docs/workflow-automation/setup-and-configuration/actions-catalog" |
| 10 | + |
| 11 | +# Define file extractions mapping |
| 12 | +# Format: (source_file, line_start, line_end, dest_file, title_suffix, description) |
| 13 | +AWS_EXTRACTIONS = [ |
| 14 | + # EC2 |
| 15 | + ("aws.mdx", 773, 1449, "aws-ec2.mdx", "AWS EC2 actions", "EC2 instance and snapshot management"), |
| 16 | + # SystemsManager |
| 17 | + ("aws.mdx", 1451, 2341, "aws-systemsmanager.mdx", "AWS Systems Manager actions", "Systems Manager automation and document operations"), |
| 18 | + # Execute API |
| 19 | + ("aws.mdx", 2343, 2720, "aws-execute-api.mdx", "AWS Execute API", "Execute any AWS API operation"), |
| 20 | + # CloudWatch |
| 21 | + ("aws.mdx", 2721, 3110, "aws-cloudwatch.mdx", "AWS CloudWatch actions", "CloudWatch Logs operations"), |
| 22 | + # S3 |
| 23 | + ("aws.mdx", 3111, 4311, "aws-s3.mdx", "AWS S3 actions", "S3 bucket and object operations"), |
| 24 | + # SNS |
| 25 | + ("aws.mdx", 4312, 4549, "aws-sns.mdx", "AWS SNS actions", "SNS topic operations"), |
| 26 | + # SQS |
| 27 | + ("aws.mdx", 4550, 4914, "aws-sqs.mdx", "AWS SQS actions", "SQS queue operations"), |
| 28 | +] |
| 29 | + |
| 30 | +HTTP_EXTRACTIONS = [ |
| 31 | + ("http.mdx", 34, 180, "http-get.mdx", "HTTP GET", "HTTP GET request operations"), |
| 32 | + ("http.mdx", 181, 337, "http-post.mdx", "HTTP POST", "HTTP POST request operations"), |
| 33 | + ("http.mdx", 338, 505, "http-put.mdx", "HTTP PUT", "HTTP PUT request operations"), |
| 34 | + ("http.mdx", 506, 665, "http-delete.mdx", "HTTP DELETE", "HTTP DELETE request operations"), |
| 35 | +] |
| 36 | + |
| 37 | +NEWRELIC_EXTRACTIONS = [ |
| 38 | + ("new-relic.mdx", 30, 353, "newrelic-ingest.mdx", "New Relic Ingest actions", "Send events and logs to New Relic"), |
| 39 | + ("new-relic.mdx", 355, 520, "newrelic-nerdgraph.mdx", "New Relic NerdGraph actions", "Execute NerdGraph queries and mutations"), |
| 40 | + ("new-relic.mdx", 522, 626, "newrelic-nrdb.mdx", "New Relic NRDB actions", "Query New Relic database"), |
| 41 | + ("new-relic.mdx", 628, 1133, "newrelic-notification.mdx", "New Relic Notification actions", "Send notifications through New Relic"), |
| 42 | +] |
| 43 | + |
| 44 | +COMMUNICATION_EXTRACTIONS = [ |
| 45 | + ("communication.mdx", 32, 445, "slack-chat.mdx", "Slack Chat actions", "Slack messaging operations"), |
| 46 | +] |
| 47 | + |
| 48 | +PAGERDUTY_EXTRACTIONS = [ |
| 49 | + ("pagerduty.mdx", 23, 1016, "pagerduty-incident.mdx", "PagerDuty Incident actions", "PagerDuty incident management"), |
| 50 | +] |
| 51 | + |
| 52 | +UTILS_EXTRACTIONS = [ |
| 53 | + ("others.mdx", 14, 197, "utils-datetime.mdx", "Utilities - DateTime", "Date and time utilities"), |
| 54 | + ("others.mdx", 199, 320, "utils-transform.mdx", "Utilities - Transform", "Data transformation utilities"), |
| 55 | + ("others.mdx", 322, 420, "utils-uuid.mdx", "Utilities - UUID", "UUID generation utilities"), |
| 56 | +] |
| 57 | + |
| 58 | +def read_file_lines(filepath, start_line, end_line): |
| 59 | + """Read specific lines from a file""" |
| 60 | + with open(filepath, 'r') as f: |
| 61 | + lines = f.readlines() |
| 62 | + return ''.join(lines[start_line-1:end_line]) |
| 63 | + |
| 64 | +def get_prerequisites(source_file): |
| 65 | + """Extract prerequisites section from source file""" |
| 66 | + with open(source_file, 'r') as f: |
| 67 | + content = f.read() |
| 68 | + match = re.search(r'## Prerequisites.*?(?=##|\Z)', content, re.DOTALL) |
| 69 | + if match: |
| 70 | + return match.group(0) |
| 71 | + return "" |
| 72 | + |
| 73 | +def create_file(source_file, start_line, end_line, dest_file, title, description): |
| 74 | + """Create a new action file from extracted content""" |
| 75 | + source_path = os.path.join(BASE_DIR, source_file) |
| 76 | + dest_path = os.path.join(BASE_DIR, dest_file) |
| 77 | + |
| 78 | + # Get prerequisites |
| 79 | + prereqs = get_prerequisites(source_path) |
| 80 | + |
| 81 | + # Get action content |
| 82 | + action_content = read_file_lines(source_path, start_line, end_line) |
| 83 | + |
| 84 | + # Create frontmatter |
| 85 | + tags_base = [ |
| 86 | + "workflow automation", |
| 87 | + "workflow", |
| 88 | + "workflow automation actions", |
| 89 | + ] |
| 90 | + |
| 91 | + if "aws" in dest_file.lower(): |
| 92 | + tags_base.extend(["AWS actions", f"{title}"]) |
| 93 | + elif "http" in dest_file.lower(): |
| 94 | + tags_base.extend(["HTTP actions", f"{title}"]) |
| 95 | + elif "newrelic" in dest_file.lower(): |
| 96 | + tags_base.extend(["New Relic actions", f"{title}"]) |
| 97 | + elif "slack" in dest_file.lower(): |
| 98 | + tags_base.extend(["Slack actions", "communication actions", f"{title}"]) |
| 99 | + elif "pagerduty" in dest_file.lower(): |
| 100 | + tags_base.extend(["PagerDuty actions", f"{title}"]) |
| 101 | + elif "utils" in dest_file.lower(): |
| 102 | + tags_base.extend(["utility actions", f"{title}"]) |
| 103 | + |
| 104 | + tags_str = "\n - ".join(tags_base) |
| 105 | + |
| 106 | + frontmatter = f"""--- |
| 107 | +title: "{title}" |
| 108 | +tags: |
| 109 | + - {tags_str} |
| 110 | +metaDescription: "A list of available {title.lower()} in the actions catalog for workflow definitions" |
| 111 | +freshnessValidatedDate: never |
| 112 | +--- |
| 113 | +
|
| 114 | +<Callout title="preview"> |
| 115 | + We're still working on this feature, but we'd love for you to try it out! |
| 116 | +
|
| 117 | + This feature is currently provided as part of a preview program pursuant to our [pre-release policies](/docs/licenses/license-information/referenced-policies/new-relic-pre-release-policy). |
| 118 | +</Callout> |
| 119 | +
|
| 120 | +This page provides a comprehensive reference for {title.lower()} available in the workflow automation actions catalog. These actions enable you to {description.lower()}. |
| 121 | +
|
| 122 | +""" |
| 123 | + |
| 124 | + # Write the file |
| 125 | + with open(dest_path, 'w') as f: |
| 126 | + f.write(frontmatter) |
| 127 | + if prereqs: |
| 128 | + f.write(prereqs + "\n\n") |
| 129 | + f.write(action_content) |
| 130 | + |
| 131 | + print(f"Created: {dest_file}") |
| 132 | + |
| 133 | +def main(): |
| 134 | + """Main execution""" |
| 135 | + print("Starting extraction...") |
| 136 | + |
| 137 | + # Process all extractions |
| 138 | + all_extractions = ( |
| 139 | + AWS_EXTRACTIONS + |
| 140 | + HTTP_EXTRACTIONS + |
| 141 | + NEWRELIC_EXTRACTIONS + |
| 142 | + COMMUNICATION_EXTRACTIONS + |
| 143 | + PAGERDUTY_EXTRACTIONS + |
| 144 | + UTILS_EXTRACTIONS |
| 145 | + ) |
| 146 | + |
| 147 | + for source, start, end, dest, title, desc in all_extractions: |
| 148 | + try: |
| 149 | + create_file(source, start, end, dest, title, desc) |
| 150 | + except Exception as e: |
| 151 | + print(f"Error creating {dest}: {e}") |
| 152 | + |
| 153 | + print("\nExtraction complete!") |
| 154 | + |
| 155 | +if __name__ == "__main__": |
| 156 | + main() |
0 commit comments