-
-
Notifications
You must be signed in to change notification settings - Fork 60
90 lines (79 loc) · 3.15 KB
/
iana-hostname-list-updater.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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 }}