Skip to content

Commit 0aa8d56

Browse files
authored
Update GitLab access diagnostics in workflow
1 parent c2a1483 commit 0aa8d56

1 file changed

Lines changed: 35 additions & 14 deletions

File tree

.github/workflows/main.yml

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,42 +101,63 @@ jobs:
101101
102102
echo "GitLab credentials are configured."
103103
104-
- name: Diagnose GitLab token
104+
- name: Diagnose GitLab access
105105
env:
106106
GITLAB_TOKEN: ${{ secrets.TOTA11Y_GITLAB_TOKEN }}
107107
run: |
108108
set -eu
109109
110-
RESPONSE_FILE="/tmp/gitlab-project-response.json"
110+
RESPONSE_FILE="/tmp/gitlab-response"
111+
HEADERS_FILE="/tmp/gitlab-headers"
111112
112113
HTTP_STATUS="$(
113114
curl \
114115
--silent \
115116
--show-error \
117+
--dump-header "${HEADERS_FILE}" \
116118
--output "${RESPONSE_FILE}" \
117119
--write-out "%{http_code}" \
118120
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
119121
"https://gitlab.tech.orange/api/v4/projects/574357"
120122
)"
121123
122-
echo "GitLab API status: ${HTTP_STATUS}"
124+
echo "GitLab HTTP status: ${HTTP_STATUS}"
125+
echo "Response Content-Type:"
126+
grep -i '^content-type:' "${HEADERS_FILE}" || true
123127
124-
node -e "
125-
const fs = require('fs');
126-
const body = JSON.parse(fs.readFileSync('${RESPONSE_FILE}', 'utf8'));
128+
CONTENT_TYPE="$(
129+
grep -i '^content-type:' "${HEADERS_FILE}" \
130+
| tail -n 1 \
131+
| tr -d '\r' \
132+
|| true
133+
)"
127134
128-
console.log('GitLab response:', {
129-
message: body.message || null,
130-
projectId: body.id || null,
131-
projectPath: body.path_with_namespace || null
132-
});
133-
"
135+
if printf '%s' "${CONTENT_TYPE}" | grep -qi 'application/json'; then
136+
node -e "
137+
const fs = require('fs');
138+
const body = JSON.parse(
139+
fs.readFileSync('${RESPONSE_FILE}', 'utf8')
140+
);
141+
142+
console.log({
143+
message: body.message || null,
144+
projectId: body.id || null,
145+
projectPath: body.path_with_namespace || null
146+
});
147+
"
148+
else
149+
echo "Non-JSON response received."
150+
grep -io '<title>[^<]*' "${RESPONSE_FILE}" \
151+
| head -n 1 \
152+
| sed 's/<title>//i' \
153+
|| true
154+
fi
134155
135156
if [ "${HTTP_STATUS}" != "200" ]; then
136-
echo "::error::GitLab token cannot access project 574357."
157+
echo "::error::GitLab is not accessible from this GitHub runner."
137158
exit 1
138159
fi
139-
160+
140161
- name: Clone tota11y-scan from GitLab
141162
env:
142163
GITLAB_USERNAME: ${{ secrets.TOTA11Y_GITLAB_USERNAME }}

0 commit comments

Comments
 (0)