Skip to content

Commit

Permalink
Actually continuously integrate
Browse files Browse the repository at this point in the history
  • Loading branch information
northeastprince committed Apr 9, 2024
1 parent e743367 commit cbfa4b0
Show file tree
Hide file tree
Showing 337 changed files with 54,967 additions and 65 deletions.
8 changes: 8 additions & 0 deletions .github/actions/format/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Format YAML files
inputs:
token:
required: true
default: "${{ github.token }}"
runs:
using: node20
main: index.js
54 changes: 54 additions & 0 deletions .github/actions/format/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const core = require("@actions/core")
const fs = require("fs")
const yaml = require("js-yaml")

try {
const yamlFiles = fs.readdirSync("./").filter(file => file.endsWith(".yaml"))
format(yamlFiles)
} catch (error) {
core.setFailed(error.message)
}

function format(yamlFiles) {
yamlFiles.forEach(file => {
const content = fs.readFileSync(file)

let data = yaml.load(content)
data = consistent(data)
data = sort(data)

const formattedContent = yaml.dump(data, {quotingType: '"', lineWidth: -1})
fs.writeFileSync(file, formattedContent)
})
}

function consistent(data) { // one-record subdomains might not be an array
for (const key in data) {
if (!Array.isArray(data[key])) {
const array = [data[key]]
data[key] = array
}
}

return data
}

function sort(subdomains) {
const sortedSubdomains = {}
Object.keys(subdomains).sort().forEach(key => {
sortedSubdomains[key] = subdomains[key]
})

for (const subdomain in sortedSubdomains) {
const records = sortedSubdomains[subdomain]
for (const record in records) {
const sortedOptions = {}
Object.keys(records[record]).sort().forEach(option => {
sortedOptions[option] = sortedSubdomains[subdomain][record][option]
})
sortedSubdomains[subdomain][record] = sortedOptions
}
}

return sortedSubdomains
}
1 change: 1 addition & 0 deletions .github/actions/format/node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .github/actions/format/node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions .github/actions/format/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .github/actions/format/node_modules/@actions/core/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cbfa4b0

Please sign in to comment.