Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 187 additions & 0 deletions .github/scripts/update-checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

UPSTREAM=https://github.com/ddev/ddev-addon-template/blob/main

# List to store actions
actions=()

# Check for unnecessary files and suggest removal
check_remove_file() {
local file=$1
if [[ -f "$file" ]]; then
actions+=("Remove unnecessary file: $file")
fi
}

# Check README.md for required conditions
check_readme() {
local readme="README.md"
local badge

if [[ -f "$readme" ]]; then
# Check for 'ddev add-on get'
if ! grep -q "ddev add-on get" "$readme"; then
actions+=("README.md should contain 'ddev add-on get', see upstream file $UPSTREAM/README_ADDON.md?plain=1")
fi

# Check for 'ddev get'
if grep -q "ddev get" "$readme"; then
actions+=("Remove 'ddev get' from README.md, see upstream file $UPSTREAM/README_ADDON.md?plain=1")
fi

# Check for required badges and replacements
if grep -q "project is maintained" "$readme"; then
actions+=("README.md should not contain 'project is maintained' badge, see upstream file $UPSTREAM/README_ADDON.md?plain=1")
fi

# Ensure the required badges are present
for badge in "add-on registry" "tests" "last commit" "release"; do
if ! grep -q "$badge" "$readme"; then
actions+=("README.md should contain badge: $badge, see upstream file $UPSTREAM/README_ADDON.md?plain=1")
fi
done
else
actions+=("README.md is missing, see upstream file $UPSTREAM/README_ADDON.md?plain=1")
fi
}

# Check install.yaml for required conditions
check_install_yaml() {
local install_yaml="install.yaml"

if [[ -f "$install_yaml" ]]; then
# Check for ddev_version_constraint
if ! grep -q "ddev_version_constraint: '>= v1.24.3'" "$install_yaml"; then
actions+=("install.yaml should contain 'ddev_version_constraint: \">= v1.24.3\"', see upstream file $UPSTREAM/$install_yaml")
fi

# Check for addon-template
if grep -q "addon-template" "$install_yaml"; then
actions+=("install.yaml should not contain 'addon-template', use your own name")
fi
else
actions+=("install.yaml is missing, see upstream file $UPSTREAM/$install_yaml")
fi
}

# Check tests/test.bats for required conditions
check_test_bats() {
local test_bats="tests/test.bats"

if [[ -f "$test_bats" ]]; then
# Check for test_tags=release
if grep -q "install from release" "$test_bats" && ! grep -q "# bats test_tags=release" "$test_bats"; then
actions+=("$test_bats should contain '# bats test_tags=release', see upstream file $UPSTREAM/$test_bats")
fi

# Check for ddev add-on get
if ! grep -q "ddev add-on get" "$test_bats"; then
actions+=("$test_bats should contain 'ddev add-on get', see upstream file $UPSTREAM/$test_bats")
fi
else
actions+=("$test_bats is missing, see upstream file $UPSTREAM/$test_bats")
fi
}

# Check for correct shebang in commands/**/* files
check_shebang() {
local file
while IFS= read -r -d '' file; do
if [[ -f "$file" && -r "$file" ]]; then
local first_line
first_line=$(head -n1 "$file" 2>/dev/null || echo "")
if [[ "$first_line" == "#!/bin/bash" ]]; then
actions+=("$file should use '#!/usr/bin/env bash' instead of '#!/bin/bash'")
fi
fi
done < <(find commands -type f -print0 2>/dev/null || true)
}

# Check .github/workflows/tests.yml for required conditions
check_tests_workflow() {
local tests_yml=".github/workflows/tests.yml"

if [[ -f "$tests_yml" ]]; then
# Check for ddev/github-action-add-on-test@v2
if ! grep -q "ddev/github-action-add-on-test@v2" "$tests_yml"; then
actions+=("$tests_yml should use 'ddev/github-action-add-on-test@v2', see upstream file $UPSTREAM/$tests_yml")
fi
else
actions+=("$tests_yml is missing, see upstream file $UPSTREAM/$tests_yml")
fi
}

