Skip to content

Commit 6f9198f

Browse files
committed
works on my machine update
1 parent bafc9fa commit 6f9198f

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

.github/workflows/validate-structure.yml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,59 @@ jobs:
2626
run: cp .github/scripts/validate-structure.js "$RUNNER_TEMP/validate-structure.js"
2727

2828
- name: Fetch pull request head
29+
id: fetch_head
2930
env:
30-
PR_REMOTE_URL: https://x-access-token:${{ github.token }}@github.com/${{ github.event.pull_request.head.repo.full_name }}.git
31+
PR_REMOTE_URL: https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
3132
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
3233
run: |
3334
git remote remove pr >/dev/null 2>&1 || true
3435
git remote add pr "$PR_REMOTE_URL"
35-
git fetch pr "$PR_HEAD_REF":pr-head --depth=1
36-
git checkout pr-head
36+
if git fetch pr "$PR_HEAD_REF":pr-head --no-tags; then
37+
git checkout pr-head
38+
git fetch origin "${{ github.event.pull_request.base.ref }}"
39+
echo "fetched=true" >> "$GITHUB_OUTPUT"
40+
else
41+
echo "::warning::Unable to fetch fork repository. Skipping structure validation."
42+
echo "fetched=false" >> "$GITHUB_OUTPUT"
43+
fi
3744
3845
- name: Use Node.js 18
3946
uses: actions/setup-node@v4
4047
with:
4148
node-version: 18
4249

4350
- name: Validate folder layout
51+
if: ${{ steps.fetch_head.outputs.fetched == 'true' }}
4452
id: validate
45-
continue-on-error: true
46-
run: node "$RUNNER_TEMP/validate-structure.js" origin/${{ github.event.pull_request.base.ref }}...HEAD
53+
run: |
54+
set -euo pipefail
55+
56+
tmp_output=$(mktemp)
57+
tmp_error=$(mktemp)
58+
59+
set +e
60+
node "$RUNNER_TEMP/validate-structure.js" origin/${{ github.event.pull_request.base.ref }}...HEAD >"$tmp_output" 2>"$tmp_error"
61+
status=$?
62+
set -e
63+
64+
cat "$tmp_output"
65+
cat "$tmp_error" >&2
66+
67+
if grep -q 'Folder structure violations found' "$tmp_output" "$tmp_error"; then
68+
echo "status=failed" >> "$GITHUB_OUTPUT"
69+
exit 0
70+
fi
71+
72+
if [ $status -ne 0 ]; then
73+
echo "::warning::Structure validation skipped because the diff could not be evaluated (exit code $status)."
74+
echo "status=skipped" >> "$GITHUB_OUTPUT"
75+
exit 0
76+
fi
77+
78+
echo "status=passed" >> "$GITHUB_OUTPUT"
4779
4880
- name: Close pull request on failure
49-
if: ${{ steps.validate.outcome == 'failure' }}
81+
if: ${{ steps.validate.outputs.status == 'failed' }}
5082
uses: actions/github-script@v6
5183
with:
5284
github-token: ${{ github.token }}
@@ -59,7 +91,7 @@ jobs:
5991
owner,
6092
repo,
6193
issue_number: pullNumber,
62-
body: `Thank you for your contribution. However, it doesn't comply with our contributing guidelines. As a reminder, the general requirements (as outlined in the [CONTRIBUTING.md file](https://github.com/ServiceNowDevProgram/code-snippets/blob/main/CONTRIBUTING.md)) are the following: follow the folder+subfolder+snippetfolder guidelines and include a README.md file explaining what the code snippet does. Review your contribution against the guidelines and make the necessary adjustments. Closing this for now. Once you make additional changes, feel free to re-open this Pull Request or create a new one.`.trim()
94+
body: `Thank you for your contribution. However, it doesn't comply with our contributing guidelines. As a reminder, the general requirements (as outlined in the [CONTRIBUTING.md file](https://github.com/ServiceNowDevProgram/code-snippets/blob/main/CONTRIBUTING.md)) are the following: follow the folder+subfolder guidelines and include a README.md file explaining what the code snippet does. Review your contribution against the guidelines and make the necessary adjustments. Closing this for now. Once you make additional changes, feel free to re-open this Pull Request or create a new one.`.trim()
6395
});
6496
6597
await github.rest.pulls.update({
@@ -70,6 +102,5 @@ jobs:
70102
});
71103
72104
- name: Mark job as failed if validation failed
73-
if: ${{ steps.validate.outcome == 'failure' }}
105+
if: ${{ steps.validate.outputs.status == 'failed' }}
74106
run: exit 1
75-

0 commit comments

Comments
 (0)