-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
126 lines (114 loc) · 4.51 KB
/
action.yml
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
name: 'Get BrowserStack Quality Gate Result'
author: 'Pramod Yadav'
description: 'To fetch the quality gate result from BrowserStack API'
branding:
icon: 'arrow-left-circle'
color: 'yellow'
inputs:
project-name:
description: 'name of the project'
required: true
build-name:
description: 'name of the build'
required: true
build-tags:
description: 'name of the custom build tags'
required: true
browserstack-username:
description: 'BrowserStack username'
required: true
browserstack-access-key:
description: 'BrowserStack API value'
required: true
timeout-in-seconds:
description: 'timeout duration in seconds after which pooling for result stops'
required: false
default: 120
outputs:
build-id:
description: "Build ID"
value: ${{ steps.get_build_id.outputs.BUILD_ID }}
quality-gate-result:
description: "Quality Gate Result"
value: ${{ steps.get_quality_gate_result.outputs.QUALITY_GATE_RESULT }}
runs:
using: "composite"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq
shell: bash
- name: Sanitize Inputs
id: sanitize-inputs
run: |
sanitized_project_name=$(echo "${{ inputs.project-name }}" | sed 's/[^a-zA-Z0-9-]/%20/g')
sanitized_build_name=$(echo "${{ inputs.build-name }}" | sed 's/[^a-zA-Z0-9-]/%20/g')
sanitized_build_tags=$(echo "${{ inputs.build-tags }}" | sed 's/[^a-zA-Z0-9-]/%20/g')
echo "SANITIZED_PROJECT_NAME=$sanitized_project_name" >> $GITHUB_ENV
echo "SANITIZED_BUILD_NAME=$sanitized_build_name" >> $GITHUB_ENV
echo "SANITIZED_BUILD_TAGS=$sanitized_build_tags" >> $GITHUB_ENV
shell: bash
- name: Get build_id
id: get_build_id
run: |
end=$((SECONDS+${{ inputs.timeout-in-seconds }}))
while [ $SECONDS -lt $end ]; do
response=$(curl -u "${{ inputs.browserstack-username }}:${{ inputs.browserstack-access-key }}" "https://api-observability.browserstack.com/ext/v1/builds/latest?project_name=${{ env.SANITIZED_PROJECT_NAME }}&build_name=${{ env.SANITIZED_BUILD_NAME }}&user_name=${{ inputs.browserstack-username }}&build_tags=${{ env.SANITIZED_BUILD_TAGS }}")
if echo "$response" | jq '.build_id' | grep -q -v null; then
echo "Desired value found!"
echo "$response" | jq '.' > latest-build-run-details.json
build_id=$(echo "$response" | jq -r '.build_id')
echo "BUILD_ID=$build_id" >> $GITHUB_ENV
echo "BUILD_ID=$build_id" >> $GITHUB_OUTPUT
exit 0
else
echo "Desired value not found, retrying..."
sleep 3
fi
done
echo "Timeout reached without finding desired value"
exit 1
shell: bash
- name: Get quality_gate_result
id: get_quality_gate_result
run: |
echo "BUILD_ID value: ${{ env.BUILD_ID }}"
end=$((SECONDS+${{ inputs.timeout-in-seconds }}))
while [ $SECONDS -lt $end ]; do
response=$(curl -u "${{ inputs.browserstack-username }}:${{ inputs.browserstack-access-key }}" "https://api-observability.browserstack.com/ext/v1/quality-gates/${{ env.BUILD_ID }}")
status=$(echo "$response" | jq -r '.status')
echo "Status: '$status'"
if [ "$status" == "running" ] || [ "$status" == "null" ]; then
echo "Quality Gate Result not available yet, retrying..."
sleep 5
else
echo "Quality Gate Result is ready!"
echo "$response" | jq '.' > quality-gate-result.json
quality_gate_result=$(echo "$response" | jq -r '.quality_gate_result')
echo "QUALITY_GATE_RESULT=$quality_gate_result" >> $GITHUB_ENV
echo "QUALITY_GATE_RESULT=$quality_gate_result" >> "$GITHUB_OUTPUT"
exit 0
fi
done
echo "Timeout reached without finding desired value"
exit 1
shell: bash
- name: Print quality_gate_result
run: |
echo "QUALITY_GATE_RESULT value: ${{ env.QUALITY_GATE_RESULT }}"
shell: bash
- name: Upload build run details
if: success()
uses: actions/upload-artifact@v4
with:
name: latest-build-run-details
path: latest-build-run-details.json
- name: Upload quality gate result
if: success()
uses: actions/upload-artifact@v4
with:
name: quality-gate-result
path: quality-gate-result.json