-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e743367
commit cbfa4b0
Showing
337 changed files
with
54,967 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.