|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -o errexit |
| 4 | +set -o nounset |
| 5 | +set -o pipefail |
| 6 | + |
| 7 | +UPSTREAM=https://github.com/ddev/ddev-addon-template/blob/main |
| 8 | + |
| 9 | +# List to store actions |
| 10 | +actions=() |
| 11 | + |
| 12 | +# Check for unnecessary files and suggest removal |
| 13 | +check_remove_file() { |
| 14 | + local file=$1 |
| 15 | + if [[ -f "$file" ]]; then |
| 16 | + actions+=("Remove unnecessary file: $file") |
| 17 | + fi |
| 18 | +} |
| 19 | + |
| 20 | +# Check README.md for required conditions |
| 21 | +check_readme() { |
| 22 | + local readme="README.md" |
| 23 | + |
| 24 | + if [[ -f "$readme" ]]; then |
| 25 | + # Check for 'ddev add-on get' |
| 26 | + if ! grep -q "ddev add-on get" "$readme"; then |
| 27 | + actions+=("README.md should contain 'ddev add-on get', see upstream file $UPSTREAM/README_ADDON.md?plain=1") |
| 28 | + fi |
| 29 | + |
| 30 | + # Check for 'ddev get' |
| 31 | + if grep -q "ddev get" "$readme"; then |
| 32 | + actions+=("Remove 'ddev get' from README.md, see upstream file $UPSTREAM/README_ADDON.md?plain=1") |
| 33 | + fi |
| 34 | + |
| 35 | + # Check for required badges and replacements |
| 36 | + if grep -q "project is maintained" "$readme"; then |
| 37 | + actions+=("README.md should not contain 'project is maintained' badge, see upstream file $UPSTREAM/README_ADDON.md?plain=1") |
| 38 | + fi |
| 39 | + |
| 40 | + # Ensure the required badges are present |
| 41 | + for badge in "add-on registry" "tests" "last commit" "release"; do |
| 42 | + if ! grep -q "$badge" "$readme"; then |
| 43 | + actions+=("README.md should contain badge: $badge, see upstream file $UPSTREAM/README_ADDON.md?plain=1") |
| 44 | + fi |
| 45 | + done |
| 46 | + else |
| 47 | + actions+=("README.md is missing, see upstream file $UPSTREAM/README_ADDON.md?plain=1") |
| 48 | + fi |
| 49 | +} |
| 50 | + |
| 51 | +# Check install.yaml for required conditions |
| 52 | +check_install_yaml() { |
| 53 | + local install_yaml="install.yaml" |
| 54 | + |
| 55 | + if [[ -f "$install_yaml" ]]; then |
| 56 | + # Check for ddev_version_constraint |
| 57 | + if ! grep -q "ddev_version_constraint: '>= v1.24.3'" "$install_yaml"; then |
| 58 | + actions+=("install.yaml should contain 'ddev_version_constraint: \">= v1.24.3\"', see upstream file $UPSTREAM/$install_yaml") |
| 59 | + fi |
| 60 | + |
| 61 | + # Check for addon-template |
| 62 | + if grep -q "addon-template" "$install_yaml"; then |
| 63 | + actions+=("install.yaml should not contain 'addon-template', use your own name") |
| 64 | + fi |
| 65 | + else |
| 66 | + actions+=("install.yaml is missing, see upstream file $UPSTREAM/$install_yaml") |
| 67 | + fi |
| 68 | +} |
| 69 | + |
| 70 | +# Check tests/test.bats for required conditions |
| 71 | +check_test_bats() { |
| 72 | + local test_bats="tests/test.bats" |
| 73 | + |
| 74 | + if [[ -f "$test_bats" ]]; then |
| 75 | + # Check for test_tags=release |
| 76 | + if ! grep -q "# bats test_tags=release" "$test_bats"; then |
| 77 | + actions+=("$test_bats should contain '# bats test_tags=release', see upstream file $UPSTREAM/$test_bats") |
| 78 | + fi |
| 79 | + |
| 80 | + # Check for ddev add-on get |
| 81 | + if ! grep -q "ddev add-on get" "$test_bats"; then |
| 82 | + actions+=("$test_bats should contain 'ddev add-on get', see upstream file $UPSTREAM/$test_bats") |
| 83 | + fi |
| 84 | + else |
| 85 | + actions+=("$test_bats is missing, see upstream file $UPSTREAM/$test_bats") |
| 86 | + fi |
| 87 | +} |
| 88 | + |
| 89 | +# Check for required GitHub template files |
| 90 | +check_github_templates() { |
| 91 | + local templates=( |
| 92 | + ".github/ISSUE_TEMPLATE/bug_report.yml" |
| 93 | + ".github/ISSUE_TEMPLATE/feature_request.yml" |
| 94 | + ".github/PULL_REQUEST_TEMPLATE.md" |
| 95 | + ) |
| 96 | + |
| 97 | + for template in "${templates[@]}"; do |
| 98 | + if [[ ! -f "$template" ]]; then |
| 99 | + actions+=("GitHub template missing: $template, see upstream file $UPSTREAM/$template?plain=1") |
| 100 | + fi |
| 101 | + done |
| 102 | + |
| 103 | + # Check PULL_REQUEST_TEMPLATE.md for the forbidden exact link |
| 104 | + local pr_template=".github/PULL_REQUEST_TEMPLATE.md" |
| 105 | + if [[ -f "$pr_template" ]]; then |
| 106 | + if grep -q "https://github.com/<user>/<repo>/tarball/<branch>" "$pr_template"; then |
| 107 | + actions+=("PULL_REQUEST_TEMPLATE.md should not contain 'https://github.com/<user>/<repo>/tarball/<branch>', see upstream file $UPSTREAM/$pr_template?plain=1") |
| 108 | + fi |
| 109 | + fi |
| 110 | +} |
| 111 | + |
| 112 | +# Main function |
| 113 | +main() { |
| 114 | + # Check unnecessary files |
| 115 | + check_remove_file "README_DEBUG.md" |
| 116 | + check_remove_file "images/gh-tmate.jpg" |
| 117 | + check_remove_file "images/template--button.png" |
| 118 | + check_remove_file "docker-compose.addon-template.yaml" |
| 119 | + |
| 120 | + # Check README.md for conditions |
| 121 | + check_readme |
| 122 | + |
| 123 | + # Check install.yaml for conditions |
| 124 | + check_install_yaml |
| 125 | + |
| 126 | + # Check tests/test.bats for conditions |
| 127 | + check_test_bats |
| 128 | + |
| 129 | + # Check GitHub templates |
| 130 | + check_github_templates |
| 131 | + |
| 132 | + # If any actions are needed, throw an error |
| 133 | + if [[ ${#actions[@]} -gt 0 ]]; then |
| 134 | + echo "ERROR: Actions needed:" |
| 135 | + for action in "${actions[@]}"; do |
| 136 | + echo "- $action" |
| 137 | + done |
| 138 | + exit 1 |
| 139 | + else |
| 140 | + echo "All checks passed, no actions needed." |
| 141 | + fi |
| 142 | +} |
| 143 | + |
| 144 | +# Run the main function |
| 145 | +main |
0 commit comments