|
| 1 | +name: Validate New Plugin Metadata |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [ "main" ] |
| 6 | + paths: [ "plugins/**" ] |
| 7 | + types: [ opened, edited, reopened, synchronize ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + identify-new-plugins: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + plugin_dirs: ${{ steps.find_new_plugins.outputs.plugin_dirs }} |
| 14 | + steps: |
| 15 | + - name: Checkout Repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + ref: ${{ github.event.pull_request.head.ref }} |
| 20 | + |
| 21 | + - name: Identify New Plugin Directories |
| 22 | + id: find_new_plugins |
| 23 | + run: | |
| 24 | + git fetch origin ${{ github.event.pull_request.base.ref }} |
| 25 | + BASE_COMMIT=$(git merge-base origin/${{ github.event.pull_request.base.ref }} HEAD) |
| 26 | +
|
| 27 | + NEW_PLUGINS=() |
| 28 | + for plugin_dir in $(git diff --diff-filter=A --name-only $BASE_COMMIT...HEAD | grep '^plugins/' | cut -d'/' -f1-2 | sort -u); do |
| 29 | + if ! git rev-parse --verify origin/${{ github.event.pull_request.base.ref }}:"$plugin_dir" &>/dev/null; then |
| 30 | + NEW_PLUGINS+=("$plugin_dir") |
| 31 | + fi |
| 32 | + done |
| 33 | +
|
| 34 | + if [[ ${#NEW_PLUGINS[@]} -eq 0 ]]; then |
| 35 | + echo "plugin_dirs=[]" >> $GITHUB_OUTPUT |
| 36 | + exit 0 |
| 37 | + fi |
| 38 | +
|
| 39 | + echo "plugin_dirs=$(jq -nc --argjson arr "$(printf '%s\n' "${NEW_PLUGINS[@]}" | jq -R . | jq -s .)" '$arr')" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + validate-individual-plugins: |
| 42 | + needs: identify-new-plugins |
| 43 | + if: ${{ needs.identify-new-plugins.outputs.plugin_dirs != '[]' }} |
| 44 | + runs-on: ubuntu-latest |
| 45 | + strategy: |
| 46 | + matrix: |
| 47 | + plugin_dir: ${{ fromJson(needs.identify-new-plugins.outputs.plugin_dirs) }} |
| 48 | + steps: |
| 49 | + - name: Checkout Repository |
| 50 | + uses: actions/checkout@v4 |
| 51 | + |
| 52 | + - name: Validate Plugin Metadata |
| 53 | + run: | |
| 54 | + metadata_file="${{ matrix.plugin_dir }}/plugin_metadata.yml" |
| 55 | + if [[ ! -f "$metadata_file" ]]; then |
| 56 | + echo "::error file=$metadata_file::Missing plugin_metadata.yml" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "::group::Validating $metadata_file" |
| 61 | +
|
| 62 | + metadata=$(yq '.' "$metadata_file") |
| 63 | + errors=0 |
| 64 | +
|
| 65 | + check_required_field() { |
| 66 | + local field="$1" |
| 67 | + local value=$(echo "$metadata" | yq ".$field") |
| 68 | + if [[ -z "$value" ]]; then |
| 69 | + echo "::error file=$metadata_file::'$field' is missing" |
| 70 | + ((errors++)) |
| 71 | + fi |
| 72 | + } |
| 73 | +
|
| 74 | + check_valid_url() { |
| 75 | + local field="$1" |
| 76 | + local value=$(echo "$metadata" | yq ".$field" || true) |
| 77 | +
|
| 78 | + if [[ -z "$value" ]]; then |
| 79 | + return 0 |
| 80 | + fi |
| 81 | +
|
| 82 | + if [[ "$value" == "["*"]" ]]; then # Detects if the field is an array |
| 83 | + for url in $(echo "$value" | yq '.[]'); do |
| 84 | + if [[ ! "$url" =~ ^https?:\/\/[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,})+(:[0-9]{1,5})?(\/.*)?$ ]]; then |
| 85 | + echo "::error file=$metadata_file::'$field' contains an invalid URL: $url" |
| 86 | + ((errors++)) |
| 87 | + fi |
| 88 | + done |
| 89 | + else |
| 90 | + if [[ ! "$value" =~ ^https?:\/\/[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,})+(:[0-9]{1,5})?(\/.*)?$ ]]; then |
| 91 | + echo "::error file=$metadata_file::'$field' is not a valid URL" |
| 92 | + ((errors++)) |
| 93 | + fi |
| 94 | + fi |
| 95 | + } |
| 96 | +
|
| 97 | + check_required_field "plugin_name" |
| 98 | + check_required_field "author" |
| 99 | + check_required_field "short_description" |
| 100 | + check_required_field "detailed_description" |
| 101 | + check_required_field "support_contact" |
| 102 | +
|
| 103 | + check_valid_url "logo_url" |
| 104 | + check_valid_url "plugin_logo_url" |
| 105 | + check_valid_url "demo_video_url" |
| 106 | + check_valid_url "documentation_url" |
| 107 | + check_valid_url "changelog_url" |
| 108 | + check_valid_url "community_url" |
| 109 | + check_valid_url "screenshots" # Now supports an array of URLs |
| 110 | +
|
| 111 | + release_date=$(echo "$metadata" | yq '.release_date') |
| 112 | + if [[ ! "$release_date" =~ ^202[0-9]{1}-[0-9]{2}$ ]]; then |
| 113 | + echo "::error file=$metadata_file::'release_date' should be in YYYY-MM format" |
| 114 | + ((errors++)) |
| 115 | + fi |
| 116 | +
|
| 117 | + x_account_handle=$(echo "$metadata" | yq '.x_account_handle') |
| 118 | + if [[ -n "$x_account_handle" && ! "$x_account_handle" =~ ^@[a-zA-Z0-9_]{1,15}$ ]]; then |
| 119 | + echo "::error file=$metadata_file::'x_account_handle' is not a valid X (Twitter) handle" |
| 120 | + ((errors++)) |
| 121 | + fi |
| 122 | +
|
| 123 | + support_contact=$(echo "$metadata" | yq '.support_contact') |
| 124 | + if [[ ! "$support_contact" =~ ^(https?:\/\/[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,})+(:[0-9]{1,5})?(\/.*)?|[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$ ]]; then |
| 125 | + echo "::error file=$metadata_file::'support_contact' must be a valid URL or email address" |
| 126 | + ((errors++)) |
| 127 | + fi |
| 128 | +
|
| 129 | + echo "::endgroup::" |
| 130 | + exit $errors |
0 commit comments