Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow for updating tld.h file #121

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Regenerate tld.h

on: workflow_dispatch

jobs:
generate:
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: Build
run: |
cd hs-names
./download
# 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'
});
Loading