Skip to content

Commit

Permalink
Add workflow for updating tld.h file
Browse files Browse the repository at this point in the history
  • Loading branch information
Falci committed Nov 27, 2023
1 parent 42aa53d commit 9d8aa3f
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Update

on: workflow_dispatch

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Setup nodejs
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Checkout repository (hnsd)
uses: actions/checkout@v4
with:
path: hnsd

- name: Checkout repository (hs-names)
uses: actions/checkout@v4
with:
repository: handshake-org/hs-names
path: hs-names

- name: Install dependencies (hs-names)
run: npm --prefix=hs-names install

- name: Install dependencies (hsd)
run: npm --prefix=hs-names install hsd@^5

- name: Download (tlds-alpha-by-domain.txt)
uses: wei/wget@v1
with:
args: -O hs-names/data/tlds-alpha-by-domain.txt https://data.iana.org/TLD/tlds-alpha-by-domain.txt

- name: Download (root.zone)
uses: wei/wget@v1
with:
args: -O hs-names/data/root.zone https://www.internic.net/domain/root.zone

- name: Build
run: |
cd hs-names
# Workaround for https://github.com/chjj/bns/issues/41
sed -i '/ZONEMD/d' data/root.zone
./zone.js
./zone-build.js
- name: Commit/PR
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const branch = `update-${new Date().getTime()}`;
const ref = `refs/heads/${branch}`;
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref,
sha: context.sha
});
const fileOptions = {
owner: context.repo.owner,
repo: context.repo.repo,
path: 'src/tld.h',
};
const file = await github.rest.repos.getContent({
...fileOptions,
ref
});
await github.rest.repos.createOrUpdateFileContents({
...fileOptions,
message: 'Update tld.h',
content: Buffer.from(fs.readFileSync('hs-names/build/tld.h')).toString('base64'),
sha: file.data.sha,
branch
});
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Update tld.h',
head: branch,
base: 'master'
});

0 comments on commit 9d8aa3f

Please sign in to comment.