Merge pull request #223 from is-a-good-dev/main

Add auto record adding.
This commit is contained in:
Tweak
2022-10-26 00:06:04 +00:00
committed by GitHub
4 changed files with 70 additions and 3 deletions
+33
View File
@@ -0,0 +1,33 @@
name: Add DNS records
on:
push:
branches: [ main ]
jobs:
validation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v34
with:
files: |
sub-logs/**
reserved/**
- name: Install modules
if: steps.changed-files.outputs.any_changed == 'true'
run: yarn
- name: Add records
if: steps.changed-files.outputs.any_changed == 'true'
id: tests
run: yarn add-records
env:
API_KEY: ${{ secrets.API_KEY }}
FILES: ${{ steps.changed-files.outputs.all_changed_files }}
actions_path: ${{ github.workspace }}
+7 -1
View File
@@ -10,10 +10,16 @@ jobs:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v32
uses: tj-actions/changed-files@v34
with:
files: |
sub-logs/**
reserved/**
- name: Install modules
if: steps.changed-files.outputs.any_changed == 'true'
run: yarn
- name: Run tests
if: steps.changed-files.outputs.any_changed == 'true'
id: tests
run: yarn test
env:
+3 -2
View File
@@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --verbose"
"test": "jest --verbose",
"add-records": "node ./scripts/addRecords.js"
},
"keywords": [],
"author": "Tweak4141",
@@ -13,7 +14,7 @@
"jest": "28.1.1"
},
"dependencies": {
"node-fetch": "2.6.7",
"node-fetch": "^2.6.7",
"jest": "28.1.1",
"@actions/core": "1.9.0"
}
+27
View File
@@ -0,0 +1,27 @@
const fetch = require('node-fetch');
const getJSON = require('../utils/getJSON.js');
const data = getJSON(process.env.FILES);
async function addRecord(type, name, value) {
const response = await fetch(`https://api.is-a-good.dev/api/is-a-good-dev/zones/add?apiKey=${process.env.API_KEY}&type=${type}&name=${name}&content=${value}`);
const data = await response.json();
return data
}
(async () => {
try {
if (!data) return
const records = Object.keys(data.target)
for (const i in records) {
recordType = records[i]
name = data.target[recordType].name;
value = data.target[recordType].value;
const result = await addRecord(recordType, name, value);
console.log(result);
}
} catch (e) {
console.log("Error adding records")
console.log(e)
}
})();