respect-validation/bin/update-tld
Alexandre Gomes Gaigalas ef4778b456 Remove version info from Tld.php
We currently use a GitHub action to automate updating this file.

That action has the ability to ignore making the PR if the file
didn't changed.

Having the version number, which changed a line, was causing
several useless PR.

Users can still check if Tld.php changed by seeing the git log,
and a manual note should be issued by the maintainer on the
CHANGELOG.md file when a release containing such changes is
made.
2023-02-19 00:19:09 -03:00

43 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Usage: {script} RULE_FILENAME
# Update list of TLD
set -euo pipefail
declare -r IFS=$'\n'
declare -r LIST_URL="https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
declare -r LIST_FILENAME=$(mktemp)
declare -r RULE_FILENAME=$(dirname "${BASH_SOURCE}")/../library/Rules/Tld.php
declare -r RULE_FILENAME_TEMPORARY=$(mktemp)
echo "- Downloading list"
curl --silent --location "${LIST_URL}" --output "${LIST_FILENAME}"
echo "- Creating temporary file"
{
sed --silent --regexp-extended "/^</,/^\{/p" "${RULE_FILENAME}"
echo " /**"
echo " * List extracted from ${LIST_URL}"
echo " */"
echo " private const TLD_LIST = ["
grep --invert-match "^#" "${LIST_FILENAME}" |
sed --regexp-extended "s,^,',; s/$/', /" |
tr --delete "\n" |
fold --width=72 --spaces |
sed "s,^, ,g; s, $,,g"
echo
echo " ];"
echo
echo " /**"
echo " * {@inheritDoc}"
echo " */"
sed --silent --regexp-extended "/^ public function/,/^}/p" "${RULE_FILENAME}"
} > "${RULE_FILENAME_TEMPORARY}"
echo "- Updating content of '$(basename ${RULE_FILENAME})'"
mv "${RULE_FILENAME_TEMPORARY}" "${RULE_FILENAME}"
echo "Finished!"