diff --git a/.github/workflows/update.yaml b/.github/workflows/update.yaml new file mode 100644 index 00000000..9b46d092 --- /dev/null +++ b/.github/workflows/update.yaml @@ -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' + });