Skip to content

IANA TLD List Updater #91

IANA TLD List Updater

IANA TLD List Updater #91

name: "IANA TLD List Updater"
on:
workflow_dispatch:
schedule:
# weekly on mondays
- cron: '0 0 * * 1'
jobs:
update-hostnames:
runs-on: ubuntu-latest
steps:
- name: Get default branch
id: default-branch
shell: bash
run: |
set -e
echo "branch-name=$(gh repo view "$GITHUB_REPOSITORY" --json defaultBranchRef --jq '.defaultBranchRef.name')" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ steps.default-branch.outputs.branch-name }}
fetch-depth: 1
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: intl
- name: Install composer dependencies
run: composer install --no-interaction
- name: Update TLDs from IANA
id: update-hostnames
shell: bash
run: |
set -e
php -f bin/update_hostname_validator.php
[ ! -n "$(git status --porcelain -- src/Hostname.php)" ] || echo "changed=true" >> $GITHUB_OUTPUT
- name: Configure git
if: steps.update-hostnames.outputs.changed == 'true'
shell: bash
run: |
set -e
SIGNING_KEY_ID=$(echo "$SIGNING_SECRET_KEY" | gpg --import -q --import-options import-show --with-colons | awk -F: '$1=="sec" {print $5; exit}')
if [ -z "$SIGNING_KEY_ID" ]
then
echo "GPG signing key not found in SIGNING_SECRET_KEY"
exit 1
fi
echo "Using gpg key $SIGNING_KEY_ID"
git config --local user.email "$GIT_AUTHOR_EMAIL"
git config --local user.name "$GIT_AUTHOR_NAME"
git config --local user.signingkey "$SIGNING_KEY_ID"
git config --local commit.gpgsign true
env:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }}
- name: Create or update PR
if: steps.update-hostnames.outputs.changed == 'true'
shell: bash
run: |
set -e
git checkout -b "${USE_BRANCH_NAME}"
git add -- src/Hostname.php
git commit -s -S -m "Update TLD list for hostname validator"
git push --force origin "${USE_BRANCH_NAME}"
PR_STATE=$(gh pr view --repo "$GITHUB_REPOSITORY" --json state --jq ".state" "${USE_BRANCH_NAME}" 2>/dev/null || echo "NONE")
if [[ "$PR_STATE" == "OPEN" ]]
then
echo "PR for branch ${USE_BRANCH_NAME} already opened. Nothing left to do."
exit 0
fi
gh pr create --repo "$GITHUB_REPOSITORY" \
--title "Update IANA TLDs for Hostname validator" \
--body "Automated update of TLDs from IANA list available at https://data.iana.org/TLD/tlds-alpha-by-domain.txt" \
--label "Enhancement"
env:
USE_BRANCH_NAME: iana-tld-list-update
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}