-
Notifications
You must be signed in to change notification settings - Fork 0
239 lines (216 loc) · 9.28 KB
/
ci-hourly-check.yaml
File metadata and controls
239 lines (216 loc) · 9.28 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# Hourly application version check and update workflow
name: LSP Hourly Check and Update
on:
schedule:
- cron: "0 * * * *"
workflow_dispatch:
inputs:
branch:
description: "Branch to run against"
required: false
default: "snapshot"
type: string
node-version:
description: 'Node.js version to use'
required: false
default: '20.x'
type: string
jobs:
check-and-update:
runs-on: ubuntu-latest
# environment: your-environment-name # Uncomment and set your environment name to use environment variables
steps:
- name: Record start time
id: start-time
run: echo "start=$(date +%s)" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch || 'snapshot' }}
fetch-depth: 0 # Fetch all history to ensure we get the latest
- name: Ensure latest commit
run: |
git fetch origin ${{ inputs.branch || 'snapshot' }}
git reset --hard origin/${{ inputs.branch || 'snapshot' }}
- name: Get checked out commit SHA
id: checkout-sha
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Setup dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Setup Git Configuration
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Make scripts executable
run: chmod +x scripts/check-apps.sh scripts/check-core.sh
- name: Check Eureka Components Versions
id: check-core
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
echo "Running Eureka components version check..."
set +e
./scripts/check-core.sh 2>&1 | tee /tmp/check-core-output.log
exit_code=${PIPESTATUS[0]}
set -e
echo "SCRIPT_EXIT_CODE=${exit_code}" >> $GITHUB_OUTPUT
exit $exit_code
- name: Check and Update Application Versions
id: check-apps
env:
FAR_URL: ${{ vars.FAR_URL }}
run: |
echo "Running application version check..."
# Capture output and exit code
set +e # Don't exit on error
./scripts/check-apps.sh 2>&1 | tee /tmp/check-apps-output.log
exit_code=${PIPESTATUS[0]} # Get exit code of the script, not tee
set -e # Re-enable exit on error
# Store the exit code for later use
echo "SCRIPT_EXIT_CODE=${exit_code}" >> $GITHUB_OUTPUT
# Exit with the original code to fail the step if script failed
exit $exit_code
- name: Install Node ${{ inputs.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
check-latest: true
always-auth: true
- name: Build stripes
id: build-stripes
run: |
set +e
{
rm -f yarn.lock
yarn install
{
echo "## Yarn Dependencies"
echo '```'
yarn list --pattern @folio
echo '```'
} >> $GITHUB_STEP_SUMMARY
current_branch=$(git branch --show-current)
git add yarn.lock
git commit -m "[CI] Update yarn.lock" || echo "No changes to commit"
git push origin $current_branch
} 2>&1 | tee /tmp/build-stripes-output.log
exit_code=${PIPESTATUS[0]}
set -e
echo "SCRIPT_EXIT_CODE=${exit_code}" >> $GITHUB_OUTPUT
exit $exit_code
- name: Capture error details
if: always()
id: error-details
run: |
if [ "${{ steps.check-apps.outputs.SCRIPT_EXIT_CODE }}" != "0" ]; then
echo "FAILED_STEP=Check and Update Application Versions" >> $GITHUB_OUTPUT
if [ -f /tmp/check-apps-output.log ]; then
ERROR_DETAILS=$(tail -n 10 /tmp/check-apps-output.log | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
echo "ERROR_DETAILS=${ERROR_DETAILS}" >> $GITHUB_OUTPUT
else
echo "ERROR_DETAILS=No error log available" >> $GITHUB_OUTPUT
fi
elif [ "${{ steps.build-stripes.outputs.SCRIPT_EXIT_CODE }}" != "0" ]; then
echo "FAILED_STEP=Build stripes" >> $GITHUB_OUTPUT
if [ -f /tmp/build-stripes-output.log ]; then
ERROR_DETAILS=$(tail -n 20 /tmp/build-stripes-output.log | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
echo "ERROR_DETAILS=${ERROR_DETAILS}" >> $GITHUB_OUTPUT
else
echo "ERROR_DETAILS=No error log available" >> $GITHUB_OUTPUT
fi
else
echo "FAILED_STEP=" >> $GITHUB_OUTPUT
echo "ERROR_DETAILS=" >> $GITHUB_OUTPUT
fi
- name: Detect if updates were made
if: success()
id: updates-check
run: |
if grep -q "Successfully updated" /tmp/check-apps-output.log 2>/dev/null; then
echo "UPDATES_MADE=true" >> $GITHUB_OUTPUT
else
echo "UPDATES_MADE=false" >> $GITHUB_OUTPUT
fi
- name: Get final commit SHA
if: success()
id: final-sha
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Notify on Failure
if: failure()
uses: slackapi/slack-github-action@v2.1.1
with:
method: chat.postMessage
token: ${{ secrets.EUREKA_CI_SLACK_BOT_TOKEN }}
errors: true
payload: |
channel: "${{ vars.GENERAL_SLACK_NOTIF_CHANNEL }}"
text: "🚨 LSP Hourly Check and Update FAILED"
blocks:
- type: section
text:
type: mrkdwn
text: "*🚨 LSP Hourly Check and Update FAILED <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|#${{ github.run_number }}>*"
- type: section
fields:
- type: mrkdwn
text: "*Branch:*\n<${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref_name }}|${{ github.ref_name }}>"
- type: mrkdwn
text: "*Commit:*\n<${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }}>"
- type: mrkdwn
text: "*Failed Step:*\n${{ steps.error-details.outputs.FAILED_STEP || 'Unknown step' }}"
- type: mrkdwn
text: "*Triggered by:*\n${{ github.event_name == 'schedule' && 'Scheduled (cron)' || github.actor }}"
- type: section
text:
type: mrkdwn
text: "*Error Details:*\n```${{ steps.error-details.outputs.ERROR_DETAILS || 'No error details available' }}```"
attachments:
- color: "danger"
footer: "Eureka CI/CD • ${{ github.workflow }}"
- name: Calculate duration
if: success()
id: duration
run: |
end_time=$(date +%s)
start_time=${{ steps.start-time.outputs.start }}
duration=$((end_time - start_time))
minutes=$((duration / 60))
seconds=$((duration % 60))
if [ $minutes -gt 0 ]; then
echo "duration=${minutes}m ${seconds}s" >> $GITHUB_OUTPUT
else
echo "duration=${seconds}s" >> $GITHUB_OUTPUT
fi
- name: Notify on Success
if: success() && steps.updates-check.outputs.UPDATES_MADE == 'true'
uses: slackapi/slack-github-action@v2.1.1
with:
method: chat.postMessage
token: ${{ secrets.EUREKA_CI_SLACK_BOT_TOKEN }}
errors: true
payload: |
channel: "${{ vars.GENERAL_SLACK_NOTIF_CHANNEL }}"
text: "✅ LSP Hourly Check and Update SUCCESS"
blocks:
- type: section
text:
type: mrkdwn
text: "*✅ LSP Hourly Check and Update SUCCESS <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|#${{ github.run_number }}>*"
- type: section
fields:
- type: mrkdwn
text: "*Triggered from:*\n<${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref_name }}|${{ github.ref_name }}>"
- type: mrkdwn
text: "*Checked out:*\n<${{ github.server_url }}/${{ github.repository }}/tree/${{ inputs.branch || 'snapshot' }}|${{ inputs.branch || 'snapshot' }}>"
- type: mrkdwn
text: "*Commit:*\n<${{ github.server_url }}/${{ github.repository }}/commit/${{ steps.final-sha.outputs.sha }}|${{ steps.final-sha.outputs.sha }}>"
- type: mrkdwn
text: "*Duration:*\n${{ steps.duration.outputs.duration }}"
- type: mrkdwn
text: "*Triggered by:*\n${{ github.event_name == 'schedule' && 'Scheduled (cron)' || github.actor }}"
attachments:
- color: "good"
footer: "Eureka CI/CD • ${{ github.workflow }}"