-
Notifications
You must be signed in to change notification settings - Fork 18
174 lines (151 loc) · 7.42 KB
/
Sync-integration-definition.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Sync with integration-definitions
on:
push:
branches: [master]
paths:
- 'otel-integration/k8s-helm/Chart.yaml'
workflow_dispatch:
jobs:
Get_vesrion:
runs-on: ubuntu-latest
name: Get the new version
outputs:
Chart_version: "${{ steps.New_version.outputs.Chart_version }}"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get the new version
id: New_version
run: |
Chart_version=$(cat ./otel-integration/k8s-helm/Chart.yaml | grep "^version" | grep -oE '[^ ]+$')
echo "Chart_version=$Chart_version" >> $GITHUB_OUTPUT
commit_changes:
runs-on: ubuntu-latest
needs: Get_vesrion
steps:
- name: Checkout destination repository
uses: actions/checkout@v4
with:
repository: coralogix/integration-definitions
token: ${{ secrets.GH_TOKEN }}
- name: Check if version exists
id: version_exist
run: |
git fetch origin
template_version=${{ needs.Get_vesrion.outputs.Chart_version }}
if [ -d "./integrations/otel-agent-k8s/v$template_version" ]; then
echo "version exist"
echo "new_version_exist=true" >> $GITHUB_ENV
else
echo "new_version_exist=false" >> $GITHUB_ENV
echo "version Not exist"
fi
- name: Create files for the new version
if: "${{env.new_version_exist == 'false' || github.event_name == 'workflow_dispatch'}}"
run: |
branch_name="sync-telemetry-branch-$(date +"%m-%d-%H-%M")"
echo "branch_name=$branch_name" >> $GITHUB_ENV
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git checkout -b $branch_name
git pull origin master
git fetch origin
git push origin $branch_name
current_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
template_version=${{ needs.Get_vesrion.outputs.Chart_version }}
mkdir -p integrations/otel-agent-k8s/v${template_version}
last_version=$(grep "revision: " ./integrations/otel-agent-k8s/manifest.yaml | tail -n 1 | grep -oE '[^ ]+$')
cp integrations/otel-agent-k8s/v$last_version/commands.yaml integrations/otel-agent-k8s/v${template_version}/
cp integrations/otel-agent-k8s/v$last_version/fields.yaml integrations/otel-agent-k8s/v${template_version}/
cp integrations/otel-agent-k8s/v$last_version/integration_guide.yaml integrations/otel-agent-k8s/v${template_version}/
sed -i "s/--version=[^[:space:]]*/--version=$template_version/" integrations/otel-agent-k8s/v${template_version}/commands.yaml
if [ -f ./integrations/otel-agent-k8s/manifest.yaml ]; then
echo " - revision: ${template_version}
template:
type: HelmChart
commands: v${template_version}/commands.yaml
integration_guide: v${template_version}/integration_guide.yaml
field_definitions: v${template_version}/fields.yaml
published_at: $current_time" >> integrations/otel-agent-k8s/manifest.yaml
fi
git add .
merged_pr_from_telemetry_shipper=$(curl -s \
"https://api.github.com/repos/coralogix/telemetry-shippers/pulls?state=closed&base=master&sort=updated&direction=desc" \
| jq -r '.[0].title')
if [ "${{ github.event_name }}" == 'workflow_dispatch' ] || [ -z "$merged_pr_from_telemetry_shipper" ]; then
merged_pr_from_telemetry_shipper="sync-from-telemetry-shippers"
fi
echo "commit_message=$merged_pr_from_telemetry_shipper" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: commit change
if: "${{env.new_version_exist == 'false' || github.event_name == 'workflow_dispatch'}}"
uses: planetscale/[email protected]
with:
commit_message: ${{env.commit_message}}
repo: coralogix/integration-definitions
branch: ${{ env.branch_name }}
file_pattern: '*.yaml *.md'
env:
GITHUB_TOKEN: ${{secrets.GH_TOKEN}}
- name: Create pull request
if: "${{ env.new_version_exist == 'false' || github.event_name == 'workflow_dispatch' }}"
run: |
# Fetch the latest closed pull request title
Pr_name=$(curl -s "https://api.github.com/repos/coralogix/telemetry-shippers/pulls?state=closed&base=master&sort=updated&direction=desc" \
| jq -r '.[0].title')
# Set a default title if running on workflow_dispatch or if no recent PR title is found
if [ -z "$Pr_name" ]; then
Pr_name="sync-from-telemetry-shippers"
fi
# Fetch the URL of the latest closed pull request
pr_url=$(curl -s \
"https://api.github.com/repos/coralogix/telemetry-shippers/pulls?state=closed&base=master&sort=updated&direction=desc" \
| jq -r '.[0].html_url')
# Fetch the body of the latest closed pull request
pr_body=$(curl -s \
"https://api.github.com/repos/coralogix/telemetry-shippers/pulls?state=closed&base=master&sort=updated&direction=desc" \
| jq -r '.[0].body')
# Set a default body if no recent PR body is found
if [ -z "$pr_body" ]; then
pr_body="This pull request syncs the changes from the telemetry-shippers repo to this repo. link to the original PR $pr_url **dummy ticket to pass ticket validate[cds-1708]**"
else
pr_body="Link to the original PR: $pr_url $pr_body **dummy ticket to pass ticket validate[cds-1708]**"
fi
# Create the new pull request with the title and body
gh pr create --base master --head "${{ env.branch_name }}" --title "${Pr_name}" --body "$pr_body"
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Merge pull request
if: "${{env.new_version_exist == 'false' || github.event_name == 'workflow_dispatch'}}"
run: |
check_status() {
gh pr checks ${{ env.branch_name }} --json state --jq 'all(.[]; .state == "SUCCESS")'
}
# Initialize the timeout variables
max_wait_time=$((10 * 60)) # 10 minutes in seconds
elapsed_time=0
sleep_interval=10 # Interval between checks in seconds
# Loop until all status checks are successful or timeout occurs
echo "Waiting for all status checks to pass..."
# Wait for 5 seconds before checking the status
sleep 5
while true; do
status=$(check_status)
if [ "$status" == "true" ]; then
echo "All status checks passed. Merging the pull request..."
break
fi
if [ "$elapsed_time" -ge "$max_wait_time" ]; then
echo "Timeout reached: Status checks did not pass within 10 minutes."
exit 1
fi
echo "Not all checks passed yet. Waiting for $sleep_interval seconds..."
sleep $sleep_interval
elapsed_time=$((elapsed_time + sleep_interval))
done
# Merge the pull request
gh pr merge --delete-branch --admin --squash ${{ env.branch_name }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}