Skip to content

Commit e5d6eee

Browse files
authored
Fix infinite dispatch event (#28)
1 parent 848e164 commit e5d6eee

9 files changed

Lines changed: 70 additions & 45 deletions

File tree

.github/workflows/cd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: CD
44
on:
55
workflow_run:
66
workflows: ["CI"]
7-
branches: [main, eedorenko/fix-rate-limit]
7+
branches: [main]
88
types:
99
- completed
1010

.github/workflows/ci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
push:
66
branches:
77
- main
8-
- eedorenko/fix-rate-limit
98

109

1110
jobs:

.github/workflows/publish.yaml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
name: Publish
33

44
on:
5-
repository_dispatch:
6-
types: [sync-success]
7-
# workflow_run:
8-
# workflows: ["CI"]
9-
# branches: [main]
10-
# types:
11-
# - completed
5+
# repository_dispatch:
6+
# types: [sync-success]
7+
workflow_run:
8+
workflows: ["CI"]
9+
branches: [main]
10+
types:
11+
- completed
1212

1313
jobs:
1414
update_helm_chart:
@@ -18,33 +18,33 @@ jobs:
1818
steps:
1919
- name: Checkout
2020
uses: actions/checkout@v2.3.4
21-
# - name: Download Image Tags
22-
# uses: dawidd6/action-download-artifact@v2
23-
# with:
24-
# name: image_tags
25-
# workflow: ci.yml
26-
# # run_id: ${{ github.event.client_payload.runid }}
27-
# run_id: ${{ github.event.workflow_run.id }}
28-
# path: ${{ github.workspace }}
29-
# - name: Download Manifests
30-
# uses: dawidd6/action-download-artifact@v2
31-
# with:
32-
# name: manifests
33-
# workflow: ci.yml
34-
# # run_id: ${{ github.event.client_payload.runid }}
35-
# run_id: ${{ github.event.workflow_run.id }}
36-
# path: ${{ github.workspace }}
37-
# - name: Read Image Tags
38-
# run: |
39-
# echo "IMAGE_TAG=$(cat ${{ github.workspace }}/IMAGE_TAG)" >> $GITHUB_ENV
40-
# - name: Generate Manifests
41-
# run: |
42-
# .github/workflows/utils/generate-manifests.sh ${{ github.workspace }}/manifests gen_manifests hld_only
43-
# env:
44-
# APP_BUILD_VERSION: ${{ env.IMAGE_TAG }}
45-
# ORCHESTRATOR_PAT: ${{ secrets.ORCHESTRATOR_PAT }}
46-
# - name: Publish Helm Chart
47-
# run: |
48-
# .github/workflows/utils/publish_helm_chart.sh gen_manifests/hld/helm ${{ secrets.HELM_CHARTS_REPO_NAME }} ${{ secrets.HELM_CHARTS_URL }}
49-
# env:
50-
# TOKEN: ${{ secrets.HELM_CHARTS_PAT }}
21+
- name: Download Image Tags
22+
uses: dawidd6/action-download-artifact@v2
23+
with:
24+
name: image_tags
25+
workflow: ci.yml
26+
# run_id: ${{ github.event.client_payload.runid }}
27+
run_id: ${{ github.event.workflow_run.id }}
28+
path: ${{ github.workspace }}
29+
- name: Download Manifests
30+
uses: dawidd6/action-download-artifact@v2
31+
with:
32+
name: manifests
33+
workflow: ci.yml
34+
# run_id: ${{ github.event.client_payload.runid }}
35+
run_id: ${{ github.event.workflow_run.id }}
36+
path: ${{ github.workspace }}
37+
- name: Read Image Tags
38+
run: |
39+
echo "IMAGE_TAG=$(cat ${{ github.workspace }}/IMAGE_TAG)" >> $GITHUB_ENV
40+
- name: Generate Manifests
41+
run: |
42+
.github/workflows/utils/generate-manifests.sh ${{ github.workspace }}/manifests gen_manifests hld_only
43+
env:
44+
APP_BUILD_VERSION: ${{ env.IMAGE_TAG }}
45+
ORCHESTRATOR_PAT: ${{ secrets.ORCHESTRATOR_PAT }}
46+
- name: Publish Helm Chart
47+
run: |
48+
.github/workflows/utils/publish_helm_chart.sh gen_manifests/hld/helm ${{ secrets.HELM_CHARTS_REPO_NAME }} ${{ secrets.HELM_CHARTS_URL }}
49+
env:
50+
TOKEN: ${{ secrets.HELM_CHARTS_PAT }}

internal/setup/flux/sync.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ metadata:
77
spec:
88
interval: 30s
99
ref:
10-
branch: dev
10+
branch: main
1111
timeout: 20s
1212
url: https://github.com/kaizentm/gitops-manifests
1313
---
14-
apiVersion: kustomize.toolkit.fluxcd.io/v1beta1
14+
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
1515
kind: Kustomization
1616
metadata:
1717
name: gitops-connector-dev

src/gitops_connector.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ def __init__(self):
2626

2727
def process_gitops_phase(self, phase_data, req_time):
2828
if self._gitops_operator.is_supported_message(phase_data):
29-
self._queue_commit_statuses(phase_data, req_time)
30-
self._notify_orchestrator(phase_data)
29+
commit_id = self._gitops_operator.get_commit_id(phase_data)
30+
if not self._git_repository.is_commit_finished(commit_id):
31+
self._queue_commit_statuses(phase_data, req_time)
32+
self._notify_orchestrator(phase_data, commit_id)
3133
else:
3234
logging.debug(f'Message is not supported: {phase_data}')
3335

@@ -36,10 +38,9 @@ def _queue_commit_statuses(self, phase_data, req_time):
3638
for commit_status in commit_statuses:
3739
self._global_message_queue.put(item=(req_time, commit_status))
3840

39-
def _notify_orchestrator(self, phase_data):
41+
def _notify_orchestrator(self, phase_data, commit_id):
4042
is_finished, is_successful = self._gitops_operator.is_finished(phase_data)
4143
if is_finished:
42-
commit_id = self._gitops_operator.get_commit_id(phase_data)
4344
self._cicd_orchestrator.notify_on_deployment_completion(commit_id, is_successful)
4445

4546
# Entrypoint for the periodic task to search for abandoned PRs linked to

src/orchestrators/github_cicd_orchestrator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def _send_repo_dispatch_event(self, commmit_id, run_id):
3838
url = f'{self.rest_api_url}/{self.gitops_repo_name}/dispatches'
3939
event_type = 'sync-success'
4040
data = {'event_type': event_type, 'client_payload': {'sha': commmit_id, 'runid': run_id}}
41+
logging.info(f'Dispatch event: url {url}; data {data}')
4142
response = requests.post(url=url, headers=self.headers, json=data)
4243
# Throw appropriate exception if request failed
4344
response.raise_for_status()

src/repositories/azdo_git_repository.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,6 @@ def get_pr_num(self, commit_id) -> str:
129129
merged_pr_index = comment.index(MERGED_PR)
130130
pr_num = comment[merged_pr_index + len(MERGED_PR): comment.index(":", merged_pr_index)]
131131
return pr_num
132+
133+
def is_commit_finished(self, commit_id):
134+
return False

src/repositories/git_repository.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ def get_prs(self, pr_status):
2525
@abstractmethod
2626
def get_commit_message(self, commit_id):
2727
pass
28+
29+
@abstractmethod
30+
def is_commit_finished(self, commit_id):
31+
pass

src/repositories/github_git_repository.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ def post_commit_status(self, commit_status):
3232
# Throw appropriate exception if request failed
3333
response.raise_for_status()
3434

35+
def is_commit_finished(self, commit_id):
36+
url = f'{self.rest_api_url}/{self.gitops_repo_name}/commits/{commit_id}/status'
37+
38+
response = requests.get(url=url, headers=self.headers)
39+
# Throw appropriate exception if request failed
40+
response.raise_for_status()
41+
42+
responseJSON = response.json()
43+
44+
# logging.debug(f'Url {url}: Headers {self.headers}: Response {responseJSON}')
45+
46+
state = responseJSON['state']
47+
48+
logging.info(f'Commit {commit_id}: {state}')
49+
50+
return state == 'failure' or state == 'success'
51+
3552
def _map_to_github_state(self, reason):
3653
state_map = {
3754
"Suspended": "error",

0 commit comments

Comments
 (0)