-
Notifications
You must be signed in to change notification settings - Fork 18
197 lines (177 loc) · 7.17 KB
/
Copy pathgitlab-e2e.yml
File metadata and controls
197 lines (177 loc) · 7.17 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
name: GitLab E2E
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
merge_group:
workflow_dispatch:
inputs:
setup_ref:
description: "Enter an exact setup-vp commit SHA or release tag. If empty, the workflow uses this commit."
required: false
default: ""
suite:
description: "Select the GitLab test suite."
type: choice
options: [full, required]
default: full
vite_plus_version:
description: "Vite+ version or dist-tag to install."
required: false
default: latest
permissions:
contents: read
pull-requests: read
jobs:
gitlab-e2e:
name: GitLab E2E
runs-on: ubuntu-latest
timeout-minutes: 35
steps:
- name: Resolve test parameters
id: parameters
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_REF: ${{ github.ref }}
EVENT_REF_NAME: ${{ github.ref_name }}
PR_HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_NUMBER: ${{ github.event.pull_request.number }}
MANUAL_SETUP_REF: ${{ inputs.setup_ref }}
MANUAL_SUITE: ${{ inputs.suite }}
MANUAL_VITE_PLUS_VERSION: ${{ inputs.vite_plus_version }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
should_run=true
setup_vp_ref="$GITHUB_SHA"
suite=required
vite_plus_version=latest
if [ "$EVENT_NAME" = "pull_request" ]; then
if [ "$PR_HEAD_REPOSITORY" != "$GITHUB_REPOSITORY" ]; then
should_run=false
echo "The workflow skips fork pull requests. The merge queue or a maintainer can test these changes."
else
setup_vp_ref="$PR_HEAD_SHA"
while IFS= read -r changed_path; do
case "$changed_path" in
gitlab/* | src/gitlab/* | src/ci/* | dist/gitlab/* | .github/workflows/gitlab-e2e.yml | vite.config.ts | package.json | pnpm-lock.yaml | pnpm-workspace.yaml)
suite=full
break
;;
esac
done < <(gh api --paginate "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files" --jq '.[].filename')
fi
elif [ "$EVENT_NAME" = "merge_group" ]; then
suite=full
elif [ "$EVENT_NAME" = "workflow_dispatch" ]; then
setup_vp_ref="${MANUAL_SETUP_REF:-$GITHUB_SHA}"
suite="${MANUAL_SUITE:-full}"
vite_plus_version="${MANUAL_VITE_PLUS_VERSION:-latest}"
elif [ "$EVENT_NAME" = "push" ] && [[ "$EVENT_REF" == refs/tags/* ]]; then
setup_vp_ref="$EVENT_REF_NAME"
suite=full
elif [ "$EVENT_NAME" = "push" ]; then
suite=full
fi
{
echo "should_run=$should_run"
echo "setup_vp_ref=$setup_vp_ref"
echo "suite=$suite"
echo "vite_plus_version=$vite_plus_version"
} >> "$GITHUB_OUTPUT"
if [ "$should_run" = "false" ]; then
{
echo "### GitLab E2E"
echo
echo "The workflow skipped this fork pull request. The merge queue tests the reviewed merge commit."
} >> "$GITHUB_STEP_SUMMARY"
fi
- name: Trigger GitLab pipeline
if: steps.parameters.outputs.should_run == 'true'
id: trigger
env:
GITLAB_PROJECT_ID: "85578524"
GITLAB_TRIGGER_TOKEN: ${{ secrets.GITLAB_TRIGGER_TOKEN }}
SETUP_VP_REF: ${{ steps.parameters.outputs.setup_vp_ref }}
TEST_SUITE: ${{ steps.parameters.outputs.suite }}
VITE_PLUS_VERSION: ${{ steps.parameters.outputs.vite_plus_version }}
run: |
set -euo pipefail
if [ -z "$GITLAB_TRIGGER_TOKEN" ]; then
echo "::error::This repository does not have the GITLAB_TRIGGER_TOKEN secret."
exit 1
fi
response="$(curl --silent --show-error --fail-with-body \
--request POST \
--form-string "token=$GITLAB_TRIGGER_TOKEN" \
--form-string "ref=main" \
--form-string "inputs[setup_vp_ref]=$SETUP_VP_REF" \
--form-string "inputs[suite]=$TEST_SUITE" \
--form-string "inputs[vite_plus_version]=$VITE_PLUS_VERSION" \
"https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/trigger/pipeline")"
pipeline_id="$(jq -er '.id' <<< "$response")"
pipeline_url="$(jq -er '.web_url' <<< "$response")"
echo "Triggered GitLab pipeline: $pipeline_url"
{
echo "pipeline_id=$pipeline_id"
echo "pipeline_url=$pipeline_url"
} >> "$GITHUB_OUTPUT"
{
echo "### GitLab E2E"
echo
echo "- Pipeline: [$pipeline_id]($pipeline_url)"
echo "- setup-vp ref: \`$SETUP_VP_REF\`"
echo "- Suite: \`$TEST_SUITE\`"
echo "- Vite+ version: \`$VITE_PLUS_VERSION\`"
} >> "$GITHUB_STEP_SUMMARY"
- name: Wait for GitLab pipeline
if: steps.parameters.outputs.should_run == 'true'
env:
GITLAB_PROJECT_ID: "85578524"
GITLAB_PIPELINE_ID: ${{ steps.trigger.outputs.pipeline_id }}
GITLAB_PIPELINE_URL: ${{ steps.trigger.outputs.pipeline_url }}
run: |
set -euo pipefail
api_url="https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/pipelines/${GITLAB_PIPELINE_ID}"
deadline=$((SECONDS + 1800))
previous_status=""
final_status="timed_out"
while [ "$SECONDS" -lt "$deadline" ]; do
if payload="$(curl --silent --show-error --fail --retry 3 --retry-delay 2 "$api_url")"; then
status="$(jq -er '.status' <<< "$payload")"
if [ "$status" != "$previous_status" ]; then
echo "GitLab pipeline status: $status"
previous_status="$status"
fi
case "$status" in
success)
final_status=success
break
;;
failed | canceled | skipped | manual)
final_status="$status"
break
;;
esac
else
echo "The workflow could not read the GitLab pipeline status. It will try again."
fi
sleep 10
done
{
echo "- Result: \`$final_status\`"
} >> "$GITHUB_STEP_SUMMARY"
if [ "$final_status" = "success" ]; then
echo "GitLab pipeline passed: $GITLAB_PIPELINE_URL"
exit 0
fi
echo "GitLab pipeline did not pass: $GITLAB_PIPELINE_URL"
jobs_url="https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/pipelines/${GITLAB_PIPELINE_ID}/jobs?per_page=100"
if jobs="$(curl --silent --show-error --fail --retry 3 --retry-delay 2 "$jobs_url")"; then
jq -r 'sort_by(.name)[] | "\(.status)\t\(.name)\t\(.web_url)"' <<< "$jobs"
fi
echo "::error::GitLab pipeline finished with status $final_status."
exit 1