# Check for required GitHub template files
check_github_templates() {
local templates=(
".github/ISSUE_TEMPLATE/bug_report.yml"
".github/ISSUE_TEMPLATE/feature_request.yml"
".github/PULL_REQUEST_TEMPLATE.md"
)
local template

for template in "${templates[@]}"; do
if [[ ! -f "$template" ]]; then
actions+=("GitHub template missing: $template, see upstream file $UPSTREAM/$template?plain=1")
fi
done

# Check PULL_REQUEST_TEMPLATE.md for the forbidden exact link
local pr_template=".github/PULL_REQUEST_TEMPLATE.md"
if [[ -f "$pr_template" ]]; then
if grep -q "https://github.com/<user>/<repo>/tarball/<branch>" "$pr_template"; then
actions+=("PULL_REQUEST_TEMPLATE.md should not contain 'https://github.com/<user>/<repo>/tarball/<branch>', see upstream file $UPSTREAM/$pr_template?plain=1")
fi
fi
}

# Main function
main() {
if [[ ! -f "install.yaml" ]]; then
echo "ERROR: run this script from the add-on root directory, install.yaml is missing" >&2
exit 1
fi

# Check unnecessary files
check_remove_file "README_DEBUG.md"
check_remove_file "images/gh-tmate.jpg"
check_remove_file "images/template--button.png"
check_remove_file "docker-compose.addon-template.yaml"

# Check README.md for conditions
check_readme

# Check install.yaml for conditions
check_install_yaml

# Check tests/test.bats for conditions
check_test_bats

# Check shebang in commands/**/* files
check_shebang

# Check tests workflow
check_tests_workflow

# Check GitHub templates
check_github_templates

# If any actions are needed, throw an error
if [[ ${#actions[@]} -gt 0 ]]; then
echo "ERROR: Actions needed:" >&2
local action
for action in "${actions[@]}"; do
echo "- $action" >&2
done
exit 1
else
echo "All checks passed, no actions needed."
fi
}

# Run the main function
main
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ This repository is a quick way to get started. You can create a new repo from th
3. Add a meaningful description with relevant keywords for discoverability.
4. Click `Create repository` and wait for the automated `First time setup` commit.

> [!NOTE]
> Automated updates to the `README.md` happen in a minute or so after creation.
> [!NOTE]
> Automated updates to the `README.md` happen in a minute or so after creation.

5. Clone your repository locally (use the green `<> Code` button for the URL).
6. Prepare your add-on files and tests, see [Getting started](#getting-started) for details.
Expand All @@ -40,6 +40,13 @@ This repository is a quick way to get started. You can create a new repo from th
9. Create a new [release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository).
10. When ready to share, make your add-on discoverable by adding the `ddev-get` [topic](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics).

> [!TIP]
> Run update checker in your add-on to ensure it is up-to-date:
>
> ```bash
> curl -fsSL https://raw.githubusercontent.com/ddev/ddev-addon-template/main/.github/scripts/update-checker.sh | bash
> ```

## Components of the repository

* The fundamental contents of the add-on service or other component. For example, in this template there is a [docker-compose.addon-template.yaml](docker-compose.addon-template.yaml) file.
Expand Down Expand Up @@ -68,7 +75,7 @@ This repository is a quick way to get started. You can create a new repo from th
12. Add a good short description to your repo, and add the `ddev-get` [topic](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics). It will immediately be added to the list provided by `ddev add-on list --all`.
13. When it has matured you will hopefully want to have it become an "official" maintained add-on. Open an issue in the [DDEV queue](https://github.com/ddev/ddev/issues) for that.

## How to debug in Github Actions
## How to debug in GitHub Actions

See [full instructions](./README_DEBUG.md).

Expand Down