Fixing pipiline for drops-canary #72
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}) | |
echo "Base Repository: ${{ github.event.pull_request.head.repo.full_name }}" | |
ORG_USER=$(echo "${{ github.event.pull_request.head.repo.full_name }}" | cut -d'/' -f1) | |
echo "Organization/User: $ORG_USER" | |
echo "Base Branch Name: ${{ github.event.pull_request.head.ref }}" | |
# Check if the source URL contains "Azure/arc_jumpstart_drops" | |
if echo "$source_url" | grep -q 'Azure/arc_jumpstart_drops'; then | |
# Replace "Azure" with the incoming PR org/user | |
echo "Replacing Azure with $ORG_USER" | |
echo "Before: $source_url" | |
source_url=$(echo "$source_url" | sed "s/Azure/$ORG_USER/") | |
# Replace "tree/main" with "tree/<name-of-branch>" | |
source_url=$(echo "$source_url" | sed 's/tree\/main/tree\/${{ github.event.pull_request.head.ref }}/') | |
fi | |
echo "New source URL: $source_url" | |
# 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 exist." | |
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 | |