Skip to content

Commit 1b09d91

Browse files
Try auto release dispatcher (AST-000)
1 parent 2541b5d commit 1b09d91

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

.github/scripts/dispatch_event.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import os
22
import requests
33

4-
def main():
5-
repo = os.getenv('REPO')
6-
cli_version = os.getenv('CLI_VERSION')
7-
github_token = os.getenv('GITHUB_TOKEN')
4+
def trigger_github_workflow(org, repo, cli_version, github_token):
5+
"""
6+
Trigger a GitHub Actions workflow using the repository_dispatch event.
87
9-
if not repo or not github_token:
10-
raise ValueError("REPO and GITHUB_TOKEN environment variables must be set.")
11-
12-
api_url = f"https://api.github.com/repos/{repo}/dispatches"
8+
:param org: GitHub organization or user name (e.g., 'Checkmarx')
9+
:param repo: Repository name (e.g., 'ast-github-action')
10+
:param cli_version: The CLI version to be dispatched
11+
:param github_token: Personal Access Token (PAT) with appropriate permissions
12+
"""
13+
url = f'https://api.github.com/repos/{org}/{repo}/dispatches'
1314
headers = {
14-
'Accept': 'application/vnd.github+json',
15+
'Accept': 'application/vnd.github.v3+json',
1516
'Authorization': f'token {github_token}'
1617
}
1718
payload = {
@@ -21,11 +22,20 @@ def main():
2122
}
2223
}
2324

24-
response = requests.post(api_url, headers=headers, json=payload)
25+
response = requests.post(url, json=payload, headers=headers)
2526
if response.status_code == 204:
26-
print(f"Successfully dispatched event to {repo}")
27+
print(f'Success: Dispatched event to {org}/{repo}.')
2728
else:
28-
print(f"Failed to dispatch event to {repo}: {response.status_code} {response.text}")
29+
print(f'Error: Failed to dispatch event to {org}/{repo}. Status code: {response.status_code}')
30+
print(f'Response: {response.json()}')
2931

3032
if __name__ == "__main__":
31-
main()
33+
GH_ORG = os.getenv('GH_ORG')
34+
GH_REPO = os.getenv('GH_REPO')
35+
CLI_VERSION = os.getenv('CLI_VERSION', '')
36+
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
37+
38+
if not GH_ORG or not GH_REPO or not GITHUB_TOKEN:
39+
raise ValueError("GH_ORG, GH_REPO, and GITHUB_TOKEN environment variables must be set.")
40+
41+
trigger_github_workflow(GH_ORG, GH_REPO, CLI_VERSION, GITHUB_TOKEN)

.github/workflows/dispatch-workflow.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ jobs:
2424

2525
- name: Trigger Update Event On Java Wrapper Repo
2626
env:
27-
REPO: 'https://github.com/CheckmarxDev/ast-cli-java-wrapper'
27+
GH_ORG: 'CheckmarxDev',
28+
GH_REPO: 'ast-cli-java-wrapper'
2829
CLI_VERSION: ${{ inputs.cli_version }}
29-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
GITHUB_TOKEN: ${{ secrets.DISPATCH_GH_TOKEN }}
3031
run: python ./.github/scripts/dispatch_event.py
3132

3233
update_github_action:
@@ -43,8 +44,9 @@ jobs:
4344

4445
- name: Trigger Update Event On Github Action Repo
4546
env:
46-
REPO: 'https://github.com/Checkmarx/ast-github-action'
47+
GH_ORG: 'Checkmarx',
48+
GH_REPO: 'ast-github-action'
4749
CLI_VERSION: ${{ inputs.cli_version }}
48-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
GITHUB_TOKEN: ${{ secrets.DISPATCH_GH_TOKEN }}
4951
run: python ./.github/scripts/dispatch_event.py
5052

0 commit comments

Comments
 (0)