diff --git a/.github/workflows/addRecords.yml b/.github/workflows/addRecords.yml new file mode 100644 index 0000000..05e3bb8 --- /dev/null +++ b/.github/workflows/addRecords.yml @@ -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 }} diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 09ef417..d843a31 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -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: diff --git a/package.json b/package.json index e04ff2d..37b8a2a 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/scripts/addRecords.js b/scripts/addRecords.js new file mode 100644 index 0000000..c2c285d --- /dev/null +++ b/scripts/addRecords.js @@ -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) + } +})();