-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GitHub Actions workflow triggers and enhance Terraform conf…
…igurations for automated cluster setup
- Loading branch information
Showing
6 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| terraform { | ||
| required_providers { | ||
| github = { | ||
| source = "integrations/github" | ||
| version = ">= 5.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "github" { | ||
| # Configuration is expected from environment variables: | ||
| # GITHUB_TOKEN | ||
| # GITHUB_OWNER (optional) | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/usr/bin/env python3 | ||
| import os | ||
| import sys | ||
| import requests | ||
| import json | ||
|
|
||
| def trigger_workflow(repo, event_type, payload=None): | ||
| token = os.environ.get('GITHUB_TOKEN') | ||
| if not token: | ||
| print("Error: GITHUB_TOKEN environment variable not set") | ||
| sys.exit(1) | ||
|
|
||
| owner = os.environ.get('GITHUB_OWNER', 'default-org') | ||
| server_url = os.environ.get('GITHUB_SERVER_URL', 'https://api.github.com') | ||
|
|
||
| # Remove trailing slash if present and ensure we're using the API endpoint | ||
| server_url = server_url.rstrip('/') | ||
| if not server_url.endswith('/api/v3') and not 'api.github.com' in server_url: | ||
| server_url = f"{server_url}/api/v3" | ||
|
|
||
| url = f"{server_url}/repos/{owner}/{repo}/dispatches" | ||
|
|
||
| headers = { | ||
| 'Accept': 'application/vnd.github.v3+json', | ||
| 'Authorization': f'token {token}', | ||
| 'Content-Type': 'application/json', | ||
| } | ||
|
|
||
| data = { | ||
| 'event_type': event_type, | ||
| 'client_payload': payload or {} | ||
| } | ||
|
|
||
| response = requests.post(url, headers=headers, data=json.dumps(data), verify=True) | ||
|
|
||
| if response.status_code == 204: | ||
| print(f"Successfully triggered workflow {event_type} for {owner}/{repo}") | ||
| return True | ||
| else: | ||
| print(f"Failed to trigger workflow: {response.status_code}") | ||
| print(response.text) | ||
| return False | ||
|
|
||
| if __name__ == "__main__": | ||
| if len(sys.argv) < 3: | ||
| print("Usage: trigger_workflow.py <repo> <event_type> [<payload_json>]") | ||
| sys.exit(1) | ||
|
|
||
| repo = sys.argv[1] | ||
| event_type = sys.argv[2] | ||
| payload = json.loads(sys.argv[3]) if len(sys.argv) > 3 else None | ||
|
|
||
| # First trigger requirements installation | ||
| if not trigger_workflow(repo, "install-requirements"): | ||
| sys.exit(1) | ||
|
|
||
| # Then trigger the main workflow | ||
| if not trigger_workflow(repo, event_type, payload): | ||
| sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters