Skip to content

Simulate validation issue #5

Simulate validation issue

Simulate validation issue #5

name: Sample.json validation
on:
pull_request:
branches:
- "main"
jobs:
validate:
runs-on: ubuntu-latest
outputs:
response: ${{ steps.fetch.outputs.response }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Validate any sample.json file
run: |
# Find all sample.json files in the pull request
files=$(git diff --name-only HEAD HEAD~1 | grep 'sample.json$')
echo "Found sample.json files: $files"
# Process each file
for file in $files; do
echo "Processing file: $file"
response=$(curl -X POST -H "Content-Type: application/json" -d @$file https://m365-galleries.azurewebsites.net/Samples/validateSample)
echo "Response: $response"
isValid=$(echo "$response" | jq -r '.isValid')
if [[ $isValid == "true" ]]; then
echo "Validation successful for $file"
else
echo "Validation failed for $file! Please fix the errors and try again."
exit 1
fi
done
id: fetch
failure:
needs: validate
runs-on: ubuntu-latest
if: failure()
steps:
- name: Fail
run: |
echo ${{ needs.validate.outputs.response }}
- uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: JSON.parse(`${{ needs.validate.outputs.response }}`).errors?.map(e => "- " + e).join("\n")
})
- name: Fail
run: exit 1