mirror of
https://github.com/Respect/Validation.git
synced 2024-06-09 01:02:16 +02:00
Configure GitHub workflow to update top-level domains
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
83b515d0a3
commit
3be622a9fa
30
.github/workflows/update-tld.yaml
vendored
Normal file
30
.github/workflows/update-tld.yaml
vendored
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
name: Update top-level domains
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * 0'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update-tld:
|
||||||
|
name: Update top-level domains
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: "2.0"
|
||||||
|
|
||||||
|
- name: Execute script
|
||||||
|
run: bin/update-tld
|
||||||
|
|
||||||
|
- name: Create pull request
|
||||||
|
uses: peter-evans/create-pull-request@v2
|
||||||
|
with:
|
||||||
|
committer: The Respect Panda <therespectpanda@gmail.com>
|
||||||
|
author: The Respect Panda <therespectpanda@gmail.com>
|
||||||
|
commit-message: Update list of top-level domains
|
||||||
|
title: Update list of top-level domains
|
||||||
|
base: "2.0"
|
||||||
|
branch: "workflows/update-tld"
|
|
@ -1,34 +1,43 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Usage: {script} TLD_FILENAME
|
# Usage: {script} RULE_FILENAME
|
||||||
# Update list of TLD
|
# Update list of TLD
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
declare -r IFS=$'\n'
|
declare -r IFS=$'\n'
|
||||||
declare -r URL="https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
|
|
||||||
declare -r TEMPORARY_LIST_FILE=$(mktemp)
|
|
||||||
declare -r TEMPORARY_RULE_FILE=$(mktemp)
|
|
||||||
declare -r TLD_FILENAME="${1}"
|
|
||||||
|
|
||||||
echo "Downloading '${URL}'"
|
declare -r LIST_URL="https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
|
||||||
curl -s -L "${URL}" -o "${TEMPORARY_LIST_FILE}"
|
declare -r LIST_FILENAME=$(mktemp)
|
||||||
|
|
||||||
echo "Updating '${TLD_FILENAME}'"
|
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 -nE '/^</,/^\{/p' "${TLD_FILENAME}"
|
sed --silent --regexp-extended "/^</,/^\{/p" "${RULE_FILENAME}"
|
||||||
echo " // List extracted from ${URL}"
|
echo " /**"
|
||||||
grep '^#' "${TEMPORARY_LIST_FILE}" | sed 's,#, //,'
|
echo " * List extracted from ${LIST_URL}"
|
||||||
echo " protected \$tldList = ["
|
echo " * $(grep "^#" "${LIST_FILENAME}" | sed "s,# ,,")"
|
||||||
grep -v '^#' "${TEMPORARY_LIST_FILE}" |
|
echo " */"
|
||||||
tr '[A-Z]' '[a-z]' |
|
echo " private const TLD_LIST = ["
|
||||||
sed -E "s,^,',; s/$/', /" |
|
grep --invert-match "^#" "${LIST_FILENAME}" |
|
||||||
tr -d '\n' |
|
sed --regexp-extended "s,^,',; s/$/', /" |
|
||||||
fold -w 72 -s |
|
tr --delete "\n" |
|
||||||
sed 's,^, ,g; s, $,,g'
|
fold --width=72 --spaces |
|
||||||
|
sed "s,^, ,g; s, $,,g"
|
||||||
echo
|
echo
|
||||||
echo " ];"
|
echo " ];"
|
||||||
echo
|
echo
|
||||||
sed -nE '/^ public function/,/^}/p' "${TLD_FILENAME}"
|
echo " /**"
|
||||||
} > "${TEMPORARY_RULE_FILE}"
|
echo " * {@inheritDoc}"
|
||||||
|
echo " */"
|
||||||
|
sed --silent --regexp-extended "/^ public function/,/^}/p" "${RULE_FILENAME}"
|
||||||
|
} > "${RULE_FILENAME_TEMPORARY}"
|
||||||
|
|
||||||
mv "${TEMPORARY_RULE_FILE}" "${TLD_FILENAME}"
|
echo "- Updating content of '$(basename ${RULE_FILENAME})'"
|
||||||
|
mv "${RULE_FILENAME_TEMPORARY}" "${RULE_FILENAME}"
|
||||||
|
|
||||||
|
echo "Finished!"
|
||||||
|
|
Loading…
Reference in a new issue