Skip to content

Add trigger from ADO #30

Add trigger from ADO

Add trigger from ADO #30

name: Drop schema validator
on:
pull_request:
types: [opened, synchronize]
branches:
- canary
workflow_dispatch:
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get the Drop schema json
id: changed-files-specific
uses: tj-actions/changed-files@v44
with:
files: drops/*.json
- name: List changed JSON schema files
if: steps.changed-files-specific.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files-specific.outputs.all_changed_files }}
run: |
echo "✅ Success - List all the files that have changed: $ALL_CHANGED_FILES"
- name: Validate JSON
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker://orrosenblatt/validate-json-action:latest
env:
INPUT_SCHEMA: .github/workflows/default_schema.json
INPUT_JSONS: ${{ steps.changed-files-specific.outputs.all_changed_files }}
- name : Validate source repo
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
if ! jq 'has("Source")' ${{ steps.changed-files-specific.outputs.all_changed_files }} >/dev/null; then
echo "Error: missing the Source field"
exit 1
fi
source_url=$(jq -r '.Source' ${{ steps.changed-files-specific.outputs.all_changed_files }})
# Use curl to check if the URL returns a 200 OK status code
if curl --head --fail --silent "$source_url" >/dev/null; then
echo "✅ Success - The Source: $source_url exists."
else
echo "❌ Error - The $source_url does not exists."
exit 1
fi
- name : Check MIT License
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
# Use curl to check if the LICENSE file exists in the repository
source_url=$(jq -r '.Source' ${{ steps.changed-files-specific.outputs.all_changed_files }})
# Extract the organization and repository names from the GitHub URL
organization=$(echo "$source_url" | cut -d'/' -f4)
repository=$(echo "$source_url" | cut -d'/' -f5)
echo "Organization: $organization"
echo "Repository: $repository"
# Create the URL for the LICENSE file
license_url="https://raw.githubusercontent.com/$organization/$repository/main/LICENSE"
if curl --head --fail --silent "$license_url" >/dev/null; then
# If the LICENSE file exists, look for "MIT License" in the file
if curl --silent "$license_url" | grep -q 'MIT License'; then
echo "✅ Success - The $organization/$repository has an MIT license"
else
echo "❌ Error - The $license_url does not have an MIT license"
exit 1
fi
elif curl --head --fail --silent "$license_url/LICENSE.md" >/dev/null; then
# If the LICENSE.md file exists, look for "MIT" in the file
if curl --silent "$license_url/LICENSE.md" | grep -q 'MIT License'; then
echo "✅ Success - The $license_url has an MIT license"
else
echo "❌ Error - The $license_url does not have an MIT license"
exit 1
fi
else
# If neither file exists, output an error message
echo "❌ Error - The $license_url does not have a LICENSE file"
exit 1
fi